diff --git a/bin/import.ml b/bin/import.ml index 141a06e851c..c16930b21b1 100644 --- a/bin/import.ml +++ b/bin/import.ml @@ -14,7 +14,6 @@ include struct module Action_builder = Dune_rules.Action_builder module Action = Action module Dep = Dep - module Action_to_sh = Action_to_sh module Dpath = Dpath module Findlib = Dune_rules.Findlib module Diff_promotion = Diff_promotion diff --git a/src/dune_cache/shared.ml b/src/dune_cache/shared.ml index 259f394f685..38fab54f8ec 100644 --- a/src/dune_cache/shared.ml +++ b/src/dune_cache/shared.ml @@ -402,19 +402,18 @@ let lookup ~can_go_in_shared_cache ~rule_digest ~targets (* If this function fails to store the rule to the shared cache, it returns [None] because we don't want this to be a catastrophic error. We simply log this incident and continue without saving the rule to the shared cache. *) -let try_to_store_to_shared_cache ~mode ~rule_digest ~action ~produced_targets +let try_to_store_to_shared_cache ~mode ~rule_digest ~loc ~produced_targets : Digest.t Targets.Produced.t option Fiber.t = let open Fiber.O in let hex = Digest.to_string rule_digest in let pp_error msg = - let action = action () in Pp.concat - [ Pp.textf "cache store error [%s]: %s after executing" hex msg - ; Pp.space - ; Pp.char '(' - ; action - ; Pp.char ')' + [ Pp.textf + "cache store error [%s]: %s after executing action at %s" + hex + msg + (Loc.to_file_colon_line loc) ] in match @@ -600,7 +599,6 @@ let examine_targets_and_store ~loc ~rule_digest ~should_remove_write_permissions_on_generated_files - ~action ~(produced_targets : unit Targets.Produced.t) : Digest.t Targets.Produced.t Fiber.t = @@ -608,7 +606,7 @@ let examine_targets_and_store | Enabled { storage_mode = mode; reproducibility_check = _ } when can_go_in_shared_cache -> let open Fiber.O in - try_to_store_to_shared_cache ~mode ~rule_digest ~produced_targets ~action + try_to_store_to_shared_cache ~mode ~rule_digest ~produced_targets ~loc >>= (function | Some produced_targets_with_digests -> Fiber.return produced_targets_with_digests | None -> diff --git a/src/dune_cache/shared.mli b/src/dune_cache/shared.mli index 82943622bd3..a017ed281ad 100644 --- a/src/dune_cache/shared.mli +++ b/src/dune_cache/shared.mli @@ -28,6 +28,5 @@ val examine_targets_and_store -> loc:Loc.t -> rule_digest:Digest.t -> should_remove_write_permissions_on_generated_files:bool - -> action:(unit -> User_message.Style.t Pp.t) -> produced_targets:unit Targets.Produced.t -> Digest.t Targets.Produced.t Fiber.t diff --git a/src/dune_engine/action_to_sh.ml b/src/dune_engine/action_to_sh.ml deleted file mode 100644 index b29965dc7f0..00000000000 --- a/src/dune_engine/action_to_sh.ml +++ /dev/null @@ -1,202 +0,0 @@ -open Import - -module Simplified = struct - type destination = - | Dev_null - | File of string - - type source = string - - type t = - | Run of string * string list - | Chdir of string - | Setenv of string * string - | Redirect_out of t list * Action.Outputs.t * destination - | Redirect_in of t list * Action.Inputs.t * source - | Pipe of t list list * Action.Outputs.t - | Sh of string - | Concurrent of t list list -end - -open Simplified - -let echo s = - let lines = String.split_lines s in - if String.ends_with ~suffix:"\n" s - then List.map lines ~f:(fun s -> Run ("echo", [ s ])) - else ( - match List.rev lines with - | [] -> [ Run ("echo", [ "-n" ]) ] - | last :: rest -> - List.fold_left - rest - ~init:[ Run ("echo", [ "-n"; last ]) ] - ~f:(fun acc s -> Run ("echo", [ s ]) :: acc)) -;; - -let cat ps = Run ("cat", ps) -let mkdir p = Run ("mkdir", [ "-p"; p ]) - -let interpret_perm (perm : Action.File_perm.t) fn acc = - match perm with - | Normal -> acc - | Executable -> Run ("chmod", [ "+x"; fn ]) :: acc -;; - -let simplify act = - let rec loop (act : Action.For_shell.t) acc = - match act with - | Run (prog, args) -> Run (prog, Array.Immutable.to_list args) :: acc - | With_accepted_exit_codes (_, t) -> loop t acc - | Chdir (p, act) -> loop act (Chdir p :: mkdir p :: acc) - | Setenv (k, v, act) -> loop act (Setenv (k, v) :: acc) - | Redirect_out (outputs, fn, perm, act) -> - interpret_perm perm fn (Redirect_out (block act, outputs, File fn) :: acc) - | Redirect_in (inputs, fn, act) -> Redirect_in (block act, inputs, fn) :: acc - | Ignore (outputs, act) -> Redirect_out (block act, outputs, Dev_null) :: acc - | Progn l -> List.fold_left l ~init:acc ~f:(fun acc act -> loop act acc) - | Concurrent l -> Concurrent (List.map ~f:block l) :: acc - | Echo xs -> echo (String.concat xs ~sep:"") - | Cat x -> cat x :: acc - | Copy (x, y) -> Run ("cp", [ x; y ]) :: acc - | Symlink (x, y) -> Run ("ln", [ "-s"; x; y ]) :: Run ("rm", [ "-f"; y ]) :: acc - | Hardlink (x, y) -> Run ("ln", [ x; y ]) :: Run ("rm", [ "-f"; y ]) :: acc - | Bash x -> Run ("bash", [ "-e"; "-u"; "-o"; "pipefail"; "-c"; x ]) :: acc - | Write_file (x, perm, y) -> - interpret_perm perm x (Redirect_out (echo y, Stdout, File x) :: acc) - | Rename (x, y) -> Run ("mv", [ x; y ]) :: acc - | Remove_tree x -> Run ("rm", [ "-rf"; x ]) :: acc - | Mkdir x -> mkdir x :: acc - | Pipe (outputs, l) -> Pipe (List.map ~f:block l, outputs) :: acc - | Diff { optional; file1; file2; mode = Binary; directory_diffs = _ } -> - assert (not optional); - Run ("cmp", [ file1; file2 ]) :: acc - | Diff { optional = true; file1; file2; mode = _; directory_diffs = _ } -> - Sh - (Printf.sprintf - "test ! -e file1 -o ! -e file2 || diff %s %s" - (String.quote_for_shell file1) - (String.quote_for_shell file2)) - :: acc - | Diff { optional = false; file1; file2; mode = _; directory_diffs = _ } -> - Run ("diff", [ file1; file2 ]) :: acc - | Extension _ -> Sh "# extensions are not supported" :: acc - and block act = - match List.rev (loop act []) with - | [] -> [ Run ("true", []) ] - | l -> l - in - block act -;; - -let quote s = Pp.verbatim (String.quote_for_shell s) - -let rec block l = - match l with - | [ x ] -> pp x - | l -> - Pp.box - (Pp.concat - [ Pp.hvbox - ~indent:2 - (Pp.concat - [ Pp.char '{' - ; Pp.space - ; Pp.hvbox - (Pp.concat_map l ~sep:Pp.space ~f:(fun x -> - Pp.seq (pp x) (Pp.char ';'))) - ]) - ; Pp.space - ; Pp.char '}' - ]) - -and pp = function - | Run (prog, args) -> - Pp.hovbox - ~indent:2 - (Pp.concat - (quote prog :: List.concat_map args ~f:(fun arg -> [ Pp.space; quote arg ]))) - | Chdir dir -> Pp.hovbox ~indent:2 (Pp.concat [ Pp.verbatim "cd"; Pp.space; quote dir ]) - | Setenv (k, v) -> Pp.concat [ Pp.verbatim k; Pp.verbatim "="; quote v ] - | Sh s -> Pp.verbatim s - | Redirect_in (l, inputs, src) -> - let body = block l in - Pp.hovbox - ~indent:2 - (Pp.concat - [ body - ; Pp.space - ; Pp.verbatim - (match inputs with - | Stdin -> "<") - ; Pp.space - ; quote src - ]) - | Redirect_out (l, outputs, dest) -> - let body = block l in - Pp.hovbox - ~indent:2 - (Pp.concat - [ body - ; Pp.space - ; Pp.verbatim - (match outputs with - | Stdout -> ">" - | Stderr -> "2>" - | Outputs -> "&>") - ; Pp.space - ; quote - (match dest with - | Dev_null -> "/dev/null" - | File fn -> fn) - ]) - | Pipe (l, outputs) -> - let first_pipe, end_ = - match outputs with - | Stdout -> " | ", "" - | Outputs -> " 2>&1 | ", "" - | Stderr -> " 2> >( ", " 1>&2 )" - in - (match l with - | [] -> assert false - | first :: l -> - Pp.hovbox - ~indent:2 - (Pp.concat - ~sep:Pp.space - [ block first - ; Pp.verbatim first_pipe - ; Pp.concat ~sep:(Pp.verbatim " | ") (List.map l ~f:block) - ; Pp.verbatim end_ - ])) - | Concurrent t -> - (match t with - | [] -> Pp.verbatim "true" - | [ x ] -> block x - | x :: l -> - Pp.hovbox - ~indent:2 - (Pp.concat - [ Pp.char '(' - ; Pp.space - ; block x - ; Pp.space - ; Pp.char '&' - ; Pp.space - ; Pp.concat ~sep:(Pp.verbatim "&") (List.map l ~f:block) - ; Pp.space - ; Pp.char '&' - ; Pp.space - ; Pp.verbatim "wait" - ; Pp.space - ; Pp.verbatim ")" - ])) -;; - -let rec pp_seq = function - | [] -> Pp.verbatim "true" - | [ x ] -> pp x - | x :: l -> Pp.concat [ pp x; Pp.char ';'; Pp.cut; pp_seq l ] -;; - -let pp act = pp_seq (simplify act) diff --git a/src/dune_engine/action_to_sh.mli b/src/dune_engine/action_to_sh.mli deleted file mode 100644 index a7ff641f74b..00000000000 --- a/src/dune_engine/action_to_sh.mli +++ /dev/null @@ -1,3 +0,0 @@ -(** Convert an action to a shell command suitable for [/bin/sh] *) - -val pp : Action.For_shell.t -> _ Pp.t diff --git a/src/dune_engine/build_system.ml b/src/dune_engine/build_system.ml index 5ee581edfec..f19454bb8a8 100644 --- a/src/dune_engine/build_system.ml +++ b/src/dune_engine/build_system.ml @@ -698,7 +698,6 @@ end = struct .should_remove_write_permissions_on_generated_files execution_parameters) ~produced_targets:exec_result.produced_targets - ~action:(fun () -> Action.for_shell action.action |> Action_to_sh.pp) in let dynamic_deps_stages = List.map diff --git a/src/dune_engine/dune_engine.ml b/src/dune_engine/dune_engine.ml index 653627f77af..4586bffee02 100644 --- a/src/dune_engine/dune_engine.ml +++ b/src/dune_engine/dune_engine.ml @@ -24,7 +24,6 @@ module Load_rules = Load_rules module Clflags = Clflags module Response_file = Response_file module File_selector = File_selector -module Action_to_sh = Action_to_sh module Hooks = Hooks module Print_diff = Print_diff module Diff_promotion = Diff_promotion diff --git a/test/blackbox-tests/test-cases/dune-cache/repro-check.t b/test/blackbox-tests/test-cases/dune-cache/repro-check.t index a95dc3419ac..33e68efa658 100644 --- a/test/blackbox-tests/test-cases/dune-cache/repro-check.t +++ b/test/blackbox-tests/test-cases/dune-cache/repro-check.t @@ -70,7 +70,7 @@ Set 'cache-check-probability' to 1.0, which should trigger the check Warning: cache store error [5e64608154a3ed6c86e3d606ac67f24b]: ((in_cache ((non-reproducible 7378fb2d7d80dc4468d6558d864f0897))) (computed ((non-reproducible 074ebdc1c3853f27c68566d8d183032c)))) after executing - (echo 'build non-reproducible';cp dep non-reproducible) + action at dune:6 build reproducible build non-reproducible @@ -123,7 +123,7 @@ Test that the environment variable and the command line flag work too Warning: cache store error [5e64608154a3ed6c86e3d606ac67f24b]: ((in_cache ((non-reproducible 7378fb2d7d80dc4468d6558d864f0897))) (computed ((non-reproducible 074ebdc1c3853f27c68566d8d183032c)))) after executing - (echo 'build non-reproducible';cp dep non-reproducible) + action at dune:6 build reproducible build non-reproducible @@ -135,7 +135,7 @@ Test that the environment variable and the command line flag work too Warning: cache store error [5e64608154a3ed6c86e3d606ac67f24b]: ((in_cache ((non-reproducible 7378fb2d7d80dc4468d6558d864f0897))) (computed ((non-reproducible 074ebdc1c3853f27c68566d8d183032c)))) after executing - (echo 'build non-reproducible';cp dep non-reproducible) + action at dune:6 build reproducible build non-reproducible diff --git a/test/expect-tests/dune_engine/action_to_sh_tests.ml b/test/expect-tests/dune_engine/action_to_sh_tests.ml deleted file mode 100644 index f2ecfe4dccb..00000000000 --- a/test/expect-tests/dune_engine/action_to_sh_tests.ml +++ /dev/null @@ -1,247 +0,0 @@ -open Stdune -open Dune_engine -open Action.For_shell -module Action = Dune_engine.Action - -let print x = x |> Action_to_sh.pp |> Dune_tests_common.print - -let%expect_test "run" = - Run ("my_program", Array.Immutable.of_array [| "my"; "-I"; "args" |]) |> print; - [%expect - {| - my_program my -I args |}] -;; - -(* TODO dynamic-run *) - -let%expect_test "chdir" = - Chdir ("foo", Bash "echo Hello world") |> print; - [%expect - {| - mkdir -p foo;cd foo; - bash -e -u -o pipefail -c 'echo Hello world' |}] -;; - -let%expect_test "setenv" = - Setenv ("FOO", "bar", Bash "echo Hello world") |> print; - [%expect - {| - FOO=bar; - bash -e -u -o pipefail -c 'echo Hello world' |}] -;; - -let%expect_test "with-stdout-to" = - Redirect_out - (Action.Outputs.Stdout, "foo", Action.File_perm.Normal, Bash "echo Hello world") - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' > foo |}] -;; - -let%expect_test "with-stderr-to" = - Redirect_out - (Action.Outputs.Stderr, "foo", Action.File_perm.Normal, Bash "echo Hello world") - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' 2> foo |}] -;; - -let%expect_test "with-outputs-to" = - Redirect_out - ( Action.Outputs.Outputs - , "foo" - , Action.File_perm.Normal - , Progn [ Bash "first something"; Bash "then"; Bash "echo Hello world" ] ) - |> print; - [%expect - {| - { - bash -e -u -o pipefail -c 'first something'; - bash -e -u -o pipefail -c then; - bash -e -u -o pipefail -c 'echo Hello world'; - } &> foo |}] -;; - -let%expect_test "with-outputs-to executable" = - Redirect_out - (Action.Outputs.Outputs, "foo", Action.File_perm.Executable, Bash "echo Hello world") - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' &> foo; - chmod +x foo |}] -;; - -let%expect_test "ignore stdout" = - Ignore (Action.Outputs.Stdout, Bash "echo Hello world") |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' > /dev/null |}] -;; - -let%expect_test "ignore stderr" = - Ignore (Action.Outputs.Stderr, Bash "echo Hello world") |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' 2> /dev/null |}] -;; - -let%expect_test "ignore outputs" = - Ignore (Action.Outputs.Outputs, Bash "echo Hello world") |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' &> /dev/null |}] -;; - -let%expect_test "with-stdin-from" = - Redirect_in - ( Action.Inputs.Stdin - , "foo" - , Bash - {| - while read line; do - echo $line - done - |} - ) - |> print; - [%expect - {| - bash -e -u -o pipefail -c - ' - while read line; do - echo $line - done - ' < foo |}] -;; - -(* TODO currently no special printing for with-accepted-exit-codes *) -let%expect_test "with-accepted-exit-codes" = - With_accepted_exit_codes - ( Predicate_lang.of_list [ 0; 1; 123 ] - , Bash - {| - echo Hello world - exit 123 - |} - ) - |> print; - [%expect - {| - bash -e -u -o pipefail -c ' - echo Hello world - exit 123 - ' |}] -;; - -let%expect_test "progn" = - Progn [ Bash "echo Hello"; Bash "echo world" ] |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello'; - bash -e -u -o pipefail -c 'echo world' |}] -;; - -let%expect_test "concurrent" = - Concurrent [ Bash "echo Hello"; Bash "echo world" ] |> print; - [%expect - {| - ( bash -e -u -o pipefail -c 'echo Hello' & - bash -e -u -o pipefail -c 'echo world' & wait ) |}] -;; - -let%expect_test "echo" = - Echo [ "Hello"; "world" ] |> print; - [%expect - {| - echo -n Helloworld |}] -;; - -let%expect_test "write-file" = - Write_file ("foo", Action.File_perm.Normal, "Hello world") |> print; - [%expect - {| - echo -n 'Hello world' > foo |}] -;; - -let%expect_test "write-file executable" = - Write_file ("foo", Action.File_perm.Executable, "Hello world") |> print; - [%expect - {| - echo -n 'Hello world' > foo; - chmod +x foo |}] -;; - -let%expect_test "cat" = - Cat [ "foo" ] |> print; - [%expect - {| - cat foo |}] -;; - -let%expect_test "cat multiple" = - Cat [ "foo"; "bar" ] |> print; - [%expect - {| - cat foo bar |}] -;; - -let%expect_test "copy" = - Copy ("foo", "bar") |> print; - [%expect - {| - cp foo bar |}] -;; - -let%expect_test "bash" = - Bash "echo Hello world" |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' |}] -;; - -(* cmping a binary file in optional mode is not supported *) - -let%expect_test "pipe-stdout-to" = - Pipe - ( Action.Outputs.Stdout - , [ Bash "echo Hello world" - ; Redirect_out - (Action.Outputs.Stdout, "foo", Action.File_perm.Normal, Bash "echo Hello world") - ] ) - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' | - bash -e -u -o pipefail -c 'echo Hello world' > foo |}] -;; - -let%expect_test "pipe-stderr-to" = - Pipe - ( Action.Outputs.Stderr - , [ Bash "echo Hello world" - ; Redirect_out - (Action.Outputs.Stderr, "foo", Action.File_perm.Normal, Bash "echo Hello world") - ] ) - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' 2> >( - bash -e -u -o pipefail -c 'echo Hello world' 2> foo 1>&2 ) |}] -;; - -let%expect_test "pipe-outputs-to" = - Pipe - ( Action.Outputs.Outputs - , [ Bash "echo Hello world" - ; Redirect_out - (Action.Outputs.Outputs, "foo", Action.File_perm.Normal, Bash "echo Hello world") - ] ) - |> print; - [%expect - {| - bash -e -u -o pipefail -c 'echo Hello world' 2>&1 | - bash -e -u -o pipefail -c 'echo Hello world' &> foo |}] -;; diff --git a/test/expect-tests/dune_engine/dune b/test/expect-tests/dune_engine/dune deleted file mode 100644 index e9fe712003c..00000000000 --- a/test/expect-tests/dune_engine/dune +++ /dev/null @@ -1,16 +0,0 @@ -(library - (name dune_engine_test) - (inline_tests) - (libraries - dune_tests_common - predicate_lang - stdune - dune_engine - ;; This is because of the (implicit_transitive_deps false) - ;; in dune-project - ppx_expect.config - ppx_expect.config_types - base - ppx_inline_test.config) - (preprocess - (pps ppx_expect)))