示例#1
0
    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()
示例#2
0
    def buildCoreToolChainPackages(self):
        self.logger.info("Step 1 : Building the core toolchain packages for " + constants.currentArch)
        self.logger.info(constants.listCoreToolChainPackages)
        self.logger.info("")
        chroot = None
        pkgCount = 0
        try:
            pkgUtils = PackageUtils(self.logName, self.logPath)
            coreToolChainYetToBuild = []
            doneList = []
            #self.logger.debug(">>>> Looking for available packages...")
            for package in constants.listCoreToolChainPackages:
                version = SPECS.getData().getHighestVersion(package)
                rpmPkg = pkgUtils.findRPMFile(package, version)
                #rpmPkg = pkgUtils.findRPMFile(package, version, constants.buildArch)
                if rpmPkg is not None:
                    doneList.append(package+'-'+version)
                    #self.logger.debug(">>>>>> %s", package+'-'+version)
                    continue
                else:
                    coreToolChainYetToBuild.append(package)
            if coreToolChainYetToBuild:
                self.logger.info("The following core toolchain packages need to be built :")
                self.logger.info(coreToolChainYetToBuild)
            else:
                self.logger.info("Core toolchain packages are already available")

            for package in coreToolChainYetToBuild:
                self.logger.debug("Building core toolchain package : " + package)
                version = SPECS.getData().getHighestVersion(package)
                destLogPath = constants.logPath + "/" + package + "-" + version + "." + constants.currentArch
                if not os.path.isdir(destLogPath):
                    CommandUtils.runCommandInShell("mkdir -p " + destLogPath)
                chroot = Chroot(self.logger)
                chroot.create(package + "-" + version)
                #self.logger.debug(">>>>> Done List:")
                #self.logger.info(doneList)
                self.installToolchainRPMS(chroot, package, version, availablePackages=doneList)
                pkgUtils.adjustGCCSpecs(chroot, package, version)
                pkgUtils.buildRPMSForGivenPackage(chroot, package, version, destLogPath)
                pkgCount += 1
                chroot.destroy()
                doneList.append(package+'-'+version)
            self.logger.debug("Successfully built toolchain")
            self.logger.info("-" * 45 + "\n")
        except Exception as e:
            self.logger.error("Unable to build toolchain.")
            # print stacktrace
            traceback.print_exc()
            raise e
        return pkgCount
示例#3
0
    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.")
示例#4
0
    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.")