Skip to content

Commit

Permalink
Add rule locs to failed rules
Browse files Browse the repository at this point in the history
this will add a location that will point to the rule that failed

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Aug 4, 2018
1 parent b9cbdd2 commit 66f2004
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 24 deletions.
38 changes: 20 additions & 18 deletions src/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ module Dir_status = struct
; action : (unit, Action.t) Build.t
; locks : Path.t list
; context : Context.t
; loc : Loc.t option
}


Expand Down Expand Up @@ -684,23 +685,23 @@ let remove_old_artifacts t ~dir ~subdirs_to_keep =
if not (Path.Table.mem t.files path) then Path.unlink path)

let no_rule_found =
let fail fn =
die "No rule found for %s" (Utils.describe_target fn)
let fail fn ~loc =
Loc.fail_opt loc "No rule found for %s" (Utils.describe_target fn)
in
fun t fn ->
fun t ~loc fn ->
match Utils.analyse_target fn with
| Other _ -> fail fn
| Other _ -> fail fn ~loc
| Regular (ctx, _) ->
if String.Map.mem t.contexts ctx then
fail fn
fail fn ~loc
else
die "Trying to build %s but build context %s doesn't exist.%s"
(Path.to_string_maybe_quoted fn)
ctx
(hint ctx (String.Map.keys t.contexts))
| Alias (ctx, fn') ->
if String.Map.mem t.contexts ctx then
fail fn
fail fn ~loc
else
let fn = Path.append (Path.relative Path.build_dir ctx) fn' in
die "Trying to build alias %s but build context %s doesn't exist.%s"
Expand Down Expand Up @@ -729,18 +730,18 @@ let rec compile_rule t ?(copy_source=false) pre_rule =

let eval_rule () =
t.hook Rule_started;
wait_for_deps t (Lazy.force static_deps).rule_deps
wait_for_deps t (Lazy.force static_deps).rule_deps ~loc
>>| fun () ->
Build_exec.exec t build ()
in
let exec_rule (rule_evaluation : Exec_status.rule_evaluation) =
let static_deps = (Lazy.force static_deps).action_deps in
Fiber.fork_and_join_unit
(fun () ->
wait_for_deps t static_deps)
wait_for_deps ~loc t static_deps)
(fun () ->
Fiber.Future.wait rule_evaluation >>= fun (action, dyn_deps) ->
wait_for_deps t (Path.Set.diff dyn_deps static_deps)
wait_for_deps ~loc t (Path.Set.diff dyn_deps static_deps)
>>| fun () ->
(action, dyn_deps))
>>= fun (action, dyn_deps) ->
Expand Down Expand Up @@ -949,13 +950,13 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
let rules, deps =
List.fold_left actions ~init:(rules, deps)
~f:(fun (rules, deps)
{ Dir_status. stamp; action; locks ; context } ->
{ Dir_status. stamp; action; locks ; context ; loc } ->
let path =
Path.extend_basename base_path
~suffix:("-" ^ Digest.to_hex stamp)
in
let rule =
Pre_rule.make ~locks ~context:(Some context)
Pre_rule.make ~locks ~context:(Some context) ?loc
(Build.progn [ action; Build.create_file path ])
in
(rule :: rules, Path.Set.add deps path))
Expand Down Expand Up @@ -1107,7 +1108,7 @@ The following targets are not:

targets

and wait_for_file t fn =
and wait_for_file t ~loc fn =
match Path.Table.find t.files fn with
| Some file -> wait_for_file_found fn file
| None ->
Expand All @@ -1116,7 +1117,7 @@ and wait_for_file t fn =
load_dir t ~dir;
match Path.Table.find t.files fn with
| Some file -> wait_for_file_found fn file
| None -> no_rule_found t fn
| None -> no_rule_found t ~loc fn
end else if Path.exists fn then
Fiber.return ()
else
Expand Down Expand Up @@ -1146,8 +1147,8 @@ and wait_for_file_found fn (File_spec.T file) =
};
Fiber.Future.wait rule_execution)

and wait_for_deps t deps =
Fiber.parallel_iter (Path.Set.to_list deps) ~f:(wait_for_file t)
and wait_for_deps ~loc t deps =
Fiber.parallel_iter (Path.Set.to_list deps) ~f:(wait_for_file ~loc t)

let stamp_file_for_files_of t ~dir ~ext =
let files_of_dir =
Expand Down Expand Up @@ -1260,7 +1261,7 @@ let eval_request t ~request ~process_target =
Fiber.fork_and_join_unit
(fun () -> process_targets static_deps)
(fun () ->
wait_for_deps t rule_deps
wait_for_deps t ~loc:None rule_deps
>>= fun () ->
let result, dyn_deps = Build_exec.exec t request () in
process_targets (Path.Set.diff dyn_deps static_deps)
Expand All @@ -1285,7 +1286,7 @@ let update_universe t =
let do_build t ~request =
entry_point t ~f:(fun () ->
update_universe t;
eval_request t ~request ~process_target:(wait_for_file t))
eval_request t ~request ~process_target:(wait_for_file ~loc:None t))

module Ir_set = Set.Make(Internal_rule)

Expand Down Expand Up @@ -1616,12 +1617,13 @@ module Alias = struct
Build.fanout def.dyn_deps build >>^ fun (a, b) ->
Path.Set.union a b

let add_action build_system t ~context ?(locks=[]) ~stamp action =
let add_action build_system t ~context ~loc ?(locks=[]) ~stamp action =
let def = get_alias_def build_system t in
def.actions <- { stamp = Digest.string (Sexp.to_string ~syntax:Dune stamp)
; action
; locks
; context
; loc
} :: def.actions
end

Expand Down
1 change: 1 addition & 0 deletions src/build_system.mli
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ module Alias : sig
: build_system
-> t
-> context:Context.t
-> loc:Loc.t option
-> ?locks:Path.t list
-> stamp:Sexp.t
-> (unit, Action.t) Build.t
Expand Down
1 change: 1 addition & 0 deletions src/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ module Gen(P : Install_rules.Params) = struct
; deps = t.deps
; action = None
; enabled_if = t.enabled_if
; loc
} in
match test_kind (loc, s) with
| `Regular ->
Expand Down
1 change: 1 addition & 0 deletions src/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ include Sub_system.Register_end_point(
in

SC.add_alias_action sctx
~loc:(Some info.loc)
(Build_system.Alias.runtest ~dir)
~stamp:(List [ Sexp.unsafe_atom_of_string "ppx-runner"
; Quoted_string name
Expand Down
3 changes: 3 additions & 0 deletions src/jbuild.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ module Alias_conf = struct
; locks : String_with_vars.t list
; package : Package.t option
; enabled_if : String_with_vars.t Blang.t option
; loc : Loc.t
}

let alias_name =
Expand All @@ -1570,6 +1571,7 @@ module Alias_conf = struct
let t =
record
(let%map name = field "name" alias_name
and loc = loc
and package = field_o "package" Pkg.t
and action = field_o "action" (located Action.Unexpanded.t)
and locks = field "locks" (list String_with_vars.t) ~default:[]
Expand All @@ -1582,6 +1584,7 @@ module Alias_conf = struct
; package
; locks
; enabled_if
; loc
})
end

Expand Down
1 change: 1 addition & 0 deletions src/jbuild.mli
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ module Alias_conf : sig
; locks : String_with_vars.t list
; package : Package.t option
; enabled_if : String_with_vars.t Blang.t option
; loc : Loc.t
}
end

Expand Down
3 changes: 2 additions & 1 deletion src/preprocessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ let lint_module sctx ~dir ~dep_kind ~lint ~lib_name ~scope ~dir_kind =
let action = Action.Unexpanded.Chdir (workspace_root_var, action) in
Module.iter source ~f:(fun _ (src : Module.File.t) ->
let bindings = Pform.Map.input_file src.path in
add_alias src.path
add_alias src.path ~loc:None
(Build.path src.path
>>^ (fun _ -> Jbuild.Bindings.empty)
>>> SC.Action.run sctx
Expand Down Expand Up @@ -516,6 +516,7 @@ let lint_module sctx ~dir ~dep_kind ~lint ~lib_name ~scope ~dir_kind =
(fun ~source ~ast ->
Module.iter ast ~f:(fun kind src ->
add_alias src.path
~loc:None
(promote_correction ~suffix:corrected_suffix
(Option.value_exn (Module.file source kind))
(Build.of_result_map driver_and_flags ~f:(fun (exe, flags) ->
Expand Down
7 changes: 5 additions & 2 deletions src/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ let copy_files sctx ~dir ~scope ~src_dir (def: Copy_files.t) =
~dst:file_dst);
file_dst)

let add_alias sctx ~dir ~name ~stamp ?(locks=[]) build =
let add_alias sctx ~dir ~name ~stamp ~loc ?(locks=[]) build =
let alias = Build_system.Alias.make name ~dir in
SC.add_alias_action sctx alias ~locks ~stamp build
SC.add_alias_action sctx alias ~loc ~locks ~stamp build

let alias sctx ~dir ~scope (alias_conf : Alias_conf.t) =
let enabled =
Expand All @@ -91,9 +91,11 @@ let alias sctx ~dir ~scope (alias_conf : Alias_conf.t) =
(Option.map alias_conf.action ~f:snd)
]
in
let loc = Some alias_conf.loc in
if enabled then
add_alias sctx
~dir
~loc
~name:alias_conf.name
~stamp
~locks:(interpret_locks sctx ~dir ~scope alias_conf.locks)
Expand All @@ -114,6 +116,7 @@ let alias sctx ~dir ~scope (alias_conf : Alias_conf.t) =
~scope)
else
add_alias sctx
~loc
~dir
~name:alias_conf.name
~stamp
Expand Down
5 changes: 3 additions & 2 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ let add_rules t ?sandbox builds =
let add_alias_deps t alias ?dyn_deps deps =
Alias.add_deps t.build_system alias ?dyn_deps deps

let add_alias_action t alias ?locks ~stamp action =
Alias.add_action t.build_system ~context:t.context alias ?locks ~stamp action
let add_alias_action t alias ~loc ?locks ~stamp action =
Alias.add_action t.build_system ~context:t.context alias ~loc ?locks
~stamp action

let eval_glob t ~dir re = Build_system.eval_glob t.build_system ~dir re
let load_dir t ~dir = Build_system.load_dir t.build_system ~dir
Expand Down
1 change: 1 addition & 0 deletions src/super_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ val add_alias_deps
val add_alias_action
: t
-> Build_system.Alias.t
-> loc:Loc.t option
-> ?locks:Path.t list
-> stamp:Sexp.t
-> (unit, Action.t) Build.t
Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/missing-loc-run/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Exact path provided by the user:

$ dune runtest --root precise-path
Entering directory 'precise-path'
No rule found for foo.exe
File "dune", line 1, characters 0-49:
Error: No rule found for foo.exe
[1]

Path that needs to be searched:
Expand Down

0 comments on commit 66f2004

Please sign in to comment.