public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: "akuster" <akuster808@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [V2][PATCH] buildhistory.bbclass: add cloning
Date: Sun, 14 Feb 2021 19:18:47 +0000	[thread overview]
Message-ID: <20210214191847.2043214-1-akuster808@gmail.com> (raw)

Provide a method to clone and push to a git repo
Provide a method to pre-populate buildhistory
Maybe remove the need for external scripts to do the same

Three new variables:
BUILDHISTORY_BRANCH - branch used for checkout and pushing
BUILDHISTORY_CLONE - git repo uri

example:
BUILDHISTORY_BRANCH="${DISTRO}/gatesgarth/${MACHINE}"
BUILDHISTORY_CLONE = "git@gitlab.com:akuster/oe-buildhistory"
BUILDHISTORY_PUSH_REPO = "origin ${BUILDHISTORY_BRANCH}"

Signed-off-by: Armin Kuster <akuster808@gmail.com>

----
[V2]
Use BUILDHISTORY_CLONE instead of BUILDHISTORY_REPO_URI

Simplified initial clone to one step
---
 meta/classes/buildhistory.bbclass | 47 +++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass
index 117a44eaf38..d0e918c3d8e 100644
--- a/meta/classes/buildhistory.bbclass
+++ b/meta/classes/buildhistory.bbclass
@@ -44,6 +44,12 @@ BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>"
 BUILDHISTORY_PUSH_REPO ?= ""
 BUILDHISTORY_TAG ?= "build"
 
+# Branch for checkout
+BUILDHISTORY_BRANCH ?= ""
+
+# Clone previous buildhistory from repo
+BUILDHISTORY_CLONE ?= ""
+
 SSTATEPOSTINSTFUNCS_append = " buildhistory_emit_pkghistory"
 # We want to avoid influencing the signatures of sstate tasks - first the function itself:
 sstate_install[vardepsexclude] += "buildhistory_emit_pkghistory"
@@ -858,6 +864,42 @@ END
 		fi) || true
 }
 
+python buildhistory_clone() {
+    import subprocess
+
+    histdir = d.getVar('BUILDHISTORY_DIR')
+    repo_uri = d.getVar("BUILDHISTORY_CLONE")
+    bh_branch = d.getVar("BUILDHISTORY_BRANCH")
+
+    if not bh_branch:
+        bb.note("BUILDHISTORY_BRANCH not set")
+        return
+
+    if not os.path.isdir(histdir):
+        cmd = ['git', 'clone', repo_uri, '-b', bh_branch, histdir]
+        ret = subprocess.call(cmd)
+        if ret != 0:
+            bb.error('Failed to clond %s!' % repo_uri)
+
+    if not os.path.isdir(histdir):
+       rerturn
+
+    if os.path.isdir(os.path.join(histdir, '.git')):
+        cmd =['git', '-C', histdir, 'config', '--get', 'remote.origin.url']
+        hasurl = subprocess.call(cmd, shell=True)
+        if hasurl:
+            cmd = ['git', '-C', histdir, 'remote', 'add', '-f', '-t', bh_branch, '-m', bh_branch, 'origin', repo_uri]
+            subprocess.call(cmd)
+
+            cmd = ['git', '-C', histdir, 'checkout', bh_branch]
+            ret = subprocess.call(cmd)
+            if ret != 0:
+                bb.error('Failed to checkout branch %s' % bh_branch)
+
+            cmd = ['git', '-C', histdir, 'branch', '--set-upstream-to=origin/%s' % bh_branch]
+            subprocess.call(cmd)
+}
+
 python buildhistory_eventhandler() {
     if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip():
         reset = e.data.getVar("BUILDHISTORY_RESET")
@@ -874,6 +916,11 @@ python buildhistory_eventhandler() {
                 for entry in entries:
                     os.rename(os.path.join(rootdir, entry),
                               os.path.join(olddir, entry))
+
+            if e.data.getVar("BUILDHISTORY_CLONE") != "":
+                localdata = bb.data.createCopy(e.data)
+                bb.build.exec_func("buildhistory_clone", d)
+
         elif isinstance(e, bb.event.BuildCompleted):
             if reset:
                 import shutil
-- 
2.25.1


             reply	other threads:[~2021-02-14 19:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 19:18 akuster [this message]
2021-02-15 14:39 ` [OE-core] [V2][PATCH] buildhistory.bbclass: add cloning Richard Purdie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210214191847.2043214-1-akuster808@gmail.com \
    --to=akuster808@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox