-
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
Changes from 10 commits
7a5698c
3e13492
30a9142
b281554
b69a643
ed55ca9
8466924
63e8a76
7232176
192f668
02a4c59
bfb241c
e23f6fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,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 recursive alias is empty.\n\ | ||
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. "recursive" should be probably be removed from this error message if recursive aliases no longer exist. |
||
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,13 +108,6 @@ 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 | ||
|
@@ -104,22 +128,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 | ||
|
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.