Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the priority order for environment variables between workspace and context #2476

Closed
wants to merge 2 commits into from

Conversation

bobot
Copy link
Collaborator

@bobot bobot commented Jul 30, 2019

Use env-vars from the dune-workspace for dune use.

@bobot bobot requested a review from a user July 30, 2019 14:49
@bobot bobot requested review from emillon and rgrinberg as code owners July 30, 2019 14:49
@bobot bobot force-pushed the env-in-workspace branch from d96f21b to 88a6d8e Compare July 30, 2019 14:50
@bobot
Copy link
Collaborator Author

bobot commented Jul 30, 2019

@nojb Perhaps you can take a look.

@bobot bobot requested a review from nojb July 30, 2019 14:51
doc/usage.rst Outdated Show resolved Hide resolved
@bobot bobot force-pushed the env-in-workspace branch from 88a6d8e to a240c8d Compare July 30, 2019 15:30
src/context.ml Show resolved Hide resolved
@bobot
Copy link
Collaborator Author

bobot commented Jul 31, 2019

I propose to change that relative path are absolutize with respect to the build directory instead of the source directory, since it is where things should be. It forces to have the right dependencies.

@nojb
Copy link
Collaborator

nojb commented Jul 31, 2019

I propose to change that relative path are absolutize with respect to the build directory instead of the source directory, since it is where things should be. It forces to have the right dependencies.

I am not sure about this; if I understand correctly this is the right thing to do only if the binaries are being managed by dune.

Suppose that I have a toplevel tools directory with some assorted binaries that I want to bring into the PATH during by build. Before this change, dune-workspace had

(paths (PATH tools))

after this change it will have be

(paths (PATH ../../tools))

is that right?

@bobot bobot mentioned this pull request Jul 31, 2019
@bobot
Copy link
Collaborator Author

bobot commented Jul 31, 2019

The dune-workspace is the same, you just add a (deps (source_tree tools) to the rules which uses these binaries. So that dune copy the binaries in the directory _build/default/tools and record the dependency.

@nojb
Copy link
Collaborator

nojb commented Jul 31, 2019

The dune-workspace is the same, you just add a (deps (source_tree tools) to the rules which uses these binaries. So that dune copy the binaries in the directory _build/default/tools and record the dependency.

This won't work for the compiler tools for example, which is one of the use-cases of #2426 .

@bobot
Copy link
Collaborator Author

bobot commented Jul 31, 2019

This won't work for the compiler tools for example, which is one of the use-cases of #2426 .

Oh, I though your compiler tools were in absolute directories. Sorry. In your case does (paths (PATH %{workspace_root}/tools)) is possible?

@nojb
Copy link
Collaborator

nojb commented Jul 31, 2019

This won't work for the compiler tools for example, which is one of the use-cases of #2426 .

Oh, I though your compiler tools were in absolute directories. Sorry. In your case does (paths (PATH %{workspace_root}/tools)) is possible?

I will give it a try, but I don't think we currently expand variables when interpreting paths (or env-vars for that matter), but it may end up being the best solution.

@nojb
Copy link
Collaborator

nojb commented Jul 31, 2019

Oh, I though your compiler tools were in absolute directories. Sorry. In your case does (paths (PATH %{workspace_root}/tools)) is possible?

I gave it a try; indeed variables are not expanded so that would need fixing, but by writing an absolute path by hand it seems to work fine. Do you think you could look into the issue of variable expansion?

@bobot bobot force-pushed the env-in-workspace branch from 58f99a8 to 2f7dca4 Compare July 31, 2019 14:34
@bobot
Copy link
Collaborator Author

bobot commented Jul 31, 2019

Now the variable is expanded. However since we are very early, the context record is not yet built and so I couldn't use Pform. So it is perhaps not the right way but it works.

@bobot bobot force-pushed the env-in-workspace branch from 2f7dca4 to ff5cdf4 Compare July 31, 2019 14:36
@nojb
Copy link
Collaborator

nojb commented Aug 1, 2019

Now the variable is expanded. However since we are very early, the context record is not yet built and so I couldn't use Pform. So it is perhaps not the right way but it works.

We probably want to do this properly, so I would be OK if you merge your PR without the expansion of variables, and we look at that properly in a later PR.

bobot added 2 commits August 2, 2019 20:01
    between workspace and context. Use `env-vars` from the `dune-workspace` for
    dune.

Signed-off-by: François Bobot <francois.bobot@cea.fr>
Signed-off-by: François Bobot <francois.bobot@cea.fr>
@bobot
Copy link
Collaborator Author

bobot commented Aug 2, 2019

Ok so I removed the last commit and created a new merge request with the last commit (not based on this PR)

@ghost
Copy link

ghost commented Aug 6, 2019

I haven't read this PR in detail, but just one important detail to keep in mind: currently, when Dune looks up a binary in the PATH, it only test for the existence of the file via a plan Sys.file_exists. In particular, it doesn't go through the build system.

This is obviously incorrect if the PATH contains directories that point inside the build directory, as the result would depend on the time at which dune happened to call Sys.file_exists. Up to know, we made the assumption that all components of PATH were pointing outside the build directory.

Reading the discussion, I get the feeling that this PR allows to have parts of PATH point to the build directory. Is that the case?

@@ -1,3 +1,3 @@
(executable
(name hello)
(promote (until-clean)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need $ make fmt here

$ dune build
$ dune build bin/hello.exe

$ dune build @default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why $ dune build @default over just $ dune build?

@nojb
Copy link
Collaborator

nojb commented Aug 7, 2019

Reading the discussion, I get the feeling that this PR allows to have parts of PATH point to the build directory. Is that the case?

@bobot will be able to give the definite answer, but yes, I think that all relative paths will now be interpreted relative the build directory.

@ghost
Copy link

ghost commented Aug 8, 2019

Ok, so that cannot work in the current world. We could change the way dune resolves binaries to make it work (which would be really nice!), but in the meantime components of PATH cannot point to the _build directory.

Base automatically changed from master to main January 14, 2021 17:08
@rgrinberg
Copy link
Member

@bobot please re-open if you rebase.

@rgrinberg rgrinberg closed this Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants