# Build.jl from command line vs. from Pkg.build()

**URL:** <https://discourse.julialang.org/t/build-jl-from-command-line-vs-from-pkg-build/48003>\
**Category:** General Usage\
**Created:** [October 8, 2020, 8:59pm UTC](https://discourse.julialang.org/t/build-jl-from-command-line-vs-from-pkg-build/48003 "2020-10-08T20:59:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graham\_Gill](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/graham_gill/32/9269_2.png) [@Graham\_Gill](https://discourse.julialang.org/u/Graham_Gill)\
**Post date:** [October 8, 2020, 8:59pm UTC](https://discourse.julialang.org/t/build-jl-from-command-line-vs-from-pkg-build/48003/1 "2020-10-08T20:59:19Z")

</div>

In `test/runtests.jl` I have

```julia
using Test
using Logging
using MyPackage
#...

```

but in `test/Project.toml`, `MyPackage` is not a dependency. I understand that when I’m in the main project folder and `Pkg.activate(".")`, then `Pkg.test()`, that `MyPackage` is available to `test/runtests.jl` without needing to list it in `test/Project.toml`, and so the tests proceed with no complaint about `using MyPackage`.

In `deps/build.jl` I have

```julia
using Pkg, PackageCompiler

pkg"activate .." #activate main project environment

# do stuff ...

# generate precompile statements from package tests
runcmd = `julia --banner=no --project=../test --startup-file=no --trace-compile=precompile_out.jl -e 'include("../test/runtests.jl")'`
run(runcmd)

# then make a custom sysimage ...

```

This works fine when using `Pkg.build()`. In fact I can comment out the line `pkg"activate .."` and it still works fine using `Pkg.build()`.

However, running

```julia
julia --project=../test --startup-file=no -e 'include("../test/runtests.jl")'

```

from the shell prompt in the `deps` folder fails of course with a `LoadError` that `MyPackage` isn’t found on the current path, since it isn’t included in the `test` environment.

Running

```julia
julia build.jl

```

or

```julia
julia --project build.jl

```

from the shell prompt in the `deps` folder also gives the same error, despite the `pkg"activate .."` statement in `build.jl`.

So when running `Pkg.build()` there’s some extra magic going on to make the project’s main environment available in the build script, including to a julia process run via julia’s external command mechanism, that isn’t available when I run `julia build.jl` from the command line in the `deps` folder, despite activating the project’s main environment in `build.jl`.

Is this documented somewhere?

What’s the best way to run `julia build.jl` from a shell prompt so that I can generate the custom sysimage without needing to call `Pkg.build()`? Add `MyPackage` to `test/Project.toml`?

(I’m using Julia 1.4.2.)
