From c84d18788a9aa841affaaab3463aa0d930ac8f14 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Tue, 30 Jan 2024 12:06:08 +0100 Subject: [PATCH] fix(boot): sort readdir output for reproducibility 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 --- boot/duneboot.ml | 10 +++++----- doc/changes/9861-readdir-boot.md | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 doc/changes/9861-readdir-boot.md diff --git a/boot/duneboot.ml b/boot/duneboot.ml index b5159ecb50f..7f41ce23645 100644 --- a/boot/duneboot.ml +++ b/boot/duneboot.ml @@ -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 = diff --git a/doc/changes/9861-readdir-boot.md b/doc/changes/9861-readdir-boot.md new file mode 100644 index 00000000000..bb0c54b7b4d --- /dev/null +++ b/doc/changes/9861-readdir-boot.md @@ -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)