3.7 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
import json import os import sys import subprocess import errno
if len(sys.argv) != 5: print("Incorrect number of parameters, please call as %s ") sys.exit(1)
Strip off "nightly-"
target = sys.argv[1][8:] stepnum = sys.argv[2] builddir = sys.argv[3] branchname = sys.argv[4]
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] == "True": return True return False
Get a configuration variable, check overrides, first, the defaults
def getconfigvar(name, config, target): if target in config['overrides'] and name in config['overrides'][target]: return config['overrides'][target][name] if name in config['defaults']: return config['defaults'][name] return False
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)
distro = getconfigvar("DISTRO", ourconfig, target) if distro and distro != "None": variables.append('DISTRO = "%s"' % distro)
if contains(["BUILD_HISTORY_DIR", "build-history-targets", "BUILD_HISTORY_REPO"], ourconfig): # What we need to do here is check if poky, if so proceed, if not (e.g. poky-contrib) don't. # If its a main branch, checkout the previous revision and then move forward on it # If its -next check out the main branch, then move forward on it. if target in ourconfig["build-history-targets"]: bh_path = os.path.join(ourconfig["BUILD_HISTORY_DIR"], distro, branchname, "nightly-" + target) remoterepo = ourconfig["BUILD_HISTORY_REPO"] remotebranch = distro + "/" + branchname + "/nightly-" + target #if branchname.endswith("-next"): # We reset and base on the last code: # runcmd([os.path.join(scriptsdir, "buildhistory-reset"), bh_path, remoterepo, remotebranch]) runcmd([os.path.join(scriptsdir, "buildhistory-init"), bh_path, remoterepo, remotebranch]) variables.append('INHERIT += "buildhistory"') variables.append('BUILDHISTORY_DIR = "%s"' % bh_path) variables.append('BUILDHISTORY_PUSH_REPO = "%s %s:%s"' % (remoterepo, remotebranch, remotebranch))
if configtrue("QEMU_USE_KVM", ourconfig): variables.append('QEMU_USE_KVM = "True"')
print("Writing %s" % autoconf) with open(autoconf, "w") as f: for v in variables: print(v + "\n") f.write(v + "\n")
print(str(ourconfig))
print("setup-config called with %s" % " ".join(sys.argv))