On 11/22/21 17:58, Richard Purdie wrote:
> On Mon, 2021-11-22 at 16:41 +0000, Richard Purdie via lists.openembedded.org
> wrote:
>> I think this would be something really useful to fix. For ranlib, we can
>> probably just patch BUILD_RANLIB to add the flag. For ar, we need to remove 
>> the
>> u option so it can only really be done with an intercept.
>>
>> I did try this on the autobuilder with your ar intercept and the ranlib flag
>> tweak with:
>>
>> https://autobuilder.yoctoproject.org/typhoon/#/builders/15/builds/4671/steps/11/logs/stdio
>>
>> It broke as the above needs to be:
>>
>> exec ar D$args $*
>>
>> with no space else it breaks, at least on ubuntu1804. I'll try again with 
>> that
>> fixed.
>>
>> As mentioned on irc, I am a little worried about the fork overhead in the
>> wrapper too as fork overhead does seem to be a build pain point for us and 
>> the
>> hit on a more complex program like python may be worth it, not sure.
> 
> FWIW the above breaks meson which tries to run "ar D--version" after the above
> change. The intercept script is going to have to be a little more "clever" :/
> 

Here is a slightly more intelligent version, based on top of your patch
that adjusts BUILD_RANLIB. It should hopefully handle the meson breakage.

Jacob
From 8f6e7987f9a49ba78d0a7b34c63ba774e6eef681 Mon Sep 17 00:00:00 2001
From: Richard Purdie <[email protected]>
Date: Mon, 22 Nov 2021 16:08:16 +0000
Subject: [PATCH 1/2] bitbake.conf: Pass -D option to ranlib for determisim

Signed-off-by: Richard Purdie <[email protected]>
---
 meta/conf/bitbake.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 71c1e52ad6..fba99e8f0c 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -542,7 +542,7 @@ export BUILD_LD = "${BUILD_PREFIX}ld ${BUILD_LD_ARCH}"
 export BUILD_CCLD = "${BUILD_PREFIX}gcc ${BUILD_CC_ARCH}"
 export BUILD_AR = "${BUILD_PREFIX}ar"
 export BUILD_AS = "${BUILD_PREFIX}as ${BUILD_AS_ARCH}"
-export BUILD_RANLIB = "${BUILD_PREFIX}ranlib"
+export BUILD_RANLIB = "${BUILD_PREFIX}ranlib -D"
 export BUILD_STRIP = "${BUILD_PREFIX}strip"
 BUILD_OBJCOPY = "${BUILD_PREFIX}objcopy"
 BUILD_OBJDUMP = "${BUILD_PREFIX}objdump"
From 15b46669649a605821304bbd05664e4acb897916 Mon Sep 17 00:00:00 2001
From: Jacob Kroon <[email protected]>
Date: Sun, 21 Nov 2021 22:48:49 +0100
Subject: [PATCH 2/2] native/cross: Add ar wrapper for determinism

Signed-off-by: Jacob Kroon <[email protected]>
---
 meta/classes/cross.bbclass  |  2 ++
 scripts/cross-intercept/ar  |  1 +
 scripts/native-intercept/ar | 29 +++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
 create mode 120000 scripts/cross-intercept/ar
 create mode 100755 scripts/native-intercept/ar

diff --git a/meta/classes/cross.bbclass b/meta/classes/cross.bbclass
index 3e6a2f60b9..9d951076a7 100644
--- a/meta/classes/cross.bbclass
+++ b/meta/classes/cross.bbclass
@@ -93,3 +93,5 @@ python do_addto_recipe_sysroot () {
 }
 addtask addto_recipe_sysroot after do_populate_sysroot
 do_addto_recipe_sysroot[deptask] = "do_populate_sysroot"
+
+PATH:prepend = "${COREBASE}/scripts/cross-intercept:"
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..e3320cd39c
--- /dev/null
+++ b/scripts/native-intercept/ar
@@ -0,0 +1,29 @@
+#!/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][0] == '--':
+    # No modifier given
+    None
+else:
+    # remove the optional '-'
+    if argv[1][0] == '-':
+        argv[1] = argv[1][1:]
+    argv[1] = argv[1].replace('u', '')
+    argv[1] = 'D' + argv[1]
+
+os.execv(real_ar, argv)
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#1358): 
https://lists.openembedded.org/g/openembedded-architecture/message/1358
Mute This Topic: https://lists.openembedded.org/mt/87230716/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-architecture/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to