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

Rename path variables in dune files #944

Merged
merged 1 commit into from
Jul 3, 2018

Conversation

emillon
Copy link
Collaborator

@emillon emillon commented Jul 2, 2018

  • ${path:file} -> %{dep:file}
  • ${path-no-dep:file} -> %{path:file}

See #842.

I moved the path-no-dep test that was in misc and expanded it a bit - I don't think that the path: (with dep) part was directly tested, so I added a small test as well.

@emillon emillon requested review from rgrinberg and a user July 2, 2018 15:36
@rgrinberg
Copy link
Member

Implementation looks good, but I wonder if it might be worth it to complicate things a little more for the sake of better error messages. Concretely, we'd like to handle the following cases better:

  • Using %{dep:..} in jbuild files
  • Using %{path-no-dep:..} in dune files.

@emillon
Copy link
Collaborator Author

emillon commented Jul 2, 2018

Sure, let's do this!

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

Done - I tried to simplify a bit the match by removing the guards, but it's now full of booleans. I'm open to suggestions to make this more readable.

@ghost
Copy link

ghost commented Jul 3, 2018

@emillon what about doing this in the main pattern match? i.e.:

| Pair ("dep", s) -> if not new_syntax then fail ...

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

I tried this, but that requires duplicating the happy path (e.g. Some (path_exp (Path.relative dir s))). But if I extract a function for these, that should look OK. I'll try that.

@ghost
Copy link

ghost commented Jul 3, 2018

BTW, I'm having second thoughts about renaming path-no-dep to path; it means that {path:x} exists in both the old and new syntax but mean something different, which might make things confusing for users. In particular, it might be tempting to replace ${path:x} by %{path:x}. Should we keep keep path-no-dep as it for now and only rename it in dune 2?

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

Yep that looks better!

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

About your comment - yes I agree that reusing the same piece of syntax is a bit dangerous. Can we avoid path altogether? What is the use case for using ${path-no-dep:x} or %{path:x} (the ones that do not add the dependency) rather than x? Capture the current directory?

@ghost
Copy link

ghost commented Jul 3, 2018

The idea is that the payload of ${path-no-dep:...} is relative to the directory of the jbuild file while its expansion is relative to the cwd when running the command. So for instance (chdir ${ROOT} (run echo ${path-no-dep:f})) in src/jbuild expands to: (chdir .. (run echo src/f))

@ghost
Copy link

ghost commented Jul 3, 2018

We could possibly replace it by just %{dir} or similar that would be the equivalent of ${path-no-dep:.}, then we'd do: %{dir}/f rather than %{path:f}

@rgrinberg
Copy link
Member

A more radical approach might be just adding a %{no-dep:x:...}, where x can be path, exe, bin, etc.

@ghost
Copy link

ghost commented Jul 3, 2018

A more radical approach might be just adding a %{no-dep:x:...}, where x can be path, exe, bin, etc.

That would be more generic indeed, however in most of these case the file is always a dependency.

While I remember needing this in the past, I can't find a single occurrence of path-no-dep in the dune universe. I can't really think of a valid use case for it either. So I suggest that we indeed get rid of it. Although adding a variable to refer to the directory of the dune file seems good to me, just in case someone was indeed using ${path-no-dep:...}.

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

A disadvantage of using %{dir}/f is that we cannot check that the corresponding path is still within the _build directory (but we can reject %{path:../../..}). I'm trying to thinking of a better name.

@ghost
Copy link

ghost commented Jul 3, 2018

That's true, but we can't check it either if the user writes a plain path without variables

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2018

That's fair! I'll leave that part out and remove path-no-dep in a separate PR.

emillon added a commit to emillon/dune that referenced this pull request Jul 3, 2018
See ocaml#944

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
See ocaml#842

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
@emillon emillon merged commit 9ece73d into ocaml:master Jul 3, 2018
emillon added a commit to emillon/dune that referenced this pull request Jul 3, 2018
See ocaml#944

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
emillon added a commit to emillon/dune that referenced this pull request Jul 3, 2018
See ocaml#944

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
@emillon emillon mentioned this pull request Jul 3, 2018
emillon added a commit to emillon/dune that referenced this pull request Jul 4, 2018
See ocaml#944

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
emillon added a commit to emillon/dune that referenced this pull request Jul 4, 2018
See ocaml#944

Signed-off-by: Etienne Millon <etienne@cryptosense.com>
@emillon emillon deleted the rename-path-vars branch July 25, 2023 09:22
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.

2 participants