def __init__(self, rootfs, product="rootfs"): self._rootfs = rootfs self._product = product if rootfs == "THIS": self._label = run.run([ "solvent", "printlabel", "--thisProject", "--product=%s" % (self._product, ) ]).strip() wrapper = gitwrapper.GitWrapper(".") self._hint = wrapper.originURLBasename() elif self._labelExists(self._rootfs): self._label = self._rootfs self._hint = self._rootfs elif "__" in self._rootfs: repository, product = self._rootfs.split("__") self._label = run.run([ "solvent", "printlabel", "--repositoryBasename", repository, "--product", product ]).strip() self._hint = repository else: self._label = run.run([ "solvent", "printlabel", "--repositoryBasename", rootfs, "--product=%s" % (self._product, ) ]).strip() self._hint = rootfs
def _configureLogbeam(self): conf = subprocess.check_output(["logbeam", "createConfig"]) logging.info("logbeam config: %(config)s", dict(config=conf)) with open(os.path.join(config.BUILD_CHROOT, "tmp", "logbeam.config"), "w") as f: f.write(conf) run.run([ "sudo", "mv", os.path.join(config.BUILD_CHROOT, "tmp", "logbeam.config"), os.path.join(config.BUILD_CHROOT, "etc", "logbeam.config")])
def _configureSolvent(self): with open("/etc/solvent.conf") as f: contents = f.read() modified = re.sub("LOCAL_OSMOSIS:.*", "LOCAL_OSMOSIS: 127.0.0.1:1010", contents) # todo: change 127.0.0.1 -> localhost with open(os.path.join(config.BUILD_CHROOT, "tmp", "solvent.conf"), "w") as f: f.write(modified) run.run([ "sudo", "mv", os.path.join(config.BUILD_CHROOT, "tmp", "solvent.conf"), os.path.join(config.BUILD_CHROOT, "etc", "solvent.conf")])
def __init__(self, rootfs): self._rootfs = rootfs if rootfs == "THIS": self._label = run.run( ["solvent", "printlabel", "--thisProject", "--product=rootfs"]).strip() wrapper = gitwrapper.GitWrapper(".") self._hint = wrapper.originURLBasename() elif self._labelExists(self._rootfs): self._label = self._rootfs self._hint = self._rootfs else: self._label = run.run([ "solvent", "printlabel", "--repositoryBasename", rootfs, "--product=rootfs" ]).strip() self._hint = rootfs
def _runAndBeamLog(self, logName, command, cwd=None): try: output = run.run(command=command, cwd=cwd) except subprocess.CalledProcessError as e: self._beamLog(logName, e.output, e.returncode) raise else: self._beamLog(logName, output, returnCode=0)
def __init__(self, rootfs): self._rootfs = rootfs if rootfs == "THIS": self._label = run.run([ "solvent", "printlabel", "--thisProject", "--product=rootfs"]).strip() wrapper = gitwrapper.GitWrapper(".") self._hint = wrapper.originURLBasename() elif self._labelExists(self._rootfs): self._label = self._rootfs self._hint = self._rootfs elif "__" in self._rootfs: repository, product = self._rootfs.split("__") self._label = run.run([ "solvent", "printlabel", "--repositoryBasename", repository, "--product", product]).strip() self._hint = repository else: self._label = run.run([ "solvent", "printlabel", "--repositoryBasename", rootfs, "--product=rootfs"]).strip() self._hint = rootfs
def __init__(self, officialObjectStore): self._officialObjectStore = officialObjectStore labelRegex = solvent.label.label(basename="(.*)", product="build", hash="(.*)", state="official$") regex = re.compile(labelRegex) labels = run.run([ 'osmosis', 'listlabels', labelRegex, '--objectStores', self._officialObjectStore]).strip().split("\n") if labels == [""]: labels = [] self._labels = set() for label in labels: basename, hash = regex.match(label).groups() self._labels.add((basename, hash))
def _checkOutBuildRootFS(self, buildRootFSLabel): logging.info("checking out build chroot at label '%(label)s'", dict(label=buildRootFSLabel)) run.run([ "sudo", "solvent", "bringlabel", "--label", buildRootFSLabel, "--destination", config.BUILD_CHROOT]) run.run([ "sudo", "cp", "-a", "/etc/hosts", "/etc/resolv.conf", os.path.join(config.BUILD_CHROOT, "etc")]) run.run([ "sudo", "sed", 's/.*requiretty.*//', "-i", os.path.join(config.BUILD_CHROOT, "etc", "sudoers")]) self._configureSolvent() self._configureLogbeam()
def replicate(self, destination): with self._lock.lock(timeout=self._LOCK_TIMEOUT): run.run(["sudo", "cp", "-a", self._cloneDirectory, destination + "/"])
def defaultTargetDependsOnTarget(directory, makefileFilename, target): output = run.run(["make", "-f", makefileFilename, "--just-print", "-d"], directory) return re.search(r"Considering .*\`%s\'" % target, output) is not None
def targetDoesNotDependOnAnything(directory, makefileFilename, target): with makefileForATargetThatMayNotExists(directory, makefileFilename, target) as tempMakefile: output = run.run(["make", "-f", tempMakefile, target, "--just-print", "-d"], directory) relevantLines = _linesUnderTargetConsideration(output, target) return 'Considering' not in "\n".join(relevantLines)
def _run(self, command): return run.run(command=command, cwd=self._directory)
def clone(cls, originURL, baseDirectory): basename = originURLBasename(originURL) run.run(["git", "clone", originURL, basename], cwd=baseDirectory) clone = cls(os.path.join(baseDirectory, basename)) clone.checkout('master') return clone
def _beamLog(self, logName, output, returnCode): logFilename = os.path.join(config.BUILD_CHROOT, "tmp", logName + ".log.txt") with open(logFilename, "w") as f: f.write(output) f.write("\nRETURN_CODE %d" % returnCode) run.run(["logbeam", "upload", logFilename])
def _beamLogsDir(self, under, path): run.run(["logbeam", "upload", path, "--under", under])
def savePng(self, filename): assert filename.endswith(".png") dot = tempfile.NamedTemporaryFile(suffix=".dot") dot.write(self._dotContents()) dot.flush() run.run(["dot", dot.name, "-Tpng", "-o", filename])
def _mountBinds(self): for mountBind in self._MOUNT_BIND: run.run([ "sudo", "mount", "-o", "bind", "/" + mountBind, os.path.join(config.BUILD_CHROOT, mountBind)])
def run(self, command, hash): with self._lock.lock(timeout=self._LOCK_TIMEOUT): self._git.checkout(hash) return run.run(command, cwd=self._git.directory())
def _getLabels(self): return run.run(['osmosis', 'listlabels', '--objectStores', self._objectStore]).strip().split("\n")
def _checkOutDependencies(self): run.run(["sudo", "solvent", "fulfillrequirements"], cwd=self._git.directory())