build: dist should have %tarfile as target.
[goals.git] / src / run.ml
index 2d4e326..b9cb0f0 100644 (file)
@@ -54,26 +54,31 @@ let rec goal_runner env loc name args
           | d :: _ -> Ast.Env.add "^" d env in
         let r = Eval.run_code env loc code in
         if r <> 0 then
-          failwithf "goal ‘%s’ failed with exit code %d" name r;
+          failwithf "%a: goal ‘%s’ failed with exit code %d"
+            Ast.string_loc loc debug_goal r;
 
         (* Check all targets were updated after the code was
          * run (else it's an error).
          *)
         let pattern_still_needs_rebuild =
           try
-            Some (List.find (needs_rebuild env loc deps extra_deps) patterns)
+            let pattern =
+              List.find
+                (needs_rebuild ~final_check:true env loc deps extra_deps)
+                patterns in
+            Some pattern
           with
             Not_found -> None in
         match pattern_still_needs_rebuild with
         | None -> ()
         | Some pattern ->
-           failwithf "%a: goal %s ran successfully but it did not rebuild %a"
+           failwithf "%a: goal ‘%s’ ran successfully but it did not rebuild %a"
              Ast.string_loc loc debug_goal Ast.string_pattern pattern
     )
   )
 
 (* Return whether the target (pattern) needs to be rebuilt. *)
-and needs_rebuild env loc deps extra_deps pattern =
+and needs_rebuild ?(final_check = false) env loc deps extra_deps pattern =
   Cmdline.debug "%a: testing if %a needs rebuild"
     Ast.string_loc loc Ast.string_pattern pattern;
 
@@ -105,6 +110,11 @@ and needs_rebuild env loc deps extra_deps pattern =
      (* Add some standard variables to the environment. *)
      let env = Ast.Env.add "<" (Ast.EList (Ast.noloc, deps)) env in
      let env =
+       (*let b = Ast.EConstant (Ast.noloc, Ast.CBool final_check) in*)
+       let b = Ast.EConstant (Ast.noloc,
+                              Ast.CString (if final_check then "1" else "")) in
+       Ast.Env.add "goals_final_check" b env in
+     let env =
        (* NB: extra_deps are not added to %^ *)
        match deps with
        | [] -> env
@@ -113,11 +123,13 @@ and needs_rebuild env loc deps extra_deps pattern =
      if r = 99 (* means "needs rebuild" *) then true
      else if r = 0 (* means "doesn't need rebuild" *) then false
      else
-       failwithf "tactic ‘%s’ failed with exit code %d" tactic r
+       failwithf "%a: tactic ‘%s’ failed with exit code %d"
+         Ast.string_loc loc tactic r
 
 and exists_runner env loc p debug_tactic =
   Cmdline.debug "%a: running implicit existence rule for tactic %s"
     Ast.string_loc loc debug_tactic;
 
   if needs_rebuild env loc [] [] p then
-    failwithf "%a: don't know how to build %s" Ast.string_loc loc debug_tactic
+    failwithf "%a: don't know how to build ‘%s’"
+      Ast.string_loc loc debug_tactic