Make gcc-aarch64 reproducible (#366)

This fixes https://github.com/postmarketOS/binary-package-repo/issues/1

GCC generates hardlinks between files `A` and `B` in its `make install` step. The problem is, that `tar` randomly packages `A` as full binary, and links `B` to `A`, or the other way around! I was able to reproduce this issue consistently when re-building `gcc-aarch64` on Travis CI (interestingly, this did not appear for `gcc-armhf`).

The fix is, to delete `B` and create a symlink `B` that points to `A` instead.
This commit is contained in:
Oliver Smith 2017-08-12 14:06:02 +00:00 committed by GitHub
parent 55b32da086
commit a65e7d034b
2 changed files with 72 additions and 42 deletions

View file

@ -12,6 +12,41 @@ LANG_FORTRAN=false
LANG_ADA=false
options="!strip !tracedeps"
# Wrap the package function, to make the resulting package
# lazy-reproducible
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
# Unmodified package function from the gcc APKBUILD
_package
# Workaround for: postmarketOS/binary-package-repo#1
echo "Replacing hardlinks with symlinks"
rm -v "$pkgdir"/usr/bin/"$CTARGET"-c++
ln -s -v /usr/bin/"$CTARGET"-g++ "$pkgdir"/usr/bin/"$CTARGET"-c++
rm -v "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
ln -s -v /usr/bin/"$CTARGET"-gcc "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
}
pkgname="gcc-aarch64"
pkgver=6.4.0
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
@ -320,27 +355,7 @@ build() {
make
}
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
_package() {
cd "$_builddir"
make -j1 DESTDIR="${pkgdir}" install

View file

@ -12,6 +12,41 @@ LANG_FORTRAN=false
LANG_ADA=false
options="!strip !tracedeps"
# Wrap the package function, to make the resulting package
# lazy-reproducible
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
# Unmodified package function from the gcc APKBUILD
_package
# Workaround for: postmarketOS/binary-package-repo#1
echo "Replacing hardlinks with symlinks"
rm -v "$pkgdir"/usr/bin/"$CTARGET"-c++
ln -s -v /usr/bin/"$CTARGET"-g++ "$pkgdir"/usr/bin/"$CTARGET"-c++
rm -v "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
ln -s -v /usr/bin/"$CTARGET"-gcc "$pkgdir"/usr/bin/"$CTARGET"-gcc-"$pkgver"
}
pkgname="gcc-armhf"
pkgver=6.4.0
[ "$BOOTSTRAP" = "nolibc" ] && pkgname="gcc-pass2"
@ -320,27 +355,7 @@ build() {
make
}
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
_package() {
cd "$_builddir"
make -j1 DESTDIR="${pkgdir}" install