summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJacob Kroon <jacob.kroon@gmail.com>2021-11-24 06:31:10 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-26 16:58:55 +0000
commit59922c95fcb20c66634c5677012d490be2246b0b (patch)
tree2049240fb1846bea95cfc6458bff438d8e142891 /scripts
parente0010af733825ed1050fd3342cf3ef1c478df1a0 (diff)
downloadopenembedded-core-contrib-59922c95fcb20c66634c5677012d490be2246b0b.tar.gz
native/cross: Add ar wrapper for determinism
Add a wrapper around ar calls for native/cross recipes. This wrapper adds the -D option so that deterministic archives are built for native/cross output. This improves the changes of hash equivalence matches and hence build artefact reuse. We don't need this in the target case since we compile binutils-cross with an option making this the default. We need a wrapper since we need to remove the "u" option and replace it with "D" but also allow things like "--version" to continue to work too. Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
l---------scripts/cross-intercept/ar1
-rwxr-xr-xscripts/native-intercept/ar32
2 files changed, 33 insertions, 0 deletions
diff --git a/scripts/cross-intercept/ar b/scripts/cross-intercept/ar
new file mode 120000
index 0000000000..bc68ffd7a2
--- /dev/null
+++ b/scripts/cross-intercept/ar
@@ -0,0 +1 @@
+../native-intercept/ar \ No newline at end of file
diff --git a/scripts/native-intercept/ar b/scripts/native-intercept/ar
new file mode 100755
index 0000000000..dcc623e3ed
--- /dev/null
+++ b/scripts/native-intercept/ar
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+#
+# Wrapper around 'ar' that defaults to deterministic archives
+
+import os
+import shutil
+import sys
+
+# calculate path to the real 'ar'
+path = os.environ['PATH']
+path = path.replace(os.path.dirname(sys.argv[0]), '')
+real_ar = shutil.which('ar', path=path)
+
+if len(sys.argv) == 1:
+ os.execl(real_ar, 'ar')
+
+# modify args to mimic 'ar' configured with --default-deterministic-archives
+argv = sys.argv
+if argv[1].startswith('--'):
+ # No modifier given
+ None
+else:
+ # remove the optional '-'
+ if argv[1][0] == '-':
+ argv[1] = argv[1][1:]
+ if 'U' in argv[1]:
+ sys.stderr.write("ar: non-deterministic mode requested\n")
+ else:
+ argv[1] = argv[1].replace('u', '')
+ argv[1] = 'D' + argv[1]
+
+os.execv(real_ar, argv)