On 11/22/21 22:25, Jacob Kroon via lists.openembedded.org wrote:
> 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.
> 

That version had a bug, needed:

-if argv[1][0] == '--':
+if argv[1].startswith('--'):

I've attached an updated version of the patch.

Jacob
From f3dedf71986ce087ff4a0883a7ee081e9f271800 Mon Sep 17 00:00:00 2001
From: Jacob Kroon <[email protected]>
Date: Sun, 21 Nov 2021 22:48:49 +0100
Subject: [PATCH] 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..642b6eae86
--- /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].startswith('--'):
+    # 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 (#1359): 
https://lists.openembedded.org/g/openembedded-architecture/message/1359
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