5.9 KiB
Executable File
#!/usr/bin/env python3
Generate an auto.conf and associated other config files for a given autobuilder configuration
Called with $1 - The 'nightly' target the autobuilder is running
$2 - The autobuilder step number (a given target can run multiple steps with different configurations)
$3 - The target build directory to configure
$4 - The poky branch name the build is running on
$5 - The name of the repository the build is running on
$6 - The directory to publish sstate into
import json import os import sys import subprocess import errno
if len(sys.argv) != 7: print("Incorrect number of parameters, please call as %s ") sys.exit(1)
target = sys.argv[1] stepnum = int(sys.argv[2]) + 1 # Our step numbering is 1 2 3 etc., not 0 of buildbot builddir = sys.argv[3] branchname = sys.argv[4] reponame = sys.argv[5] sstate_release = sys.argv[6]
scriptsdir = os.path.dirname(os.path.realpath(file))
with open(os.path.join(scriptsdir, '..', 'config.json')) as f: ourconfig = json.load(f)
Check if config contains all the listed params
def contains(params, config): for p in params: if p not in config: return False return True
Check if a config boolean is set
def configtrue(name, config): if name in config and config[name]: return True return False
Get a configuration variable, check overrides, first, the defaults
def getconfigvar(name, config, target, stepnum): step = "step" + str(stepnum) if target in config['overrides']: if step in config['overrides'][target] and name in config['overrides'][target][step]: return config['overrides'][target][step][name] if name in config['overrides'][target]: return config['overrides'][target][name] if name in config['defaults']: return config['defaults'][name] return False
def getconfiglist(name, config, target, stepnum): ret = [] step = "step" + str(stepnum) if target in config['overrides']: if step in config['overrides'][target] and name in config['overrides'][target][step]: ret.extend(config['overrides'][target][step][name]) if name in config['overrides'][target]: ret.extend(config['overrides'][target][name]) if name in config['defaults']: ret.extend(config['defaults'][name]) return ret
Run a command, trigger a traceback with command output if it fails
def runcmd(cmd): return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
variables = []
autoconf = os.path.join(builddir, "conf", "auto.conf") if os.path.exists(autoconf): os.remove(autoconf)
Ensure autoconf's directory exists
try: os.makedirs(os.path.dirname(autoconf)) except OSError as e: if e.errno != errno.EEXIST: # Do not complain if the directory exists raise e
sdkextraconf = os.path.join(builddir, "conf", "sdk-extra.conf") if os.path.exists(sdkextraconf): os.remove(sdkextraconf)
for v in ["MACHINE", "DISTRO", "SDKMACHINE"]: value = getconfigvar(v, ourconfig, target, stepnum) if value and value != "None": variables.append(v + ' = "%s"' % value)
distro = getconfigvar("DISTRO", ourconfig, target, stepnum)
for v in ["DLDIR", "PRSERV"]: value = getconfigvar(v, ourconfig, target, stepnum) if value: variables.append(value)
Use a separate SSTATE_DIR with the primary
SSTATE_DIR configured as a mirror so that we
have a directory of symlinks to sstate objects
that can be published for the release
key = "SSTATEDIR" if sstate_release != "None": key = "SSTATEDIR_RELEASE" value = getconfigvar(key, ourconfig, target, stepnum) for v in value: v = v.replace("@RELEASENUM@", sstate_release) variables.append(v)
if getconfigvar("BUILDINFO", ourconfig, target, stepnum): infovars = getconfiglist("BUILDINFOVARS", ourconfig, target, stepnum) variables.extend(infovars)
extravars = getconfiglist("extravars", ourconfig, target, stepnum) if extravars: variables.extend(extravars)
if contains(["BUILD_HISTORY_DIR", "build-history-targets", "BUILD_HISTORY_REPO"], ourconfig): if target in ourconfig["build-history-targets"]: base = None if (reponame + ":" + branchname) in ourconfig["BUILD_HISTORY_DIRECTPUSH"]: base = reponame + ":" + branchname if (reponame + ":" + branchname) in ourconfig["BUILD_HISTORY_FORKPUSH"]: base = ourconfig["BUILD_HISTORY_FORKPUSH"][reponame + ":" + branchname] if base: baserepo, basebranch = base.split(":") bh_path = os.path.join(ourconfig["BUILD_HISTORY_DIR"], distro, branchname, target) remoterepo = ourconfig["BUILD_HISTORY_REPO"] remotebranch = repo + "/" + branchname + "/" + target baseremotebranch = baserepo + "/" + basebranch + "/" + target runcmd([os.path.join(scriptsdir, "buildhistory-init"), bh_path, remoterepo, remotebranch, baseremotebranch]) variables.append('INHERIT += "buildhistory"') variables.append('BUILDHISTORY_DIR = "%s"' % bh_path) variables.append('BUILDHISTORY_PUSH_REPO = "%s %s:%s"' % (remoterepo, remotebranch, remotebranch)) variables.append("BUILDHISTORY_COMMIT = '1'") variables.append('ERROR_QA_remove = "version-going-backwards"')
print("Writing %s with contents:" % autoconf) with open(autoconf, "w") as f: for v in variables: print(" " + v) f.write(v + "\n")
print("Writing %s with contents:" % sdkextraconf) with open(sdkextraconf, "w") as f: for v in getconfiglist("SDKEXTRAS", ourconfig, target, stepnum): replace = "" if sstate_release != "None": replace = sstate_release + "/" v = v.replace("@RELEASENUM@", replace) print(" " + v) f.write(v + "\n")