From 5eb9b92e7b02e2aa6017dba4e641a9fe9193af6e Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 4 Aug 2017 20:38:27 +0000 Subject: [PATCH] Fix: gcc-armhf not reproducible (#64) (#333) libstdc++.a from gcc-armhf was not reproducible on Travis (it was, when built locally!). These .a files are just archives of object files .o, and in this case it was caused by a random order of the .o files in the archive. This PR patches the package() function of the APKBUILD when running pmbootstrap aportgen gcc-armhf (same for aarch64 of course), to extract all .a files, and repack them to be reproducible (by sorting the files before packing them). As usually, we can still inherit everything from the upstream gcc aport from Alpine, and apply our changes on top of that. Travis without the patch: https://api.travis-ci.org/jobs/260402679/log.txt?deansi=true > CHALLENGE FAILED for usr/armv6-alpine-linux-muslgnueabihf/lib/libstdc++.a:File 'usr/armv6-alpine-linux-muslgnueabihf/lib/libstdc++.a' is different! Travis with the patch (I've instructed Travis to run off this branch to test it): https://api.travis-ci.org/jobs/260806203/log.txt?deansi=true > Done. Your build exited with 0. --- aports/cross/gcc-aarch64/APKBUILD | 20 ++++++++++++++++++++ aports/cross/gcc-armhf/APKBUILD | 20 ++++++++++++++++++++ pmb/aportgen/gcc.py | 28 +++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/aports/cross/gcc-aarch64/APKBUILD b/aports/cross/gcc-aarch64/APKBUILD index 3c03c491..e752c595 100644 --- a/aports/cross/gcc-aarch64/APKBUILD +++ b/aports/cross/gcc-aarch64/APKBUILD @@ -321,6 +321,26 @@ build() { } package() { + # Repack the *.a files to be reproducible (see #64) + _temp="$_builddir"/_reproducible-patch + cd "$_builddir" + for f in $(find -name '*.a'); do + # Copy to a temporary folder + echo "Repack $f to be reproducible" + mkdir -p "$_temp" + cd "$_temp" + cp "$_builddir"/"$f" . + + # Repack with a sorted file order + ar x *.a + rm *.a + ar r sorted.a $(find -name '*.o' | sort) + + # Copy back and clean up + cp -v sorted.a "$_builddir"/"$f" + cd .. + rm -r "$_temp" + done cd "$_builddir" make -j1 DESTDIR="${pkgdir}" install diff --git a/aports/cross/gcc-armhf/APKBUILD b/aports/cross/gcc-armhf/APKBUILD index 7f63fc08..1005221d 100644 --- a/aports/cross/gcc-armhf/APKBUILD +++ b/aports/cross/gcc-armhf/APKBUILD @@ -321,6 +321,26 @@ build() { } package() { + # Repack the *.a files to be reproducible (see #64) + _temp="$_builddir"/_reproducible-patch + cd "$_builddir" + for f in $(find -name '*.a'); do + # Copy to a temporary folder + echo "Repack $f to be reproducible" + mkdir -p "$_temp" + cd "$_temp" + cp "$_builddir"/"$f" . + + # Repack with a sorted file order + ar x *.a + rm *.a + ar r sorted.a $(find -name '*.o' | sort) + + # Copy back and clean up + cp -v sorted.a "$_builddir"/"$f" + cd .. + rm -r "$_temp" + done cd "$_builddir" make -j1 DESTDIR="${pkgdir}" install diff --git a/pmb/aportgen/gcc.py b/pmb/aportgen/gcc.py index 2ade84fe..f7c67318 100644 --- a/pmb/aportgen/gcc.py +++ b/pmb/aportgen/gcc.py @@ -57,7 +57,33 @@ def generate(args, pkgname): # Do not package libstdc++, do not add "g++-$ARCH" here (already # did that explicitly in the subpackages variable above, so # pmbootstrap picks it up properly). - '*subpackages="$subpackages libstdc++:libcxx:*': None + '*subpackages="$subpackages libstdc++:libcxx:*': None, + + # libstdc++.a is not reproducible by default (.a files are archives of + # object files, and these object files are inside the .a file in a random + # order!). The best way would be to patch this upstream in gcc, but for now + # we repackage the .a files to make sure, that they are reproducible. + '*package() {*': """package() { + # Repack the *.a files to be reproducible (see #64) + _temp="$_builddir"/_reproducible-patch + cd "$_builddir" + for f in $(find -name '*.a'); do + # Copy to a temporary folder + echo "Repack $f to be reproducible" + mkdir -p "$_temp" + cd "$_temp" + cp "$_builddir"/"$f" . + + # Repack with a sorted file order + ar x *.a + rm *.a + ar r sorted.a $(find -name '*.o' | sort) + + # Copy back and clean up + cp -v sorted.a "$_builddir"/"$f" + cd .. + rm -r "$_temp" + done""" } pmb.aportgen.core.rewrite(