From patchwork Sun Oct 1 16:00:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Sakoman X-Patchwork-Id: 31484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89607E748EE for ; Sun, 1 Oct 2023 16:00:45 +0000 (UTC) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web10.62430.1696176044356047252 for ; Sun, 01 Oct 2023 09:00:44 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@sakoman-com.20230601.gappssmtp.com header.s=20230601 header.b=QG7/YBgQ; spf=softfail (domain: sakoman.com, ip: 209.85.214.181, mailfrom: steve@sakoman.com) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1c5c91bece9so126622265ad.3 for ; Sun, 01 Oct 2023 09:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakoman-com.20230601.gappssmtp.com; s=20230601; t=1696176043; x=1696780843; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cnf6/Vd7f+0bSvFdaxArNk3ofYJUViUF3BX5EJHL6Kc=; b=QG7/YBgQL1cVvzxnvNYuKwpVYxEXt8yWhccEYD2wDfEeYZAwdmwbBPHnbpH8Ztpkpj TlaKuL3YNb4rGtEnbhwfsfWDjLXz/za68wP0oxHdESRKHJOP49D+mIgZznD+LFrAkOwK xo+P9P+/Y20SsdA+WUaufQF1wA5OkmGd75As2iHXEkXTKQIf8fVfKOFSB+YxvSqWwVfW nETTQ0Y0prfC18h4ucDIB8Wfwue7fB0gRuqjowPWw0RkmiaUQztdiX6zeD1ZoUo5WIc4 CGVyEkfKNmZTBipKo7CmzP8tXDQ4wLvvBLPXHZCvqq3uTNsV/gDW2Czsrjnsm0K9A2fo xN8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696176043; x=1696780843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cnf6/Vd7f+0bSvFdaxArNk3ofYJUViUF3BX5EJHL6Kc=; b=VOsvpD6JTsAKTkxl1w2s66oaIlHun8ikPHy4gMtvxgNi5A7gfRCJKsWdR22B912z1L tMpHQ7L9FziOR9PG1KS18Ad/X1JNe4KZSSNWUbuO+6DHkWt1uT7/OqHEeBmn5lRiTUxw s0nkAv8PHY4kuzqBViCKGUQKjX5YoXy1LA8pkQ1ptkLrDsgXi7VjrjOR3ZymEw5zJAwj KrlvHcE0EfF8a9/VVtkQqo5aBhpnc7XCPbv0FhQLpJ91qbLnv+Z3S35cV/zXTm87bhRj r50Hmiadw+fl9pn6sjwxqHbdtGwIBK7W7R1Vh7F5anbfSRGlQ8kknCUKNynemm5Ra+Lb Y6WA== X-Gm-Message-State: AOJu0YxrSMhbe4D8/hnCPF+OIH3A2AD7gcDPYHuHgLLmPe1/8SCeI/89 ZMK9CtZZwgniL4e9kleNQQZVuQJ4oFDhkhtVdwSW9A== X-Google-Smtp-Source: AGHT+IFwpBKIu6n1JNRpOgad7j/R5hNCVCxzz+AUtbv+GUa83LIqI3hUvkJeFHN7CNTFk7+ewkAVdQ== X-Received: by 2002:a17:903:48c:b0:1c3:bc7b:8805 with SMTP id jj12-20020a170903048c00b001c3bc7b8805mr6746057plb.52.1696176043416; Sun, 01 Oct 2023 09:00:43 -0700 (PDT) Received: from hexa.lan (dhcp-72-234-106-30.hawaiiantel.net. [72.234.106.30]) by smtp.gmail.com with ESMTPSA id jk4-20020a170903330400b001c5900c9e8fsm15416967plb.81.2023.10.01.09.00.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:00:43 -0700 (PDT) From: Steve Sakoman To: openembedded-core@lists.openembedded.org Subject: [OE-core][mickledore 14/23] patch.py: use --absolute-git-dir instead of --show-toplevel to retrieve gitdir Date: Sun, 1 Oct 2023 06:00:01 -1000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Sun, 01 Oct 2023 16:00:45 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/188503 From: Julien Stephan [YOCTO #14141] Currently the gitdir is manually constructed using `git rev-parse --show-toplevel` and appending `.git`. This is most of the time correct but not always: `.git` can be a file with the following content: gitdir: This is the case for submodules, so when using devtool modify on a recipe using submodules *and* patching files inside one of the submodules, do_patch fails with the following error: ERROR: Error executing a python function in exec_func_python() autogenerated: The stack trace of python calls that resulted in this exception/failure was: File: 'exec_func_python() autogenerated', lineno: 2, function: 0001: *** 0002:patch_do_patch(d) 0003: File: '<..>/poky/meta/classes-global/patch.bbclass', lineno: 157, function: patch_do_patch 0153: except Exception as exc: 0154: bb.utils.remove(process_tmpdir, True) 0155: bb.fatal("Importing patch '%s' with striplevel '%s'\n%s" % (parm['patchname'], parm['striplevel'], repr(exc).replace("\\n", "\n"))) 0156: try: *** 0157: resolver.Resolve() 0158: except bb.BBHandledException as e: 0159: bb.utils.remove(process_tmpdir, True) 0160: bb.fatal("Applying patch '%s' on target directory '%s'\n%s" % (parm['patchname'], patchdir, repr(e).replace("\\n", "\n"))) 0161: File: '<..>/poky/meta/lib/oe/patch.py', lineno: 769, function: Resolve 0765: def Resolve(self): 0766: olddir = os.path.abspath(os.curdir) 0767: os.chdir(self.patchset.dir) 0768: try: *** 0769: self.patchset.Push() 0770: except Exception: 0771: import sys 0772: os.chdir(olddir) 0773: raise File: '<..>/poky/meta/lib/oe/patch.py', lineno: 274, function: Push 0270: else: 0271: next = 0 0272: 0273: bb.note("applying patch %s" % self.patches[next]) *** 0274: ret = self._applypatch(self.patches[next], force) 0275: 0276: self._current = next 0277: return ret 0278: File: '<..>/poky/meta/lib/oe/patch.py', lineno: 556, function: _applypatch 0552: if os.path.lexists(hooks_dir_backup): 0553: raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup) 0554: if os.path.lexists(hooks_dir): 0555: shutil.move(hooks_dir, hooks_dir_backup) *** 0556: os.mkdir(hooks_dir) 0557: commithook = os.path.join(hooks_dir, 'commit-msg') 0558: applyhook = os.path.join(hooks_dir, 'applypatch-msg') 0559: with open(commithook, 'w') as f: 0560: # NOTE: the formatting here is significant; if you change it you'll also need to Exception: NotADirectoryError: [Errno 20] Not a directory: '<..>/build/tmp/work/core2-64-poky-linux/vulkan-samples/git/devtooltmp-n87_zx1i/workdir/git/third_party/spdlog/.git/hooks' Using `git rev-parse --absolute-git-dir` instead of `git rev-parse --show-toplevel` ensure we get the correct gitdir Signed-off-by: Julien Stephan Signed-off-by: Luca Ceresoli Signed-off-by: Richard Purdie (cherry picked from commit f74879dd95b19504ce8a8554636d2310d0336806) Signed-off-by: Steve Sakoman --- meta/lib/oe/patch.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index d047b3b947..e5108e9ad6 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -547,7 +547,10 @@ class GitApplyTree(PatchTree): reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip() if not reporoot: raise Exception("Cannot get repository root for directory %s" % self.dir) - hooks_dir = os.path.join(reporoot, '.git', 'hooks') + gitdir = (runcmd("git rev-parse --absolute-git-dir".split(), self.dir) or '').strip() + if not gitdir: + raise Exception("Cannot get gitdir for directory %s" % self.dir) + hooks_dir = os.path.join(gitdir, 'hooks') hooks_dir_backup = hooks_dir + '.devtool-orig' if os.path.lexists(hooks_dir_backup): raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup)