summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Gortmaker <paul.gortmaker@windriver.com>2022-04-20 11:11:41 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-05-12 16:42:13 +0100
commit663939ef27a7906d25fcf40d713086cb4a3b5878 (patch)
tree20c8710333e676270c2a71b7fcb59d3ae5da617e
parent87bd34033a525ea7a37e37741a7d9c8e0d308cd6 (diff)
downloadpoky-663939ef27a7906d25fcf40d713086cb4a3b5878.tar.gz
install/devshell: Introduce git intercept script due to fakeroot issues
In a devshell, recent versions of git will complain if the repo is owned by someone other than the current UID - consider this example: ------ bitbake -c devshell linux-yocto [...] kernel-source#git branch fatal: unsafe repository ('/home/paul/poky/build-qemuarm64/tmp/work-shared/qemuarm64/kernel-source' is owned by someone else) To add an exception for this directory, call: git config --global --add safe.directory /home/paul/poky/build-qemuarm64/tmp/work-shared/qemuarm64/kernel-source kernel-source# ------ Of course the devshell has UID zero and the "real" UID is for "paul" in this case. And so recent git versions complain. As the whole purpose of the devshell is to invoke a shell where development can take place, having a non-functional git is clearly unacceptable. Richard suggested we could use PSEUDO_UNLOAD=1 to evade this issue, and I suggested we probably will see other similar instances like this and should make use of PATH to intercept via devshell wrappers - conveniently we already have examples of this. Here, we copy the existing "ar" example and tune it to the needs of git to combine Richard's suggestion and mine. As such we now also can store commit logs and use send-email with our user specific settings, instead of "root", so in additon to fixing basic commands like "git branch" it should also increase general usefulness. RP: Tweaked the patch so the PATH change only applies to the devshell task and is a generic git intercept rather than devshell specific. RP: Also apply the PATH change to do_install tasks since that also runs under fakeroot and several software projects inject "git describe" output into their binaries (systemd, iputils, llvm, ipt-gpu-tools at least) causing reproducibility issues from systems with different git versions. (From OE-Core rev: 262470f5c01c08826e0fcf3d08337d17952a257d) Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 3266c327dfa186791e0f1e2ad63c6f5d39714814) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/base.bbclass1
-rw-r--r--meta/classes/devshell.bbclass2
-rwxr-xr-xscripts/git-intercept/git19
3 files changed, 22 insertions, 0 deletions
diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index 070341d1aa..78cc8279dd 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -339,6 +339,7 @@ addtask install after do_compile
339do_install[dirs] = "${B}" 339do_install[dirs] = "${B}"
340# Remove and re-create ${D} so that is it guaranteed to be empty 340# Remove and re-create ${D} so that is it guaranteed to be empty
341do_install[cleandirs] = "${D}" 341do_install[cleandirs] = "${D}"
342PATH:prepend:task-install = "${COREBASE}/scripts/git-intercept:"
342 343
343base_do_install() { 344base_do_install() {
344 : 345 :
diff --git a/meta/classes/devshell.bbclass b/meta/classes/devshell.bbclass
index 76dd0b42ee..b6212ebd89 100644
--- a/meta/classes/devshell.bbclass
+++ b/meta/classes/devshell.bbclass
@@ -2,6 +2,8 @@ inherit terminal
2 2
3DEVSHELL = "${SHELL}" 3DEVSHELL = "${SHELL}"
4 4
5PATH:prepend:task-devshell = "${COREBASE}/scripts/git-intercept:"
6
5python do_devshell () { 7python do_devshell () {
6 if d.getVarFlag("do_devshell", "manualfakeroot"): 8 if d.getVarFlag("do_devshell", "manualfakeroot"):
7 d.prependVar("DEVSHELL", "pseudo ") 9 d.prependVar("DEVSHELL", "pseudo ")
diff --git a/scripts/git-intercept/git b/scripts/git-intercept/git
new file mode 100755
index 0000000000..8adf5c9ecb
--- /dev/null
+++ b/scripts/git-intercept/git
@@ -0,0 +1,19 @@
1#!/usr/bin/env python3
2#
3# Wrapper around 'git' that doesn't think we are root
4
5import os
6import shutil
7import sys
8
9os.environ['PSEUDO_UNLOAD'] = '1'
10
11# calculate path to the real 'git'
12path = os.environ['PATH']
13path = path.replace(os.path.dirname(sys.argv[0]), '')
14real_git = shutil.which('git', path=path)
15
16if len(sys.argv) == 1:
17 os.execl(real_git, 'git')
18
19os.execv(real_git, sys.argv)