[PATCH][autobuilder-helper][warrior 27/41] scripts/run-config: Share buildtools setup code with shared-repo-unpack


Richard Purdie
 

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
scripts/run-config | 49 +------------------------------------
scripts/shared-repo-unpack | 2 ++
scripts/utils.py | 50 ++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 48 deletions(-)

diff --git a/scripts/run-config b/scripts/run-config
index 54d74dc..814f0cc 100755
--- a/scripts/run-config
+++ b/scripts/run-config
@@ -8,9 +8,6 @@ import os
import sys
import subprocess
import errno
-import fnmatch
-import glob
-import fcntl

import utils

@@ -83,51 +80,7 @@ if args.target in ourconfig['overrides']:

hp.printheader("Target task %s has %d steps" % (args.target, maxsteps))

-bttarball = None
-if "buildtools" in ourconfig and args.workername:
- btcfg = utils.getconfig("buildtools", ourconfig)
- for entry in btcfg:
- if fnmatch.fnmatch(args.workername, entry):
- bttarball = btcfg[entry]
- break
-
-btenv = None
-if bttarball:
- btdir = args.builddir + "/../buildtools"
- if not os.path.exists(btdir):
- btdlpath = utils.getconfig("BASE_SHAREDDIR", ourconfig) + "/buildtools/" + os.path.basename(bttarball)
- print("Extracting buildtools %s" % bttarball)
- btlock = btdlpath + ".lock"
- if not os.path.exists(os.path.dirname(btdlpath)):
- os.makedirs(os.path.dirname(btdlpath), exist_ok=True)
- while True:
- try:
- with open(btlock, 'a+') as lf:
- fileno = lf.fileno()
- fcntl.flock(fileno, fcntl.LOCK_EX)
- if not os.path.exists(btdlpath):
- if bttarball.startswith("/"):
- subprocess.check_call(["cp", bttarball, btdlpath])
- else:
- subprocess.check_call(["wget", "-O", btdlpath, bttarball])
- os.chmod(btdlpath, 0o775)
- break
- except OSError:
- # We raced with someone else, try again
- pass
- subprocess.check_call(["bash", btdlpath, "-d", btdir, "-y"])
- btenv = glob.glob(btdir + "/environment-setup*")
- print("Using buildtools %s" % btenv)
- # We either parse or wrap all our execution calls, rock and a hard place :(
- with open(btenv[0], "r") as f:
- for line in f.readlines():
- if line.startswith("export "):
- line = line.strip().split(" ", 1)[1].split("=", 1)
- if "$PATH" in line[1]:
- line[1] = line[1].replace("$PATH", os.environ["PATH"])
- if line[1].startswith(("'", '"')):
- line[1] = line[1][1:-1]
- os.environ[line[0]] = line[1]
+utils.setup_buildtools_tarball(ourconfig, args.workername, args.builddir + "/../buildtools")

finalret = 0

diff --git a/scripts/shared-repo-unpack b/scripts/shared-repo-unpack
index 4a2b1c9..7dc250c 100755
--- a/scripts/shared-repo-unpack
+++ b/scripts/shared-repo-unpack
@@ -61,6 +61,8 @@ for repo in sorted(repos.keys()):
if args.publish_dir:
utils.publishrepo(targetsubdir, repo, args.publish_dir)

+utils.setup_buildtools_tarball(ourconfig, args.workername, args.abworkdir + "/buildtools")
+
try:
subprocess.check_call([scriptsdir + "/layer-config", args.abworkdir, args.target])
except subprocess.CalledProcessError as e:
diff --git a/scripts/utils.py b/scripts/utils.py
index 5542fe2..d7b9ae7 100644
--- a/scripts/utils.py
+++ b/scripts/utils.py
@@ -8,6 +8,9 @@ import codecs
import sys
import re
import argparse
+import fnmatch
+import glob
+import fcntl

#
# Check if config contains all the listed params
@@ -364,3 +367,50 @@ def getcomparisonbranch(ourconfig, reponame, branchname):
if (reponame + ":" + branchname) in getconfig("BUILD_HISTORY_DIRECTPUSH", ourconfig):
return branchname, None
return None, None
+
+def setup_buildtools_tarball(ourconfig, workername, btdir):
+ bttarball = None
+ if "buildtools" in ourconfig and workername:
+ btcfg = getconfig("buildtools", ourconfig)
+ for entry in btcfg:
+ if fnmatch.fnmatch(workername, entry):
+ bttarball = btcfg[entry]
+ break
+
+ btenv = None
+ if bttarball:
+ btdir = os.path.abspath(btdir)
+ if not os.path.exists(btdir):
+ btdlpath = getconfig("BASE_SHAREDDIR", ourconfig) + "/buildtools/" + os.path.basename(bttarball)
+ print("Extracting buildtools %s" % bttarball)
+ btlock = btdlpath + ".lock"
+ if not os.path.exists(os.path.dirname(btdlpath)):
+ os.makedirs(os.path.dirname(btdlpath), exist_ok=True)
+ while True:
+ try:
+ with open(btlock, 'a+') as lf:
+ fileno = lf.fileno()
+ fcntl.flock(fileno, fcntl.LOCK_EX)
+ if not os.path.exists(btdlpath):
+ if bttarball.startswith("/"):
+ subprocess.check_call(["cp", bttarball, btdlpath])
+ else:
+ subprocess.check_call(["wget", "-O", btdlpath, bttarball])
+ os.chmod(btdlpath, 0o775)
+ break
+ except OSError:
+ # We raced with someone else, try again
+ pass
+ subprocess.check_call(["bash", btdlpath, "-d", btdir, "-y"])
+ btenv = glob.glob(btdir + "/environment-setup*")
+ print("Using buildtools %s" % btenv)
+ # We either parse or wrap all our execution calls, rock and a hard place :(
+ with open(btenv[0], "r") as f:
+ for line in f.readlines():
+ if line.startswith("export "):
+ line = line.strip().split(" ", 1)[1].split("=", 1)
+ if "$PATH" in line[1]:
+ line[1] = line[1].replace("$PATH", os.environ["PATH"])
+ if line[1].startswith(("'", '"')):
+ line[1] = line[1][1:-1]
+ os.environ[line[0]] = line[1]
--
2.25.1

Join yocto@lists.yoctoproject.org to automatically receive all group messages.