Esempio n. 1
0
    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].get(
                        platform.machine(), []), self.package)

            listDependentPackages, listTestPackages, 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:
                    properVersion = pkgUtils._getProperVersion(
                        pkg.package, pkg)
                    self._installPackage(pkgUtils, pkg.package, properVersion,
                                         containerID, destLogPath,
                                         listInstalledPackages,
                                         listInstalledRPMs)
                for pkg in listTestPackages:
                    flag = False
                    for lineContent in listDependentPackages:
                        if lineContent.package == pkg:
                            properVersion = pkgUtils._getProperVersion(
                                pkg, lineContent)
                            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)
Esempio n. 2
0
    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

        chrUtils = ChrootUtils(self.logName, self.logPath)
        chrootID = None
        try:
            chrootID = self._prepareBuildRoot()
            listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = (
                self._findDependentPackagesAndInstalledRPM(chrootID, index))

            pkgUtils = PackageUtils(self.logName, self.logPath)

            if listDependentPackages:
                self.logger.info(
                    "Installing the build time dependent packages......")
                for pkg in listDependentPackages:
                    properVersion = pkgUtils._getProperVersion(
                        pkg.package, pkg)
                    self._installPackage(pkgUtils, pkg.package, properVersion,
                                         chrootID, self.logPath,
                                         listInstalledPackages,
                                         listInstalledRPMs)
                for pkg in listTestPackages:
                    flag = False
                    for lineContent in listDependentPackages:
                        if lineContent.package == pkg:
                            properVersion = pkgUtils._getProperVersion(
                                pkg, lineContent)
                            self._installPackage(pkgUtils, pkg, properVersion,
                                                 chrootID, self.logPath,
                                                 listInstalledPackages,
                                                 listInstalledRPMs)
                            flag = True
                            break
                    if flag == False:
                        self._installPackage(pkgUtils, pkg, "*", chrootID,
                                             self.logPath,
                                             listInstalledPackages,
                                             listInstalledRPMs)
                pkgUtils.installRPMSInAOneShot(chrootID, self.logPath)
                self.logger.info(
                    "Finished installing the build time dependent packages...."
                )

            pkgUtils.adjustGCCSpecs(self.package, chrootID, self.logPath,
                                    index)
            pkgUtils.buildRPMSForGivenPackage(self.package, chrootID,
                                              self.logPath, index)
            self.logger.info("Successfully built the package:" + self.package)
        except Exception as e:
            self.logger.error("Failed while building package:" + self.package)
            self.logger.debug("Chroot with ID: " + chrootID +
                              " not deleted for debugging.")
            logFileName = os.path.join(self.logPath, self.package + ".log")
            fileLog = os.popen('tail -n 100 ' + logFileName).read()
            self.logger.debug(fileLog)
            raise e
        if chrootID is not None:
            chrUtils.destroyChroot(chrootID)
Esempio n. 3
0
    def installToolChainRPMS(self,
                             chrootID,
                             packageName,
                             logPath=None,
                             index=0):
        if logPath is None:
            logPath = self.logPath
        cmdUtils = CommandUtils()
        self.prepareBuildRoot(chrootID)
        self.logger.info("Installing Tool Chain RPMS.......")
        rpmFiles = ""
        packages = ""
        self.package = packageName
        listBuildRequiresPackageLineContent = self.getListDependentPackageLineContent(
            index)
        for package in constants.listToolChainRPMsToInstall:
            pkgUtils = PackageUtils(self.logName, self.logPath)
            rpmFile = None
            version = "*"
            for depPkg in listBuildRequiresPackageLineContent:
                if depPkg.package == package:
                    version = pkgUtils._getProperVersion(package, depPkg)
            if constants.rpmCheck:
                rpmFile = pkgUtils.findRPMFileForGivenPackage(package, version)
            else:
                if (packageName not in constants.listToolChainRPMsToInstall or
                        constants.listToolChainRPMsToInstall.index(packageName)
                        > constants.listToolChainRPMsToInstall.index(package)):
                    rpmFile = pkgUtils.findRPMFileForGivenPackage(
                        package, version)
            if rpmFile is None:
                # sqlite-autoconf package was renamed, but it still published as sqlite-autoconf
                if (package == "sqlite") and (platform.machine() == "x86_64"):
                    package = "sqlite-autoconf"
                rpmFile = self.findRPMFileInGivenLocation(
                    package, constants.prevPublishRPMRepo)
                if rpmFile is None:
                    if package in constants.listOfRPMsProvidedAfterBuild:
                        self.logger.info(
                            "No old version of " + package +
                            " exists, skip until the new version is built")
                        continue
                    self.logger.error("Unable to find rpm " + package +
                                      " in current and previous versions")
                    raise Exception("Input Error")
            rpmFiles += " " + rpmFile
            packages += " " + package

        self.logger.debug("Installing toolchain rpms:" + packages)
        cmd = (self.rpmCommand + " -i -v --nodeps --noorder --force --root " +
               chrootID + " --define \'_dbpath /var/lib/rpm\' " + rpmFiles)
        retVal = cmdUtils.runCommandInShell(
            cmd, logPath + "/install_toolchain_rpms.log")
        if not retVal:
            self.logger.debug("Command Executed:" + cmd)
            self.logger.error("Installing tool chain  failed")
            raise Exception("RPM installation failed")
        self.logger.info(
            "Successfully installed default Tool Chain RPMS in Chroot:" +
            chrootID)
        print("Building Package: ".format(packageName))
        print(constants.perPackageToolChain)
        if packageName in constants.perPackageToolChain:
            print(constants.perPackageToolChain[packageName])
            self.installCustomToolChainRPMS(
                chrootID, constants.perPackageToolChain[packageName].get(
                    platform.machine(), []), packageName)