diff options
author | Douglas Royds <douglas.royds@taitradio.com> | 2018-09-14 14:58:15 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-09-21 18:45:46 -0700 |
commit | 73ba6051bebe901b7aac07cbffb2d368ca8408ea (patch) | |
tree | 34cc46114ca8082279fd2844707dce19311ec93b /meta/classes/reproducible_build.bbclass | |
parent | 526276a74d1bc4f75885a5573ab0b1086f8f2f35 (diff) | |
download | poky-73ba6051bebe901b7aac07cbffb2d368ca8408ea.tar.gz |
reproducible: Find the git repo in WORKDIR/git or S first
Change the search regime for find_git_folder():
1. WORKDIR/git: This is the default git fetcher unpack path
2. ${S}
3. Go looking for .git/ under the WORKDIR as a last resort.
linux-yocto:
We had an existing (silent) defect. The linux-yocto recipes all specify
two git SRC_URIs, one for the kernel source itself, the other for the
kmeta data (config fragments and friends). find_git_folder() was finding
the git checkout for the kmeta data, but due to a typo in the git log -1
--pretty=%ct line, we were (silently) reading the source_date_epoch from
the ${S} directory = STAGING_KERNEL_DIR, which is empty. If your
build/ happened to be inside a git checkout, git would walk up the
directory tree, and silently read the commit timestamp from this other
git checkout. The correct path to read the git commit timestamp from is
the "gitpath", being that found by find_git_folder(), though this
function was incorrectly finding the kmeta data checkout, not the kernel
source tree.
Non-kernel git recipes:
The default git fetcher clones and checks out the sources at
WORKDIR/git/ regardless of the setting of S (unless subpath or
destsuffix is set). find_git_folder() now looks for the
WORKDIR/git/.git/ directory first.
Non-yocto linux kernels:
Kernel recipes that don't inherit kernel-yocto should always set
S = ${WORKDIR}/git, so that when base_do_unpack_append() in
kernel.bbclass moves the checkout down to the STAGING_KERNEL_DIR and
symlinks it as WORKDIR/git, the build can still work by following the
symlink. We were previously failing to follow the symlink in the
os.walk(), but we now look first for WORKDIR/git/.git/, and find it due
to the symlink.
If none of the above mechanisms work for finding the git checkout,
perhaps there was a subpath or destsuffix specified in the SRC_URI.
We go looking for the git checkout under the WORKDIR as a last resort.
(From OE-Core rev: b0ddb141d36853447f85ecaac07dbc9c5779627f)
Signed-off-by: Douglas Royds <douglas.royds@taitradio.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/reproducible_build.bbclass')
-rw-r--r-- | meta/classes/reproducible_build.bbclass | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/meta/classes/reproducible_build.bbclass b/meta/classes/reproducible_build.bbclass index 3f3790dfe3..42cb37b042 100644 --- a/meta/classes/reproducible_build.bbclass +++ b/meta/classes/reproducible_build.bbclass | |||
@@ -61,28 +61,39 @@ def get_source_date_epoch_from_known_files(d, sourcedir): | |||
61 | source_date_epoch = mtime | 61 | source_date_epoch = mtime |
62 | return source_date_epoch | 62 | return source_date_epoch |
63 | 63 | ||
64 | def find_git_folder(workdir): | 64 | def find_git_folder(d, sourcedir): |
65 | exclude = set(["temp", "license-destdir", "patches", "recipe-sysroot-native", "recipe-sysroot", "pseudo", "build", "image", "sysroot-destdir"]) | 65 | # First guess: WORKDIR/git |
66 | # This is the default git fetcher unpack path | ||
67 | workdir = d.getVar('WORKDIR') | ||
68 | gitpath = os.path.join(workdir, "git/.git") | ||
69 | if os.path.isdir(gitpath): | ||
70 | return gitpath | ||
71 | |||
72 | # Second guess: ${S} | ||
73 | gitpath = os.path.join(sourcedir, ".git") | ||
74 | if os.path.isdir(gitpath): | ||
75 | return gitpath | ||
76 | |||
77 | # Perhaps there was a subpath or destsuffix specified. | ||
78 | # Go looking in the WORKDIR | ||
79 | exclude = set(["build", "image", "license-destdir", "patches", "pseudo", | ||
80 | "recipe-sysroot", "recipe-sysroot-native", "sysroot-destdir", "temp"]) | ||
66 | for root, dirs, files in os.walk(workdir, topdown=True): | 81 | for root, dirs, files in os.walk(workdir, topdown=True): |
67 | dirs[:] = [d for d in dirs if d not in exclude] | 82 | dirs[:] = [d for d in dirs if d not in exclude] |
68 | if '.git' in dirs: | 83 | if '.git' in dirs: |
69 | return root | 84 | return root |
70 | 85 | ||
86 | bb.warn("Failed to find a git repository in WORKDIR: %s" % workdir) | ||
87 | return None | ||
88 | |||
71 | def get_source_date_epoch_from_git(d, sourcedir): | 89 | def get_source_date_epoch_from_git(d, sourcedir): |
72 | source_date_epoch = None | 90 | source_date_epoch = None |
73 | if "git://" in d.getVar('SRC_URI'): | 91 | if "git://" in d.getVar('SRC_URI'): |
74 | workdir = d.getVar('WORKDIR') | 92 | gitpath = find_git_folder(d, sourcedir) |
75 | gitpath = find_git_folder(workdir) | ||
76 | if gitpath: | 93 | if gitpath: |
77 | import subprocess | 94 | import subprocess |
78 | if os.path.isdir(os.path.join(gitpath,".git")): | 95 | source_date_epoch = int(subprocess.check_output(['git','log','-1','--pretty=%ct'], cwd=gitpath)) |
79 | try: | 96 | bb.debug(1, "git repo path: %s sde: %d" % (gitpath, source_date_epoch)) |
80 | source_date_epoch = int(subprocess.check_output(['git','log','-1','--pretty=%ct'], cwd=sourcedir)) | ||
81 | bb.debug(1, "git repo path:%s sde: %d" % (gitpath,source_date_epoch)) | ||
82 | except subprocess.CalledProcessError as grepexc: | ||
83 | bb.debug(1, "Expected git repository not found, (path: %s) error:%d" % (gitpath, grepexc.returncode)) | ||
84 | else: | ||
85 | bb.warn("Failed to find a git repository for path:%s" % workdir) | ||
86 | return source_date_epoch | 97 | return source_date_epoch |
87 | 98 | ||
88 | def get_source_date_epoch_from_youngest_file(d, sourcedir): | 99 | def get_source_date_epoch_from_youngest_file(d, sourcedir): |