Skip to content

Commit

Permalink
Implement alias field via temp file
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Oct 21, 2019
1 parent 2014e73 commit bc09e64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 15 additions & 5 deletions src/dune/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,24 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
|> SC.Action.run sctx (snd rule.action) ~loc:(fst rule.action) ~expander
~dep_kind:Required ~targets ~targets_dir:dir
in
Option.iter rule.alias ~f:(fun name ->
let action =
match rule.alias with
| None -> action
| Some alias ->
let stamp =
let action = Some (snd rule.action) in
stamp ~deps:rule.deps ~extra_bindings ~action
|> Digest.generic
|> Digest.to_string
in
let stamp_target = Path.Build.relative dir stamp in
let () =
let alias = Alias.make alias ~dir in
let deps = Path.Set.singleton (Path.build stamp_target) in
Rules.Produce.Alias.add_deps alias deps
in
add_alias sctx ~dir ~name ~stamp ~loc:(Some (fst rule.action)) action);
Build.progn [action; Build.create_file stamp_target]
in
SC.add_rule_get_targets
sctx
(* user rules may have extra requirements, in which case they will be
Expand All @@ -86,9 +98,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule.t) =
~sandbox:Sandbox_config.no_special_requirements ~dir ~mode:rule.mode
~loc:rule.loc
~locks:(interpret_locks ~expander rule.locks)
( SC.Deps.interpret_named sctx ~expander rule.deps
|> SC.Action.run sctx (snd rule.action) ~loc:(fst rule.action) ~expander
~dep_kind:Required ~targets ~targets_dir:dir )
action

let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) =
let loc = String_with_vars.loc def.glob in
Expand Down
10 changes: 2 additions & 8 deletions test/blackbox-tests/test-cases/github2681/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ dependency of the alias.
> (alias bar))
> EOF
$ dune build @bar --display short
File "dune", line 2, characters 9-50:
2 | (action (with-stdout-to foo (echo "hello world")))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Rule has targets in different directories.
Targets:
- _build/.aliases/default/bar-fc3cef760337ee5dd7a56722c8e58053
- _build/default/foo
[1]
$ cat _build/default/foo
hello world

The field order should not affect the alias field:
$ cd .. && mkdir field-order && cd field-order
Expand Down

0 comments on commit bc09e64

Please sign in to comment.