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

melange: interpret melc --where as a list of :-separated paths #7176

Merged
merged 3 commits into from
Feb 28, 2023

Conversation

anmonteiro
Copy link
Collaborator

@anmonteiro anmonteiro commented Feb 24, 2023

@Alizter
Copy link
Collaborator

Alizter commented Feb 24, 2023

On cygwin will this be ; separated? For OCAMLPATH (and COQPATH) this is the case.

@anmonteiro
Copy link
Collaborator Author

That's a good idea. I'll change it

@anmonteiro
Copy link
Collaborator Author

Changed to use Bin.path_sep.

@rgrinberg
Copy link
Member

I think you'd be better off just using ; everywhere.

@anmonteiro
Copy link
Collaborator Author

I think you'd be better off just using ; everywhere.

Why is that?

I think I'd prefer to stick to the PATH variable convention to avoid surprises.

@rgrinberg
Copy link
Member

To me, the bigger surprise is varying the path separator depending on the platform. In any case, it's just a suggestion.

in
Option.map
~f:(fun dirs ->
String.split ~on:Bin.path_sep dirs |> List.map ~f:Path.of_string)
Copy link
Member

Choose a reason for hiding this comment

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

If this is a relative path, is it clear what it should be relative to?

Copy link
Collaborator Author

@anmonteiro anmonteiro Feb 24, 2023

Choose a reason for hiding this comment

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

Melange interprets it relative to the melc executable. But it shouldn't really be a relative path. That's a fallback mechanism.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

perhaps I should clarify: the result of melc --where is guaranteed to be an absolute path. So I believe dune doesn't have to worry about it being a relative path.

Copy link
Member

Choose a reason for hiding this comment

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

If it can't be a relative path, perhaps the code shouldn't allow it. E.g. Path.External.of_string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to a Path.External.t in 44cf928

Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Copy link
Collaborator

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 35 to 40
Option.map
~f:(fun dirs ->
String.split ~on:Bin.path_sep dirs
|> List.map ~f:Path.External.of_string)
melange_dirs
|> Option.value ~default:[]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be more readable (imo) and consistent with code style above without Option functions:

match melange_dirs with
| None -> []
| Some dirs ->
  String.split ~on:Bin.path_sep dirs
  |> List.map ~f:Path.External.of_string

let+ dirs = Melange_binary.where sctx ~loc:None ~dir in
match dirs with
| [] -> (None, [])
| [ stdlib_dir ] -> (Some (Path.external_ stdlib_dir), [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are converting to Path.t here using external_ in this line and 482 below, would it make sense to just return Path.t list Memo.t from Melange_binary.where directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Actually, Bin.parse_sep doesn't allow external paths either.

Copy link
Member

Choose a reason for hiding this comment

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

I changed it to use Bin.parse_sep.

match dirs with
| [] -> (None, [])
| [ stdlib_dir ] -> (Some (Path.external_ stdlib_dir), [])
| stdlib_dir :: extra_obj_dirs ->
Copy link
Member

Choose a reason for hiding this comment

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

Is it a little weird that the first directory is being special cased?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, and it might not necessarily be the stdlib if we're not careful, I think that might not matter though?

_
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
@rgrinberg rgrinberg merged commit 497c0e3 into ocaml:main Feb 28, 2023
@anmonteiro anmonteiro deleted the anmonteiro/merlin-melangelib branch February 28, 2023 20:37
jchavarri added a commit to jchavarri/dune that referenced this pull request Nov 15, 2023
* main: (56 commits)
  feature: add terminal ui backend based on NoTTY (ocaml#6996)
  doc(coq): update documentation about coqdep
  fix(rules): don't descend into automatic subdirs infinitely (ocaml#7208)
  benchmark: add warm run (ocaml#7198)
  test: vendored and public libs (ocaml#7197)
  test: use sh in concurrent test (ocaml#7205)
  fix: custom log file path (ocaml#7200)
  test(melange): add test exercising ocaml#7104 (ocaml#7204)
  test(melange): add a test that introduces rules in the target dir (ocaml#7196)
  test: duplicate packages in vendor dir (ocaml#7194)
  melange: interpret `melc --where` as a list of `:`-separated paths (ocaml#7176)
  perf: add synthetic benchmark (ocaml#7189)
  Test case for bug report (ocaml#6725)
  Add test illustrating ocaml#6575 (ocaml#6576)
  chore: add rule streaming proposal (ocaml#7195)
  test(stdlib): merge wrapped/unwrapped tests
  test: move all stdlib tests
  fix: allow unwrapped libraries with `(stdlib ..)`
  test: demonstrate crash in modules.ml when `(stdlib .. )` used with `(wrapped false)`
  fix(install): respect display options (ocaml#7116)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants