summaryrefslogtreecommitdiffstats
path: root/scripts/native-intercept
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 17:01:08 +0000
commit096c9037bc8376c162ca364e23cc23d92d4c04f8 (patch)
tree7992a93e776cc2c8a16c3b92261e7c6433a6cc80 /scripts/native-intercept
parent921d3aa667ce7df03012d9ecbb62fb91f60ebf07 (diff)
downloadpoky-096c9037bc8376c162ca364e23cc23d92d4c04f8.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. (From OE-Core rev: 59922c95fcb20c66634c5677012d490be2246b0b) Signed-off-by: Jacob Kroon <jacob.kroon@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/native-intercept')
-rwxr-xr-xscripts/native-intercept/ar32
1 files changed, 32 insertions, 0 deletions
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 @@
1#!/usr/bin/env python3
2#
3# Wrapper around 'ar' that defaults to deterministic archives
4
5import os
6import shutil
7import sys
8
9# calculate path to the real 'ar'
10path = os.environ['PATH']
11path = path.replace(os.path.dirname(sys.argv[0]), '')
12real_ar = shutil.which('ar', path=path)
13
14if len(sys.argv) == 1:
15 os.execl(real_ar, 'ar')
16
17# modify args to mimic 'ar' configured with --default-deterministic-archives
18argv = sys.argv
19if argv[1].startswith('--'):
20 # No modifier given
21 None
22else:
23 # remove the optional '-'
24 if argv[1][0] == '-':
25 argv[1] = argv[1][1:]
26 if 'U' in argv[1]:
27 sys.stderr.write("ar: non-deterministic mode requested\n")
28 else:
29 argv[1] = argv[1].replace('u', '')
30 argv[1] = 'D' + argv[1]
31
32os.execv(real_ar, argv)