Skip to content
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

Add a flag --debug-artifact-substitution to help debug problems related to dune-build-info #3589

Merged
2 commits merged into from Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ next

- Fix crash when caching is enabled (@rgrinberg, #3581, fixes #3580)

- Add a `--debug-artifact-substution` flag to help debug problem with
version not being captured by `dune-build-info` (#3589,
@jeremiedimino)

2.6.0 (05/06/2020)
------------------

Expand Down
9 changes: 9 additions & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type t =
{ debug_dep_path : bool
; debug_findlib : bool
; debug_backtraces : bool
; debug_artifact_substitution : bool
; profile : Profile.t option
; workspace_file : Arg.Path.t option
; root : Workspace_root.t
Expand Down Expand Up @@ -81,6 +82,7 @@ let set_common_other ?log_file c ~targets =
Clflags.debug_dep_path := c.debug_dep_path;
Clflags.debug_findlib := c.debug_findlib;
Clflags.debug_backtraces c.debug_backtraces;
Clflags.debug_artifact_substitution := c.debug_artifact_substitution;
Clflags.capture_outputs := c.capture_outputs;
Clflags.diff_command := c.diff_command;
Clflags.promote := c.promote;
Expand Down Expand Up @@ -473,6 +475,12 @@ let term =
value & flag
& info [ "debug-backtraces" ] ~docs
~doc:{|Always print exception backtraces.|})
and+ debug_artifact_substitution =
Arg.(
value & flag
& info
[ "debug-artifact-substitution" ]
~docs ~doc:"Print debugging info about artifact substitution")
and+ terminal_persistence =
Arg.(
value
Expand Down Expand Up @@ -652,6 +660,7 @@ let term =
{ debug_dep_path
; debug_findlib
; debug_backtraces
; debug_artifact_substitution
; profile
; capture_outputs = not no_buffer
; workspace_file
Expand Down
4 changes: 2 additions & 2 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ module File_ops_real (W : Workspace) : File_operations = struct
| Some Dune_package ->
copy_special_file ~src ~package ~ic ~oc ~f:process_dune_package
| None ->
Dune.Artifact_substitution.copy ~get_vcs ~input:(input ic)
~output:(output oc))
Dune.Artifact_substitution.copy ~get_vcs ~input_file:src
~input:(input ic) ~output:(output oc))

let remove_if_exists dst =
if Path.exists dst then (
Expand Down
14 changes: 14 additions & 0 deletions otherlibs/build-info/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ Check what the generated build info module looks like:
; "dune-build-info", Some "XXX"
]

Test --debug-artifact-substitution
----------------------------------

$ dune install --prefix _install --debug-artifact-substitution 2>&1|grep -v '^\(Installing\|Deleting\)'
Found placeholder in _build/install/default/bin/c:
- placeholder: Vcs_describe "c"
- evaluates to: "1.0+c"
Found placeholder in _build/install/default/bin/c:
- placeholder: Vcs_describe "b"
- evaluates to: "1.0+b"
Found placeholder in _build/install/default/bin/c:
- placeholder: Vcs_describe "a"
- evaluates to: "1.0+a"

Test substitution when promoting
--------------------------------

Expand Down
15 changes: 13 additions & 2 deletions src/dune/artifact_substitution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ output the replacement | |
| |
\--------------------------------------------------------------------------/
v} *)
let copy ~get_vcs ~input ~output =
let copy ~get_vcs ~input_file ~input ~output =
let open Fiber.O in
let rec loop scanner_state ~beginning_of_data ~pos ~end_of_data =
let scanner_state = Scanner.run scanner_state ~buf ~pos ~end_of_data in
Expand All @@ -355,6 +355,16 @@ let copy ~get_vcs ~input ~output =
match decode placeholder with
| Some t ->
let* s = eval t ~get_vcs in
( if !Clflags.debug_artifact_substitution then
let open Pp.O in
Console.print
[ Pp.textf "Found placeholder in %s:"
(Path.to_string_maybe_quoted input_file)
; Pp.enumerate ~f:Fun.id
[ Pp.text "placeholder: " ++ Dyn.pp (to_dyn t)
; Pp.text "evaluates to: " ++ Dyn.pp (String s)
]
] );
let s = encode_replacement ~len ~repl:s in
output (Bytes.unsafe_of_string s) 0 len;
let pos = placeholder_start + len in
Expand Down Expand Up @@ -409,4 +419,5 @@ let copy_file ~get_vcs ?chmod ~src ~dst () =
~finally:(fun () ->
Io.close_both (ic, oc);
Fiber.return ())
(fun () -> copy ~get_vcs ~input:(input ic) ~output:(output oc))
(fun () ->
copy ~get_vcs ~input_file:src ~input:(input ic) ~output:(output oc))
6 changes: 5 additions & 1 deletion src/dune/artifact_substitution.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ val copy_file :

(** Generic version of [copy_file]. Rather than filenames, it takes an input and
output functions. Their semantic must match the ones of the [input] and
[output] functions from the OCaml standard library. *)
[output] functions from the OCaml standard library.

[input_file] is used only for debugging purposes. It must be the name of the
source file. *)
val copy :
get_vcs:(Path.Source.t -> Vcs.t option)
-> input_file:Path.t
-> input:(Bytes.t -> int -> int -> int)
-> output:(Bytes.t -> int -> int -> unit)
-> unit Fiber.t
Expand Down
2 changes: 2 additions & 0 deletions src/dune/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let debug_findlib = ref false

let debug_dep_path = ref false

let debug_artifact_substitution = ref false

let external_lib_deps_hint = ref []

let external_lib_deps_mode = ref false
Expand Down
3 changes: 3 additions & 0 deletions src/dune/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ val capture_outputs : bool ref
(** Always print backtraces, to help debugging dune itself *)
val debug_backtraces : bool -> unit

(** Print debug info about artifact substitution *)
val debug_artifact_substitution : bool ref

(** Command to use to diff things *)
val diff_command : string option ref

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ let test input =
to_copy
in
let output = Buffer.add_subbytes buf in
Artifact_substitution.copy ~get_vcs:(fun _ -> None) ~input ~output);
Artifact_substitution.copy
~get_vcs:(fun _ -> None)
~input_file:(Path.of_string "<memory>")
~input ~output);
let result = Buffer.contents buf in
if result <> expected then
fail
Expand Down