-
Notifications
You must be signed in to change notification settings - Fork 410
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
Sort out recursive/non-recursive aliases #268
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7a5698c
Interpret jbuild-ignore files sooner
jeremiedimino 3e13492
Get rid of Alias.tree
jeremiedimino 30a9142
All aliases on the command line are recursive
jeremiedimino b281554
Get rid of recursive aliases
jeremiedimino b69a643
Add (alias_rec ...) in dependency specification
jeremiedimino ed55ca9
Fix interpretation of (alias ...) and (alias_rec ...)
jeremiedimino 8466924
Update doc
jeremiedimino 63e8a76
Add tests for aliases
jeremiedimino 7232176
Update changelog
jeremiedimino 192f668
Fix jsoo cram tests
rgrinberg 02a4c59
Remove mention of recursive aliases from error message
rgrinberg bfb241c
add pretty printers to Alias
rgrinberg e23f6fe
Use Alias.of_path over Path operations and Alias.make
rgrinberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,25 @@ open! Import | |
(** Fully qualified name *) | ||
module Fq_name : sig | ||
type t | ||
val pp : Format.formatter -> t -> unit | ||
val make : Path.t -> t | ||
val path : t -> Path.t | ||
end = struct | ||
type t = Path.t | ||
let make t = t | ||
let path t = t | ||
let pp = Path.pp | ||
end | ||
|
||
type t = | ||
{ name : Fq_name.t | ||
; file : Path.t | ||
} | ||
|
||
let pp fmt t = | ||
Format.fprintf fmt "@[<2>{ name@ =@ %a@ ;@ file@ =@ %a }@]" | ||
Path.pp (Fq_name.path t.name) Path.pp t.file | ||
|
||
let aliases_path = Path.(relative root) "_build/.aliases" | ||
|
||
let suffix = "-" ^ String.make 32 '0' | ||
|
@@ -32,12 +38,43 @@ let of_path path = | |
let name t = Path.basename (Fq_name.path t.name) | ||
let dir t = Path.parent (Fq_name.path t.name) | ||
|
||
let fully_qualified_name t = Fq_name.path t.name | ||
|
||
let make name ~dir = | ||
assert (not (String.contains name '/')); | ||
of_path (Path.relative dir name) | ||
|
||
let dep t = Build.path t.file | ||
|
||
let is_standard = function | ||
| "runtest" | "install" | "doc" -> true | ||
| _ -> false | ||
|
||
let dep_rec ~loc ~file_tree t = | ||
let path = Path.parent (Fq_name.path t.name) |> Path.drop_build_context in | ||
let name = Path.basename (Fq_name.path t.name) in | ||
match File_tree.find_dir file_tree path with | ||
| None -> Build.fail { fail = fun () -> | ||
Loc.fail loc "Don't know about directory %s!" (Path.to_string_maybe_quoted path) } | ||
| Some dir -> | ||
let open Build.O in | ||
File_tree.Dir.fold dir ~traverse_ignored_dirs:false ~init:(Build.return true) | ||
~f:(fun dir acc -> | ||
let path = File_tree.Dir.path dir in | ||
let t = of_path (Path.relative path name) in | ||
acc | ||
>>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious if the sequencing here is actually necessary. Seems like this could be done in parallel? |
||
Build.if_file_exists t.file | ||
~then_:(Build.path t.file | ||
>>^ | ||
fun _ -> false) | ||
~else_:(Build.arr (fun x -> x))) | ||
>>^ fun is_empty -> | ||
if is_empty && not (is_standard name) then | ||
Loc.fail loc "This alias is empty.\n\ | ||
Alias %S is not defined in %s or any of its descendants." | ||
name (Path.to_string_maybe_quoted path) | ||
|
||
let file t = t.file | ||
|
||
let file_with_digest_suffix t ~digest = | ||
|
@@ -77,20 +114,29 @@ let runtest = make "runtest" | |
let install = make "install" | ||
let doc = make "doc" | ||
|
||
let recursive_aliases = | ||
[ default | ||
; runtest | ||
; install | ||
; doc | ||
] | ||
|
||
module Store = struct | ||
type entry = | ||
{ alias : t | ||
; mutable deps : Path.Set.t | ||
} | ||
let pp_entry fmt entry = | ||
let pp_deps fmt deps = | ||
Format.pp_print_list Path.pp fmt (Path.Set.elements deps) in | ||
Format.fprintf fmt "@[<2>{@ alias@ =@ %a@ ;@ deps@ = (%a)@ }@]" | ||
pp entry.alias pp_deps entry.deps | ||
|
||
type t = (Fq_name.t, entry) Hashtbl.t | ||
|
||
let pp fmt (t : t) = | ||
let bindings = Hashtbl.fold ~init:[] ~f:(fun ~key ~data acc -> | ||
(key, data)::acc | ||
) t in | ||
let pp_bindings fmt b = | ||
Format.pp_print_list (fun fmt (k, v) -> | ||
Format.fprintf fmt "@[<2>(%a@ %a)@]" Fq_name.pp k pp_entry v | ||
) fmt b in | ||
Format.fprintf fmt "Store.t@ @[@<2>(%a)@]" pp_bindings bindings | ||
|
||
let create () = Hashtbl.create 1024 | ||
end | ||
|
||
|
@@ -104,22 +150,7 @@ let add_deps store t deps = | |
} | ||
| Some e -> e.deps <- Path.Set.union deps e.deps | ||
|
||
type tree = Node of Path.t * tree list | ||
|
||
let rec setup_rec_alias store ~make_alias ~prefix ~tree:(Node (dir, children)) = | ||
let alias = make_alias ~dir:(Path.append prefix dir) in | ||
add_deps store alias (List.map children ~f:(fun child -> | ||
setup_rec_alias store ~make_alias ~prefix ~tree:child)); | ||
alias.file | ||
|
||
let setup_rec_aliases store ~prefix ~tree = | ||
List.iter recursive_aliases ~f:(fun make_alias -> | ||
ignore (setup_rec_alias store ~make_alias ~prefix ~tree : Path.t)) | ||
|
||
let rules store ~prefixes ~tree = | ||
List.iter prefixes ~f:(fun prefix -> | ||
setup_rec_aliases store ~prefix ~tree); | ||
|
||
let rules store = | ||
(* For each alias @_build/blah/../x, add a dependency: @../x --> @_build/blah/../x *) | ||
Hashtbl.fold store ~init:[] ~f:(fun ~key:_ ~data:{ Store. alias; _ } acc -> | ||
match Path.extract_build_context (Fq_name.path alias.name) with | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also document the non recursive use on the command line. If you write
jbuilder build src/x
it means just build the aliasx
in directorysrc
. The API seems to allow it no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
@src/x
? I'm not aware that it's possible to ask for an alias to be built without it. I just gave it a try as well and it doesn't seem work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so there is no way to call for an alias from the command line in a non-recursive way. Perhaps it would be good to add that in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't have much of a need for non recursive invocations. But sure, if it's easy, let's add it.