def _buildPackage(self): chroot = None try: chroot = Chroot(self.logger) chroot.create(self.package + "-" + self.version) tUtils = ToolChainUtils(self.logName, self.logPath) tUtils.installToolChainRPMS(chroot, self.package, self.version, self.logPath) listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(chroot)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.debug( "Installing the build time dependent packages......") for pkg in listDependentPackages: packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) self._installPackage(pkgUtils, packageName, packageVersion, chroot, self.logPath, listInstalledPackages, listInstalledRPMs) for pkg in listTestPackages: flag = False packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) for depPkg in listDependentPackages: depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion( depPkg) if depPackageName == packageName: flag = True break if flag == False: self._installPackage(pkgUtils, packageName, packageVersion, chroot, self.logPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInOneShot(chroot) self.logger.debug( "Finished installing the build time dependent packages...." ) pkgUtils.adjustGCCSpecs(chroot, self.package, self.version) pkgUtils.buildRPMSForGivenPackage(chroot, self.package, self.version, self.logPath) self.logger.debug("Successfully built the package:" + self.package) except Exception as e: self.logger.error("Failed while building package:" + self.package) self.logger.debug("Chroot: " + chroot.getPath() + " not deleted for debugging.") logFileName = os.path.join(self.logPath, self.package + ".log") fileLog = os.popen('tail -n 100 ' + logFileName).read() self.logger.info(fileLog) raise e if chroot: chroot.destroy()
def buildToolChain(self): try: tUtils=ToolChainUtils() tUtils.buildCoreToolChainPackages(self.listBuildOptionPackages, self.pkgBuildOptionFile) except Exception as e: self.logger.error("Unable to build tool chain") self.logger.error(e) raise e
def buildToolChain(self): try: tUtils = ToolChainUtils() tUtils.buildCoreToolChainPackages() except Exception as e: self.logger.error("Unable to build tool chain") self.logger.error(e) raise e
def buildToolChain(self): pkgCount = 0 try: tUtils = ToolChainUtils() pkgCount = tUtils.buildCoreToolChainPackages() except Exception as e: self.logger.error("Unable to build tool chain") self.logger.error(e) raise e return pkgCount
def buildToolChain(self): try: tUtils=ToolChainUtils() tUtils.buildCoreToolChainPackages() except Exception as e: self.logger.error("Unable to build tool chain") self.logger.error(e) return False return True
def buildToolChain(self): pkgCount = 0 try: tUtils = ToolChainUtils() pkgCount = tUtils.buildCoreToolChainPackages( self.listBuildOptionPackages, self.pkgBuildOptionFile) except Exception as e: self.logger.error("Unable to build tool chain") self.logger.error(e) raise e return pkgCount
def createBuildContainer(self): self.logger.info("Generating photon build container..") try: #TODO image name constants.buildContainerImageName self.dockerClient.images.remove("photon_build_container:latest", force=True) except Exception as e: #TODO - better handling self.logger.debug("Photon build container image not found.") # Create toolchain chroot and install toolchain RPMs chrootID = None try: #TODO: constants.tcrootname chrUtils = ChrootUtils("toolchain-chroot", self.logPath) returnVal, chrootID = chrUtils.createChroot("toolchain-chroot") self.logger.debug("Created tool-chain chroot: " + chrootID) if not returnVal: raise Exception("Unable to prepare tool-chain chroot") tcUtils = ToolChainUtils("toolchain-chroot", self.logPath) tcUtils.installToolChainRPMS(chrootID, "dummy") except Exception as e: if chrootID is not None: self.logger.debug("Deleting chroot: " + chrootID) chrUtils.destroyChroot(chrootID) raise e self.logger.info("VDBG-PU-createBuildContainer: chrootID: " + chrootID) # Create photon build container using toolchain chroot #TODO: Coalesce logging cmdUtils = CommandUtils() cmd = "./umount-build-root.sh " + chrootID cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot1.log") cmd = "cd " + chrootID + " && tar -czvf ../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot2.log") cmd = "mv " + chrootID + "/../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot3.log") #TODO: Container name, docker file name from constants. self.dockerClient.images.build( tag="photon_build_container:latest", path=".", rm=True, dockerfile="Dockerfile.photon_build_container") # Cleanup cmd = "rm -f ./tcroot.tar.gz" cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot4.log") chrUtils.destroyChroot(chrootID) self.logger.info("Photon build container successfully created.")
def prepareBuildRoot(self, chrootName, packageName): chrootID = None try: chrUtils = ChrootUtils(self.logName, self.logPath) returnVal, chrootID = chrUtils.createChroot(chrootName) self.logger.debug("Created new chroot: " + chrootID) if not returnVal: raise Exception("Unable to prepare build root") tUtils = ToolChainUtils(self.logName, self.logPath) tUtils.installToolChainRPMS(chrootID, packageName) except Exception as e: if chrootID is not None: self.logger.debug("Deleting chroot: " + chrootID) chrUtils.destroyChroot(chrootID) raise e return chrootID
def prepareBuildRoot(self,chrootName, packageName): chrootID=None try: chrUtils = ChrootUtils(self.logName,self.logPath) returnVal,chrootID = chrUtils.createChroot(chrootName) self.logger.debug("Created new chroot: " + chrootID) if not returnVal: raise Exception("Unable to prepare build root") tUtils=ToolChainUtils(self.logName,self.logPath) tUtils.installToolChainRPMS(chrootID, packageName) except Exception as e: if chrootID is not None: self.logger.debug("Deleting chroot: " + chrootID) chrUtils.destroyChroot(chrootID) raise e return chrootID
def _createBuildContainer(self): self.logger.info("Generating photon build container..") try: #TODO image name constants.buildContainerImageName self.dockerClient.images.remove("photon_build_container:latest", force=True) except Exception as e: #TODO - better handling self.logger.debug("Photon build container image not found.") # Create toolchain chroot and install toolchain RPMs chrootID = None try: #TODO: constants.tcrootname chrUtils = ChrootUtils("toolchain-chroot", self.logPath) returnVal, chrootID = chrUtils.createChroot("toolchain-chroot") self.logger.debug("Created tool-chain chroot: " + chrootID) if not returnVal: raise Exception("Unable to prepare tool-chain chroot") tcUtils = ToolChainUtils("toolchain-chroot", self.logPath) tcUtils.installToolChainRPMS(chrootID, "dummy") except Exception as e: if chrootID is not None: self.logger.debug("Deleting chroot: " + chrootID) chrUtils.destroyChroot(chrootID) raise e self.logger.info("VDBG-PU-createBuildContainer: chrootID: " + chrootID) # Create photon build container using toolchain chroot #TODO: Coalesce logging cmdUtils = CommandUtils() cmd = "./umount-build-root.sh " + chrootID cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot1.log") cmd = "cd " + chrootID + " && tar -czvf ../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot2.log") cmd = "mv " + chrootID + "/../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot3.log") #TODO: Container name, docker file name from constants. self.dockerClient.images.build(tag="photon_build_container:latest", path=".", rm=True, dockerfile="Dockerfile.photon_build_container") # Cleanup cmd = "rm -f ./tcroot.tar.gz" cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot4.log") chrUtils.destroyChroot(chrootID) self.logger.info("Photon build container successfully created.")
def _createBuildContainer(self, usePublishedRPMs): self.logger.debug("Generating photon build container..") try: #TODO image name constants.buildContainerImageName self.dockerClient.images.remove(constants.buildContainerImage, force=True) except Exception as e: #TODO - better handling self.logger.debug("Photon build container image not found.") # Create toolchain chroot and install toolchain RPMs chroot = None try: #TODO: constants.tcrootname chroot = Chroot(self.logger) chroot.create("toolchain-chroot") tcUtils = ToolChainUtils("toolchain-chroot", self.logPath) tcUtils.installToolchainRPMS(chroot, usePublishedRPMS=usePublishedRPMs) except Exception as e: if chroot: chroot.destroy() raise e self.logger.debug("createBuildContainer: " + chroot.getID()) # Create photon build container using toolchain chroot chroot.unmountAll() #TODO: Coalesce logging cmdUtils = CommandUtils() cmd = "cd " + chroot.getID() + " && tar -czf ../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) cmd = "mv " + chroot.getID() + "/../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) #TODO: Container name, docker file name from constants. self.dockerClient.images.build( tag=constants.buildContainerImage, path=".", rm=True, dockerfile="Dockerfile.photon_build_container") # Cleanup cmd = "rm -f ./tcroot.tar.gz" cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) chroot.destroy() self.logger.debug("Photon build container successfully created.")
def _createBuildContainer(self, usePublishedRPMs): self.logger.debug("Generating photon build container..") try: #TODO image name constants.buildContainerImageName self.dockerClient.images.remove(constants.buildContainerImage, force=True) except Exception as e: #TODO - better handling self.logger.debug("Photon build container image not found.") # Create toolchain chroot and install toolchain RPMs chroot = None try: #TODO: constants.tcrootname chroot = Chroot(self.logger) chroot.create("toolchain-chroot") tcUtils = ToolChainUtils("toolchain-chroot", self.logPath) tcUtils.installToolchainRPMS(chroot, usePublishedRPMS=usePublishedRPMs) except Exception as e: if chroot: chroot.destroy() raise e self.logger.debug("createBuildContainer: " + chroot.getID()) # Create photon build container using toolchain chroot chroot.unmountAll() #TODO: Coalesce logging cmdUtils = CommandUtils() cmd = "cd " + chroot.getID() + " && tar -czf ../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) cmd = "mv " + chroot.getID() + "/../tcroot.tar.gz ." cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) #TODO: Container name, docker file name from constants. self.dockerClient.images.build(tag=constants.buildContainerImage, path=".", rm=True, dockerfile="Dockerfile.photon_build_container") # Cleanup cmd = "rm -f ./tcroot.tar.gz" cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug) chroot.destroy() self.logger.debug("Photon build container successfully created.")
def _buildPackage(self): try: self.sandbox.create(self.package + "-" + self.version) tUtils = ToolChainUtils(self.logName, self.logPath) if self.sandbox.hasToolchain(): tUtils.installExtraToolchainRPMS(self.sandbox, self.package, self.version) else: tUtils.installToolchainRPMS(self.sandbox, self.package, self.version, availablePackages=self.doneList) self._installDependencies(constants.buildArch) if constants.crossCompiling: self._installDependencies(constants.targetArch) pkgUtils = PackageUtils(self.logName, self.logPath) pkgUtils.adjustGCCSpecs(self.sandbox, self.package, self.version) pkgUtils.buildRPMSForGivenPackage(self.sandbox, self.package, self.version, self.logPath) self.logger.debug("Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package: " + self.package) self.logger.debug("Sandbox: " + self.sandbox.getID() + " not deleted for debugging.") logFileName = os.path.join(self.logPath, self.package + ".log") fileLog = os.popen('tail -n 100 ' + logFileName).read() self.logger.info(fileLog) raise e if self.sandbox: self.sandbox.destroy()
def _buildPackage(self): try: self.sandbox.create(self.package + "-" + self.version) tUtils = ToolChainUtils(self.logName, self.logPath) if self.sandbox.hasToolchain(): tUtils.installExtraToolchainRPMS(self.sandbox, self.package, self.version) else: tUtils.installToolchainRPMS(self.sandbox, self.package, self.version, availablePackages=self.doneList) listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(self.sandbox)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.debug("Installing the build time dependent packages......") for pkg in listDependentPackages: packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg) self._installPackage(pkgUtils, packageName, packageVersion, self.sandbox, self.logPath,listInstalledPackages, listInstalledRPMs) for pkg in listTestPackages: flag = False packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg) for depPkg in listDependentPackages: depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion(depPkg) if depPackageName == packageName: flag = True break; if flag == False: self._installPackage(pkgUtils, packageName,packageVersion, self.sandbox, self.logPath,listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInOneShot(self.sandbox) self.logger.debug("Finished installing the build time dependent packages....") pkgUtils.adjustGCCSpecs(self.sandbox, self.package, self.version) pkgUtils.buildRPMSForGivenPackage(self.sandbox, self.package, self.version, self.logPath) self.logger.debug("Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package: " + self.package) self.logger.debug("Sandbox: " + self.sandbox.getID() + " not deleted for debugging.") logFileName = os.path.join(self.logPath, self.package + ".log") fileLog = os.popen('tail -n 100 ' + logFileName).read() self.logger.info(fileLog) raise e if self.sandbox: self.sandbox.destroy()
def buildPackage(self): #do not build if RPM is already built #test only if the package is in the testForceRPMS with rpmCheck #build only if the package is not in the testForceRPMS with rpmCheck if self.base.checkIfPackageIsAlreadyBuilt(): if not constants.rpmCheck: self.base.logger.info("Skipping building the package:" + self.base.package) return elif constants.rpmCheck and self.base.package not in constants.testForceRPMS: self.base.logger.info("Skipping testing the package:" + self.base.package) return #should initialize a logger based on package name containerTaskName = "build-" + self.base.package containerID = None chrootID = None isToolChainPackage = False if self.base.package in constants.listToolChainPackages: isToolChainPackage = True destLogPath = constants.logPath + "/build-" + self.base.package try: containerID, chrootID = self.prepareBuildContainer( containerTaskName, self.base.package, isToolChainPackage) tcUtils = ToolChainUtils(self.base.logName, self.base.logPath) if self.base.package in constants.perPackageToolChain: self.base.logger.debug( constants.perPackageToolChain[self.base.package]) tcUtils.installCustomToolChainRPMSinContainer( containerID, constants.perPackageToolChain[self.base.package], self.base.package) listInstalledPackages, listInstalledRPMs = self.base.findInstalledPackages( containerID) self.base.logger.info(listInstalledPackages) listDependentPackages = self.base.findBuildTimeRequiredPackages() if constants.rpmCheck and self.base.package in constants.testForceRPMS: listDependentPackages.extend( self.base.findBuildTimeCheckRequiredPackages()) testPackages = set( constants.listMakeCheckRPMPkgtoInstall) - set( listInstalledPackages) - set([self.base.package]) listDependentPackages.extend(testPackages) listDependentPackages = list(set(listDependentPackages)) pkgUtils = PackageUtils(self.base.logName, self.base.logPath) if len(listDependentPackages) != 0: self.base.logger.info( "BuildContainer-buildPackage: Installing dependent packages.." ) self.base.logger.info(listDependentPackages) for pkg in listDependentPackages: self.base.installPackage(pkgUtils, pkg, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInAOneShotInContainer( containerID, destLogPath) self.base.logger.info( "Finished installing the build time dependent packages......" ) self.base.logger.info( "BuildContainer-buildPackage: Start building the package: " + self.base.package) pkgUtils.adjustGCCSpecsInContainer(self.base.package, containerID, destLogPath) pkgUtils.buildRPMSForGivenPackageInContainer( self.base.package, containerID, self.base.listBuildOptionPackages, self.base.pkgBuildOptionFile, destLogPath) self.base.logger.info( "BuildContainer-buildPackage: Successfully built the package: " + self.base.package) except Exception as e: self.base.logger.error("Failed while building package:" + self.base.package) if containerID is not None: self.base.logger.debug("Container " + containerID.short_id + " retained for debugging.") logFileName = os.path.join(destLogPath, self.base.package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.base.logger.debug(fileLog) raise e # Remove the container if containerID is not None: containerID.remove(force=True) # Remove the dummy chroot if chrootID is not None: chrUtils = ChrootUtils(self.base.logName, self.base.logPath) chrUtils.destroyChroot(chrootID)
def _buildPackage(self): #should initialize a logger based on package name containerTaskName = "build-" + self.package + "-" + self.version container = None try: container = Container(self.logger) container.create(containerTaskName) tcUtils = ToolChainUtils(self.logName, self.logPath) tcUtils.installCustomToolChainRPMS(container, self.package, self.version) listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(container)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.debug( "Installing the build time dependent packages......") for pkg in listDependentPackages: packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) self._installPackage(pkgUtils, packageName, packageVersion, container, self.logPath, listInstalledPackages, listInstalledRPMs) for pkg in listTestPackages: flag = False packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) for depPkg in listDependentPackages: depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion( depPkg) if depPackageName == packageName: flag = True break if flag == False: self._installPackage(pkgUtils, packageName, packageVersion, container, self.logPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInOneShot(container) self.logger.debug( "Finished installing the build time dependent packages...." ) self.logger.debug( "BuildContainer-buildPackage: Start building the package: " + self.package) pkgUtils.adjustGCCSpecs(container, self.package, self.version) pkgUtils.buildRPMSForGivenPackage(container, self.package, self.version, self.logPath) self.logger.debug( "BuildContainer-buildPackage: Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package:" + self.package) if container is not None: self.logger.debug("Container " + container.getID() + " retained for debugging.") logFileName = os.path.join(self.logPath, self.package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.logger.debug(fileLog) raise e # Remove the container if container: container.destroy()
def _buildPackage(self): #should initialize a logger based on package name containerTaskName = "build-" + self.package containerID = None chrootID = None isToolChainPackage = False if self.package in constants.listToolChainPackages: isToolChainPackage = True destLogPath = constants.logPath + "/build-" + self.package try: containerID, chrootID = self._prepareBuildContainer( containerTaskName, self.package, self.version, isToolChainPackage) tcUtils = ToolChainUtils(self.logName, self.logPath) if self.package in constants.perPackageToolChain: self.logger.debug(constants.perPackageToolChain[self.package]) tcUtils.installCustomToolChainRPMSinContainer( containerID, constants.perPackageToolChain[self.package].get( platform.machine(), []), self.package) listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(containerID)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.info("BuildContainer-buildPackage: " + "Installing dependent packages..") self.logger.info(listDependentPackages) for pkg in listDependentPackages: packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) self._installPackage(pkgUtils, packageName, packageVersion, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) for pkg in listTestPackages: packageName, packageVersion = StringUtils.splitPackageNameAndVersion( pkg) flag = False for depPkg in listDependentPackages: depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion( depPkg) if depPackageName == packageName: flag = True break if flag == False: self._installPackage(pkgUtils, packageName, packageVersion, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInAOneShotInContainer( containerID, destLogPath) self.logger.info( "Finished installing the build time dependent packages...." ) self.logger.info( "BuildContainer-buildPackage: Start building the package: " + self.package) pkgUtils.adjustGCCSpecsInContainer(self.package, self.version, containerID, destLogPath) pkgUtils.buildRPMSForGivenPackageInContainer( self.package, self.version, containerID, destLogPath) self.logger.info( "BuildContainer-buildPackage: Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package:" + self.package) if containerID is not None: self.logger.debug("Container " + containerID.short_id + " retained for debugging.") logFileName = os.path.join(destLogPath, self.package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.logger.debug(fileLog) raise e # Remove the container if containerID is not None: containerID.remove(force=True) # Remove the dummy chroot if chrootID is not None: chrUtils = ChrootUtils(self.logName, self.logPath) chrUtils.destroyChroot(chrootID)
def _buildPackage(self): #do not build if RPM is already built #test only if the package is in the testForceRPMS with rpmCheck #build only if the package is not in the testForceRPMS with rpmCheck if self._checkIfPackageIsAlreadyBuilt(): if not constants.rpmCheck: self.logger.info("Skipping building the package:" + self.package) return elif constants.rpmCheck and self.package not in constants.testForceRPMS: self.logger.info("Skipping testing the package:" + self.package) return #should initialize a logger based on package name containerTaskName = "build-" + self.package containerID = None chrootID = None isToolChainPackage = False if self.package in constants.listToolChainPackages: isToolChainPackage = True destLogPath = constants.logPath + "/build-" + self.package try: containerID, chrootID = self._prepareBuildContainer( containerTaskName, self.package, isToolChainPackage) tcUtils = ToolChainUtils(self.logName, self.logPath) if self.package in constants.perPackageToolChain: self.logger.debug(constants.perPackageToolChain[self.package]) tcUtils.installCustomToolChainRPMSinContainer( containerID, constants.perPackageToolChain[self.package], self.package) listDependentPackages, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(containerID)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.info("BuildContainer-buildPackage: " + "Installing dependent packages..") self.logger.info(listDependentPackages) for pkg in listDependentPackages: self._installPackage(pkgUtils, pkg, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInAOneShotInContainer(containerID, destLogPath) self.logger.info("Finished installing the build time dependent packages....") self.logger.info("BuildContainer-buildPackage: Start building the package: " + self.package) pkgUtils.adjustGCCSpecsInContainer(self.package, containerID, destLogPath) pkgUtils.buildRPMSForGivenPackageInContainer( self.package, containerID, destLogPath) self.logger.info("BuildContainer-buildPackage: Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package:" + self.package) if containerID is not None: self.logger.debug("Container " + containerID.short_id + " retained for debugging.") logFileName = os.path.join(destLogPath, self.package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.logger.debug(fileLog) raise e # Remove the container if containerID is not None: containerID.remove(force=True) # Remove the dummy chroot if chrootID is not None: chrUtils = ChrootUtils(self.logName, self.logPath) chrUtils.destroyChroot(chrootID)
def buildPackage(self, package): #do not build if RPM is already built #test only if the package is in the testForceRPMS with rpmCheck #build only if the package is not in the testForceRPMS with rpmCheck if self.checkIfPackageIsAlreadyBuilt(package): if not constants.rpmCheck: self.logger.info("Skipping building the package:" + package) return elif constants.rpmCheck and package not in constants.testForceRPMS: self.logger.info("Skipping testing the package:" + package) return #should initialize a logger based on package name containerTaskName = "build-" + package containerID = None isToolChainPackage = False if package in constants.listToolChainPackages: isToolChainPackage = True destLogPath = constants.logPath + "/build-" + package try: containerID = self.prepareBuildContainer(containerTaskName, package, isToolChainPackage) if not os.path.isdir(destLogPath): cmdUtils = CommandUtils() cmdUtils.runCommandInShell("mkdir -p " + destLogPath) tcUtils = ToolChainUtils(self.logName, self.logPath) if package in constants.perPackageToolChain: self.logger.debug(constants.perPackageToolChain[package]) tcUtils.installCustomToolChainRPMSinContainer( containerID, constants.perPackageToolChain[package], package) listInstalledPackages, listInstalledRPMs = self.findInstalledPackages( containerID) self.logger.info(listInstalledPackages) listDependentPackages = self.findBuildTimeRequiredPackages(package) if constants.rpmCheck and package in constants.testForceRPMS: listDependentPackages.extend( self.findBuildTimeCheckRequiredPackages(package)) testPackages = set( constants.listMakeCheckRPMPkgtoInstall) - set( listInstalledPackages) - set([package]) listDependentPackages.extend(testPackages) listDependentPackages = list(set(listDependentPackages)) pkgUtils = PackageUtils(self.logName, self.logPath) if len(listDependentPackages) != 0: self.logger.info( "BuildContainer-buildPackage: Installing dependent packages.." ) self.logger.info(listDependentPackages) for pkg in listDependentPackages: self.installPackage(pkgUtils, pkg, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) # Special case sqlite due to package renamed from sqlite-autoconf to sqlite if "sqlite" in listInstalledPackages or "sqlite-devel" in listInstalledPackages or "sqlite-libs" in listInstalledPackages: if "sqlite" not in listInstalledPackages: self.installPackage(pkgUtils, "sqlite", containerID, destLogPath, listInstalledPackages, listInstalledRPMs) if "sqlite-devel" not in listInstalledPackages: self.installPackage(pkgUtils, "sqlite-devel", containerID, destLogPath, listInstalledPackages, listInstalledRPMs) if "sqlite-libs" not in listInstalledPackages: self.installPackage(pkgUtils, "sqlite-libs", containerID, destLogPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInAOneShotInContainer( containerID, destLogPath) pkgUtils.adjustGCCSpecsInContainer(package, containerID, destLogPath) pkgUtils.buildRPMSForGivenPackageInContainer( package, containerID, self.listBuildOptionPackages, self.pkgBuildOptionFile, destLogPath) self.logger.info( "BuildContainer-buildPackage: Successfully built the package: " + package) except Exception as e: self.logger.error("Failed while building package:" + package) if containerID is not None: self.logger.debug("Container " + containerID.short_id + " retained for debugging.") logFileName = os.path.join(destLogPath, package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.logger.debug(fileLog) raise e # Remove the container if containerID is not None: containerID.remove(force=True)
def _buildPackage(self, index=0): #do not build if RPM is already built #test only if the package is in the testForceRPMS with rpmCheck #build only if the package is not in the testForceRPMS with rpmCheck if self._checkIfPackageIsAlreadyBuilt(index): if not constants.rpmCheck: self.logger.info("Skipping building the package:" + self.package) return elif constants.rpmCheck and self.package not in constants.testForceRPMS: self.logger.info("Skipping testing the package:" + self.package) return #should initialize a logger based on package name containerTaskName = "build-" + self.package containerID = None chrootID = None isToolChainPackage = False if self.package in constants.listToolChainPackages: isToolChainPackage = True destLogPath = constants.logPath + "/build-" + self.package try: containerID, chrootID = self._prepareBuildContainer( containerTaskName, self.package, isToolChainPackage) tcUtils = ToolChainUtils(self.logName, self.logPath) if self.package in constants.perPackageToolChain: self.logger.debug(constants.perPackageToolChain[self.package]) tcUtils.installCustomToolChainRPMSinContainer( containerID, constants.perPackageToolChain[self.package], self.package) listDependentPackages, listDependentPackagesParseObj, listInstalledPackages, listInstalledRPMs = ( self._findDependentPackagesAndInstalledRPM(containerID, index)) pkgUtils = PackageUtils(self.logName, self.logPath) if listDependentPackages: self.logger.info("BuildContainer-buildPackage: " + "Installing dependent packages..") self.logger.info(listDependentPackages) for pkg in listDependentPackages: flag = False for objName in listDependentPackagesParseObj: if objName.package == pkg: properVersion = self._getProperVersion( pkg, objName) self._installPackage(pkgUtils, pkg, properVersion, containerID, destLogPath, listInstalledPackages, listInstalledRPMs) flag = True break if flag == False: self._installPackage(pkgUtils, pkg, "*", containerID, destLogPath, listInstalledPackages, listInstalledRPMs) pkgUtils.installRPMSInAOneShotInContainer( containerID, destLogPath) self.logger.info( "Finished installing the build time dependent packages...." ) self.logger.info( "BuildContainer-buildPackage: Start building the package: " + self.package) pkgUtils.adjustGCCSpecsInContainer(self.package, containerID, destLogPath, index) pkgUtils.buildRPMSForGivenPackageInContainer( self.package, containerID, destLogPath, index) self.logger.info( "BuildContainer-buildPackage: Successfully built the package: " + self.package) except Exception as e: self.logger.error("Failed while building package:" + self.package) if containerID is not None: self.logger.debug("Container " + containerID.short_id + " retained for debugging.") logFileName = os.path.join(destLogPath, self.package + ".log") fileLog = os.popen('tail -n 20 ' + logFileName).read() self.logger.debug(fileLog) raise e # Remove the container if containerID is not None: containerID.remove(force=True) # Remove the dummy chroot if chrootID is not None: chrUtils = ChrootUtils(self.logName, self.logPath) chrUtils.destroyChroot(chrootID)