From 35794f79cfbc15cea52015663c14c3a574a3c1fc Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Fri, 24 May 2024 16:35:41 +0200 Subject: [PATCH] [3.15] backport mac CI fixes (#10571) * fix(test): silence duplicate -lc++ warnings on mac (#10468) When linking C++ on recent macos versions, the linker will emit a duplicate `-lc++` warning which we can silence in the test suite. Signed-off-by: Etienne Millon * test: fixes to version-corruption.t (#10469) * refactor(test): rewrite compare.sh in ocaml This removes the external dependencies and makes intent clearer. The count changes because it was counting the numbers of characters differing in the hexdump instead of a byte count. Signed-off-by: Etienne Millon * fix(test): disable version-corruption.t on mac When codesigning triggers, the binary layout is completely changed to it's not meaningful to count the number of changed bytes Signed-off-by: Etienne Millon --------- Signed-off-by: Etienne Millon * ci: run build on macOS x86_64 again (#10481) Signed-off-by: Antonio Nuno Monteiro * test: fix truncate on macOS (#10361) Signed-off-by: Thomas Gazagnaire --------- Signed-off-by: Etienne Millon Signed-off-by: Antonio Nuno Monteiro Signed-off-by: Thomas Gazagnaire Co-authored-by: Antonio Nuno Monteiro Co-authored-by: Thomas Gazagnaire --- .github/workflows/workflow.yml | 4 ++ .../test-cases/corrupt-persistent.t | 3 +- .../test-cases/cxx-flags.t/dune | 23 +++++++++ test/blackbox-tests/test-cases/dune | 7 ++- .../test-cases/version-corruption.t | 48 +++++++++++-------- 5 files changed, 63 insertions(+), 22 deletions(-) mode change 100755 => 100644 test/blackbox-tests/test-cases/version-corruption.t diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d3d485f795d..f2642cac0b2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,6 +44,10 @@ jobs: - ocaml-compiler: 5.1.x os: macos-latest skip_test: true + # macOS x86_64 (Intel) + - ocaml-compiler: 4.14.x + os: macos-13 + skip_test: true # OCaml 4: - ocaml-compiler: 4.13.x os: ubuntu-latest diff --git a/test/blackbox-tests/test-cases/corrupt-persistent.t b/test/blackbox-tests/test-cases/corrupt-persistent.t index f1caf9fe1a0..4c1f397e6b1 100644 --- a/test/blackbox-tests/test-cases/corrupt-persistent.t +++ b/test/blackbox-tests/test-cases/corrupt-persistent.t @@ -10,11 +10,10 @@ Delete last 10 chars of the .db file to corrupt it - $ truncate --size=-10 _build/.db + $ truncate -s -10 _build/.db Dune log the corrupted file and recover $ dune build a $ grep "truncated object" _build/log # Failed to load corrupted file _build/.db: input_value: truncated object - diff --git a/test/blackbox-tests/test-cases/cxx-flags.t/dune b/test/blackbox-tests/test-cases/cxx-flags.t/dune index 6f4cc7ca904..a3c46259b87 100644 --- a/test/blackbox-tests/test-cases/cxx-flags.t/dune +++ b/test/blackbox-tests/test-cases/cxx-flags.t/dune @@ -8,3 +8,26 @@ (libraries quad) (foreign_stubs (language cxx) (names bazexe)) (modules main)) + +(env + (_ + (ocamlopt_flags + :standard + (:include extra_flags.sexp)))) + +(rule + (enabled_if + (or + (<> %{system} macosx) + (<> %{architecture} arm64))) + (action + (write-file extra_flags.sexp "()"))) + +; with XCode 15+, the linker complains about duplicate -lc++ libraries +(rule + (enabled_if + (and + (= %{system} macosx) + (= %{architecture} arm64))) + (action + (write-file extra_flags.sexp "(-ccopt -Wl,-no_warn_duplicate_libraries)"))) diff --git a/test/blackbox-tests/test-cases/dune b/test/blackbox-tests/test-cases/dune index a90bb873a78..956401d7b71 100644 --- a/test/blackbox-tests/test-cases/dune +++ b/test/blackbox-tests/test-cases/dune @@ -129,7 +129,12 @@ (cram (applies_to version-corruption) - (deps %{bin:od} %{bin:git} %{bin:cmp} %{bin:sed} %{bin:chmod})) + (deps %{bin:git} %{bin:chmod}) + (enabled_if + ; code signing moves placeholders in the binary + (or + (<> %{system} macosx) + (<> %{architecture} arm64)))) (cram (applies_to github8041) diff --git a/test/blackbox-tests/test-cases/version-corruption.t b/test/blackbox-tests/test-cases/version-corruption.t old mode 100755 new mode 100644 index c1ac480b550..93156474483 --- a/test/blackbox-tests/test-cases/version-corruption.t +++ b/test/blackbox-tests/test-cases/version-corruption.t @@ -1,18 +1,25 @@ -Define a helper ./dump.sh unction with offsets removed, and one byte per line in -hex (so that the output is compiler version / alignment independent). +Define a helper program that counts how many bytes differ between two files. - $ cat >./dump.sh <<'EOF' - > set -eu - > od -v -A n -t x1 $1 | tr ' ' '\n' | sed '/^$/d' + $ cat > compare.ml << EOF + > let count_different_bytes s1 s2 = + > if String.length s1 <> String.length s2 then + > failwith "This test is only meaningful for files with the same length"; + > let c = ref 0 in + > String.iteri (fun i c1 -> + > let c2 = String.unsafe_get s2 i in + > if not (Char.equal c1 c2) then + > incr c; + > ) s1; + > !c + > + > let read_all path = In_channel.with_open_bin path In_channel.input_all + > + > let () = + > let s1 = read_all Sys.argv.(1) in + > let s2 = read_all Sys.argv.(2) in + > let n = count_different_bytes s1 s2 in + > Printf.printf "%d\n" n > EOF - $ chmod +x ./dump.sh - $ cat >./compare.sh <<'EOF' - > set -eu - > ./dump.sh $1 >$1.dump - > ./dump.sh $2 >$2.dump - > cmp -l $1.dump $2.dump | wc -l | sed -e 's/^ *//' - > EOF - $ chmod +x compare.sh A repro that builds and installs multiple binaries, and promotes a bytecode and native executable in same rule (this is very likely to detect corruption with @@ -97,12 +104,15 @@ shared buffer): $ rm -f gen_lifecycle.bc gen_lifecycle.exe && dune clean && dune build && ./gen_lifecycle.exe >/dev/null $ cp _build/default/gen_lifecycle.exe gen_lifecycle.old +We compare the substituted version with the original. The expected value is 64, +which corresponds to `~min_len` in Link_time_code_gen. + $ dune install -j16 --prefix=./_install - $ ./compare.sh _build/default/gen1.exe _install/bin/gen1 - 100 + $ ocaml ./compare.ml _build/default/gen1.exe _install/bin/gen1 + 64 - $ ./compare.sh _build/default/gen2.bc _install/bin/gen2 - 100 + $ ocaml compare.ml _build/default/gen2.bc _install/bin/gen2 + 64 $ dune build --debug-artifact-substitution Found placeholder in _build/default/gen_lifecycle.exe: @@ -112,8 +122,8 @@ shared buffer): - placeholder: Vcs_describe In_source_tree "." - evaluates to: "v0.0.1" - $ ./compare.sh gen_lifecycle.old ./gen_lifecycle.exe - 100 + $ ocaml compare.ml gen_lifecycle.old ./gen_lifecycle.exe + 64 $ ./gen_lifecycle.exe 0.0.1