Skip to content

Commit

Permalink
fix(boot): sort readdir output for reproducibility (#9861)
Browse files Browse the repository at this point in the history
Fixes #9794

`_boot/dune.exe` is installed, so it needs to be reproducible. This
change ensures that the source files are scanned in an order that is
independent from the underlying directory entries.

This has been tested with `disorderfs --shuffle-dirents=yes`: two runs
of `make bootstrap` create the same binary.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Jan 30, 2024
1 parent be8d343 commit 32d5302
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions boot/duneboot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ module Status_line = struct
let () = at_exit (fun () -> Printf.printf "\r%*s\r" (String.length !displayed) "")
end

(* Return list of entries in [path] as [path/entry] *)
(* Return a sorted list of entries in [path] as [path/entry] *)
let readdir path =
Array.fold_right
~f:(fun entry dir -> (path ^/ entry) :: dir)
~init:[]
(Sys.readdir path)
Sys.readdir path
|> Array.to_list
|> List.map ~f:(fun entry -> path ^/ entry)
|> List.sort ~cmp:String.compare
;;

let open_out file =
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/9861-readdir-boot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- boot: sort directory entries in readdir. This makes the dune binary
reproducible in terms of filesystem order. (#9861, fixes #9794, @emillon)

0 comments on commit 32d5302

Please sign in to comment.