Example #1
0
def _loadRecipe(helper, package, recipePath):
    # Load the recipe
    use.setBuildFlagsFromFlavor(package.getPackageName(),
            helper.cfg.buildFlavor, error=False)
    if package.targetConfig.factory and package.targetConfig.factory != 'factory':
        sourceTrove, targetDir = tempSourceTrove(recipePath, package, helper)
        loader = RecipeLoaderFromSourceDirectory(sourceTrove, repos=helper.getRepos(),
                            cfg=helper.cfg, parentDir=targetDir,
                            labelPath=helper.plan.installLabelPath
                            )
    else:
        sourceTrove = None
        loader = RecipeLoader(recipePath, helper.cfg, helper.getRepos(),
                        directory=helper.plan.recipeDir,
                        factory=package.targetConfig.factory,
                        )

    recipeClass = loader.getRecipe()
    dummybranch = Branch([helper.plan.getTargetLabel()])
    dummyrev = Revision('1-1')
    dummyver = dummybranch.createVersion(dummyrev)
    macros = {
            'buildlabel': dummybranch.label().asString(),
            'buildbranch': dummybranch.asString(),
            }
    # Instantiate and setup if needed
    lcache = RepositoryCache(helper.getRepos(),
            refreshFilter=lambda x: helper.plan.refreshSources)
    if recipeClass.getType() == cny_recipe.RECIPE_TYPE_GROUP:
        recipeObj = recipeClass(
                repos=helper.getRepos(),
                cfg=helper.cfg,
                label=dummybranch.label(),
                flavor=helper.cfg.buildFlavor,
                laReposCache=lcache,
                extraMacros=macros,
                )
    elif recipeClass.getType() in [
            cny_recipe.RECIPE_TYPE_PACKAGE,
            cny_recipe.RECIPE_TYPE_INFO,
            cny_recipe.RECIPE_TYPE_CAPSULE,
            ]:
        recipeObj = recipeClass(
                cfg=helper.cfg,
                laReposCache=lcache,
                srcdirs=[],
                extraMacros=macros,
                lightInstance=True,
                )
    else:
        return recipeClass
    if not recipeObj.needsCrossFlags():
        recipeObj.crossRequires = []
    if sourceTrove is None:
        recipeObj.populateLcache()
    recipeObj.sourceVersion = dummyver
    recipeObj.loadPolicy()
    recipeObj.setup()
    return recipeObj
Example #2
0
def _loadRecipe(helper, package, recipePath):
    # Load the recipe
    use.setBuildFlagsFromFlavor(package.getPackageName(),
            helper.cfg.buildFlavor, error=False)
    if package.targetConfig.factory and package.targetConfig.factory != 'factory':
        sourceTrove, targetDir = tempSourceTrove(recipePath, package, helper)
        loader = RecipeLoaderFromSourceDirectory(sourceTrove, repos=helper.getRepos(),
                            cfg=helper.cfg, parentDir=targetDir,
                            labelPath=helper.plan.installLabelPath
                            )
    else:
        sourceTrove = None
        loader = RecipeLoader(recipePath, helper.cfg, helper.getRepos(),
                        directory=helper.plan.recipeDir,
                        factory=package.targetConfig.factory,
                        )

    recipeClass = loader.getRecipe()
    dummybranch = Branch([helper.plan.getTargetLabel()])
    dummyrev = Revision('1-1')
    dummyver = dummybranch.createVersion(dummyrev)
    macros = {
            'buildlabel': dummybranch.label().asString(),
            'buildbranch': dummybranch.asString(),
            }
    # Instantiate and setup if needed
    lcache = RepositoryCache(helper.getRepos(),
            refreshFilter=lambda x: helper.plan.refreshSources)
    if recipeClass.getType() == cny_recipe.RECIPE_TYPE_GROUP:
        recipeObj = recipeClass(
                repos=helper.getRepos(),
                cfg=helper.cfg,
                label=dummybranch.label(),
                flavor=helper.cfg.buildFlavor,
                laReposCache=lcache,
                extraMacros=macros,
                )
    elif recipeClass.getType() in [
            cny_recipe.RECIPE_TYPE_PACKAGE,
            cny_recipe.RECIPE_TYPE_INFO,
            cny_recipe.RECIPE_TYPE_CAPSULE,
            ]:
        recipeObj = recipeClass(
                cfg=helper.cfg,
                laReposCache=lcache,
                srcdirs=[],
                extraMacros=macros,
                lightInstance=True,
                )
    else:
        return recipeClass
    if not recipeObj.needsCrossFlags():
        recipeObj.crossRequires = []
    if sourceTrove is None:
        recipeObj.populateLcache()
    recipeObj.sourceVersion = dummyver
    recipeObj.loadPolicy()
    recipeObj.setup()
    return recipeObj
Example #3
0
    def testMacroOverrides(self):
        self.overrideBuildFlavor('is:x86(!i686,!i586,i486)')
        use.setBuildFlagsFromFlavor('group-test', self.cfg.buildFlavor)

        recipeClass = self._loadRecipe()
        dummy = recipeClass(None, self.cfg, None, None, None,
            lightInstance=True)
        self.assertEqual(dummy.macros.dummyMacro, 'right')
Example #4
0
 def testTargetFlavor(self):
     use.setBuildFlagsFromFlavor(None, self.cfg.buildFlavor, error=False)
     targetFlavor = str(
         use.createFlavor(None, use.Arch._iterAll(), targetDep=True))
     assert (targetFlavor)
     flavor = str(
         use.createFlavor(None, use.Arch._iterAll(), targetDep=False))
     assert (targetFlavor.replace('target', 'is') == flavor)
Example #5
0
 def _setArchFlags(flavor):
     # given an flavor, make use.Arch match that flavor.
     for flag in use.Arch._iterAll():
         flag._set(False)
     use.setBuildFlagsFromFlavor(self.name,
                                 flavor,
                                 error=False,
                                 useCross=False)
Example #6
0
    def runCommand(self, thisCommand, cfg, argSet, args, debugAll=False):
        client = conaryclient.ConaryClient(cfg)
        repos = client.getRepos()
        callback = commit.CheckinCallback(cfg)

        if not cfg.buildLabel and cfg.installLabelPath:
            cfg.buildLabel = cfg.installLabelPath[0]

        sys.excepthook = util.genExcepthook(debug=cfg.debugExceptions,
                                            debugCtrlC=debugAll)

        if cfg.installLabelPath:
            cfg.installLabel = cfg.installLabelPath[0]
        else:
            cfg.installLabel = None

        cfg.initializeFlavors()
        log.setMinVerbosity(log.INFO)
        log.resetErrorOccurred()

        # set the build flavor here, just to set architecture information
        # which is used when initializing a recipe class
        use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False)

        profile = False
        if argSet.has_key('lsprof'):
            import cProfile
            prof = cProfile.Profile()
            prof.enable()
            profile = 'lsprof'
            del argSet['lsprof']

        keyCache = openpgpkey.getKeyCache()
        keyCache.setPublicPath(cfg.pubRing)
        repos = conaryclient.ConaryClient(cfg).getRepos()
        keyCacheCallback = openpgpkey.KeyCacheCallback(repos, cfg)
        keyCache.setCallback(keyCacheCallback)

        try:
            rv = options.MainHandler.runCommand(self,
                                                thisCommand,
                                                cfg,
                                                argSet,
                                                args,
                                                callback=callback,
                                                repos=client.getRepos(),
                                                profile=profile)
        finally:
            if profile == 'lsprof':
                prof.disable()
                prof.dump_stats('cvc.lsprof')
                prof.print_stats()
            elif profile:
                prof.stop()

        if log.errorOccurred():
            sys.exit(2)
        return rv
Example #7
0
    def runCommand(self, thisCommand, cfg, argSet, args, debugAll=False):
        client = conaryclient.ConaryClient(cfg)
        repos = client.getRepos()
        callback = commit.CheckinCallback(cfg)

        if not cfg.buildLabel and cfg.installLabelPath:
            cfg.buildLabel = cfg.installLabelPath[0]

        sys.excepthook = util.genExcepthook(debug=cfg.debugExceptions,
                                            debugCtrlC=debugAll)

        if cfg.installLabelPath:
            cfg.installLabel = cfg.installLabelPath[0]
        else:
            cfg.installLabel = None

        cfg.initializeFlavors()
        log.setMinVerbosity(log.INFO)
        log.resetErrorOccurred()

        # set the build flavor here, just to set architecture information
        # which is used when initializing a recipe class
        use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False)

        profile = False
        if argSet.has_key('lsprof'):
            import cProfile
            prof = cProfile.Profile()
            prof.enable()
            profile = 'lsprof'
            del argSet['lsprof']

        keyCache = openpgpkey.getKeyCache()
        keyCache.setPublicPath(cfg.pubRing)
        repos = conaryclient.ConaryClient(cfg).getRepos()
        keyCacheCallback = openpgpkey.KeyCacheCallback(repos,
                                                       cfg)
        keyCache.setCallback(keyCacheCallback)

        try:
            rv = options.MainHandler.runCommand(self, thisCommand,
                                                cfg, argSet, args,
                                                callback=callback,
                                                repos=client.getRepos(),
                                                profile=profile)
        finally:
            if profile == 'lsprof':
                prof.disable()
                prof.dump_stats('cvc.lsprof')
                prof.print_stats()
            elif profile:
                prof.stop()

        if log.errorOccurred():
            sys.exit(2)
        return rv
Example #8
0
def getSysRootPath(flavor):
    # FIXME: if we wanted to get this exactly right, we'd have to load the 
    # macros from /etc/macros and use those values for sysroot. 
    # Best would be to do that at the same time as we load the recipe itself
    # and store it w/ the trove, because otherwise it's misleading.
    if hasTarget(flavor):
        flavor = getSysRootFlavor(flavor)
    use.setBuildFlagsFromFlavor(None, flavor, error=False)
    target = '%s-unknown-linux' % use.Arch._getMacro('targetarch')
    return '/opt/cross-target-%s/sys-root' % target
Example #9
0
def getSysRootPath(flavor):
    # FIXME: if we wanted to get this exactly right, we'd have to load the
    # macros from /etc/macros and use those values for sysroot.
    # Best would be to do that at the same time as we load the recipe itself
    # and store it w/ the trove, because otherwise it's misleading.
    if hasTarget(flavor):
        flavor = getSysRootFlavor(flavor)
    use.setBuildFlagsFromFlavor(None, flavor, error=False)
    target = '%s-unknown-linux' % use.Arch._getMacro('targetarch')
    return '/opt/cross-target-%s/sys-root' % target
Example #10
0
 def refresh(self, targetDir=None):
     """
     Refresh the checked-out sources for a conary source package.
     @param targetDir: checkout directory to refresh
     @type targetDir: string
     """
     cfg = self.getConaryConfig()
     self._initializeFlavors()
     use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, False)
     return checkin.refresh(self._getRepositoryClient(), cfg,
                            dirName=targetDir)
Example #11
0
 def commit(self, targetDir, message):
     cfg = self.getConaryConfig()
     self._initializeFlavors()
     use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, False)
     cwd = os.getcwd()
     try:
         os.chdir(targetDir)
         checkin.commit(self._getRepositoryClient(), cfg, message=message)
     except conaryerrors.CvcError, e:
         tb = sys.exc_info()[2]
         raise errors.RbuildError, str(e), tb
Example #12
0
    def testMacroOverrides(self):
        self.addTestPkg(1)
        repos = self.openRepository()
        loader = loadrecipe.recipeLoaderFromSourceComponent('test1:source', 
                                                           self.cfg, repos)[0]
        recipeClass = loader.getRecipe()
        self.overrideBuildFlavor('is:x86(!i686,!i586,i486)')
        use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

        dummy = recipeClass(self.cfg, None, None, {})
        assert(dummy.macros.dummyMacro == 'right')
Example #13
0
 def commit(self, targetDir, message):
     cfg = self.getConaryConfig()
     self._initializeFlavors()
     use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, False)
     cwd = os.getcwd()
     try:
         os.chdir(targetDir)
         checkin.commit(self._getRepositoryClient(), cfg, message=message)
     except conaryerrors.CvcError, e:
         tb = sys.exc_info()[2]
         raise errors.RbuildError, str(e), tb
Example #14
0
 def refresh(self, targetDir=None):
     """
     Refresh the checked-out sources for a conary source package.
     @param targetDir: checkout directory to refresh
     @type targetDir: string
     """
     cfg = self.getConaryConfig()
     self._initializeFlavors()
     use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, False)
     return checkin.refresh(self._getRepositoryClient(), cfg,
                            dirName=targetDir)
Example #15
0
    def testMacroOverrides(self):
        self.overrideBuildFlavor('is:x86(!i686,!i586,i486)')
        use.setBuildFlagsFromFlavor('group-test', self.cfg.buildFlavor)

        recipeClass = self._loadRecipe()
        dummy = recipeClass(None,
                            self.cfg,
                            None,
                            None,
                            None,
                            lightInstance=True)
        self.assertEqual(dummy.macros.dummyMacro, 'right')
Example #16
0
def loadRecipeClass(
    repos,
    name,
    version,
    flavor,
    trv=None,
    ignoreInstalled=True,
    root=None,
    loadInstalledSource=None,
    overrides=None,
    buildLabel=None,
    cfg=None,
):
    if trv is None:
        trv = repos.getTrove(name, version, deps.parseFlavor(""), withFiles=True)

    if cfg is None:
        cfg = conarycfg.ConaryConfiguration(False)
    else:
        cfg = copy.deepcopy(cfg)
    cfg.initializeFlavors()
    if root:
        cfg.root = root
    branch = version.branch()
    label = version.branch().label()
    cfg.buildLabel = label
    cfg.buildFlavor = flavor
    name = name.split(":")[0]

    use.LocalFlags._clear()
    use.setBuildFlagsFromFlavor(name, flavor, error=False)
    use.resetUsed()
    use.track(True)

    loader = RecipeLoaderFromSourceTrove(
        trv,
        repos,
        cfg,
        name + ":source",
        branch,
        ignoreInstalled=ignoreInstalled,
        db=loadInstalledSource,
        overrides=overrides,
        buildFlavor=flavor,
    )
    recipeClass = loader.getRecipe()
    recipeClass._trove = trv

    use.track(False)
    localFlags = flavorutil.getLocalFlags()
    usedFlags = use.getUsed()
    use.LocalFlags._clear()
    return loader, recipeClass, localFlags, usedFlags
Example #17
0
def loadRecipeClass(repos,
                    name,
                    version,
                    flavor,
                    trv=None,
                    ignoreInstalled=True,
                    root=None,
                    loadInstalledSource=None,
                    overrides=None,
                    buildLabel=None,
                    cfg=None):
    if trv is None:
        trv = repos.getTrove(name,
                             version,
                             deps.parseFlavor(''),
                             withFiles=True)

    if cfg is None:
        cfg = conarycfg.ConaryConfiguration(False)
    else:
        cfg = copy.deepcopy(cfg)
    cfg.initializeFlavors()
    if root:
        cfg.root = root
    branch = version.branch()
    label = version.branch().label()
    cfg.buildLabel = label
    cfg.buildFlavor = flavor
    name = name.split(':')[0]

    use.LocalFlags._clear()
    use.setBuildFlagsFromFlavor(name, flavor, error=False)
    use.resetUsed()
    use.track(True)

    loader = RecipeLoaderFromSourceTrove(trv,
                                         repos,
                                         cfg,
                                         name + ':source',
                                         branch,
                                         ignoreInstalled=ignoreInstalled,
                                         db=loadInstalledSource,
                                         overrides=overrides,
                                         buildFlavor=flavor)
    recipeClass = loader.getRecipe()
    recipeClass._trove = trv

    use.track(False)
    localFlags = flavorutil.getLocalFlags()
    usedFlags = use.getUsed()
    use.LocalFlags._clear()
    return loader, recipeClass, localFlags, usedFlags
Example #18
0
    def testPackageFlags(self):
        assert(not use.PackageFlags.kernel.pae)
        self.assertRaises(RuntimeError, setattr,
                          use.PackageFlags.kernel, 'pae', True)
        self.assertRaises(RuntimeError, setattr,
                          use.PackageFlags, 'foo', True)
        self.assertRaises(RuntimeError, bool, use.PackageFlags)

        assert(not use.PackageFlags.kernel.pae)
        use.setBuildFlagsFromFlavor(None, 
                                    parseFlavor('kernel.pae'), error=False)
        assert(bool(use.PackageFlags.kernel.pae))
        use.clearFlags()
        use.setBuildFlagsFromFlavor(None, 
                                    parseFlavor('!kernel.pae'), error=False)
        assert(not bool(use.PackageFlags.kernel.pae))
        assert(str(use.PackageFlags.kernel.pae) == 'PackageFlags.kernel.pae: False')
Example #19
0
    def writeControl(self):
        pkgName = self._getPkgName()
        log.info('writing control file for %s' % pkgName)

        recipeDir = self._helper._checkout(pkgName)
        control = self.getControl()
        if not control and os.path.exists(os.path.join(recipeDir, 'control')):
            self._helper._removeFile(recipeDir, 'control')
        if control:
            fd = open(os.path.join(recipeDir, 'control'), 'w')
            fd.write(control)
            fd.close()
            self._helper._addFile(recipeDir, 'control')

        use.setBuildFlagsFromFlavor(pkgName, self._helper._ccfg.buildFlavor,
                                    error=False)

        self._helper._commit(recipeDir, 'add/update control file')
Example #20
0
    def writeControl(self):
        pkgName = self._getPkgName()
        log.info('writing control file for %s' % pkgName)

        recipeDir = self._helper._checkout(pkgName)
        control = self.getControl()
        if not control and os.path.exists(os.path.join(recipeDir, 'control')):
            self._helper._removeFile(recipeDir, 'control')
        if control:
            fd = open(os.path.join(recipeDir, 'control'), 'w')
            fd.write(control)
            fd.close()
            self._helper._addFile(recipeDir, 'control')

        use.setBuildFlagsFromFlavor(pkgName,
                                    self._helper._ccfg.buildFlavor,
                                    error=False)

        self._helper._commit(recipeDir, 'add/update control file')
Example #21
0
    def testPackageFlags(self):
        assert (not use.PackageFlags.kernel.pae)
        self.assertRaises(RuntimeError, setattr, use.PackageFlags.kernel,
                          'pae', True)
        self.assertRaises(RuntimeError, setattr, use.PackageFlags, 'foo', True)
        self.assertRaises(RuntimeError, bool, use.PackageFlags)

        assert (not use.PackageFlags.kernel.pae)
        use.setBuildFlagsFromFlavor(None,
                                    parseFlavor('kernel.pae'),
                                    error=False)
        assert (bool(use.PackageFlags.kernel.pae))
        use.clearFlags()
        use.setBuildFlagsFromFlavor(None,
                                    parseFlavor('!kernel.pae'),
                                    error=False)
        assert (not bool(use.PackageFlags.kernel.pae))
        assert (str(
            use.PackageFlags.kernel.pae) == 'PackageFlags.kernel.pae: False')
Example #22
0
    def testBasicMacros(self):
        oldPath = os.environ['PATH']
        try:
            self.addTestPkg(1)
            repos = self.openRepository()
            loader = loadrecipe.recipeLoaderFromSourceComponent('test1:source', 
                                                               self.cfg, repos)[0]
            recipeClass = loader.getRecipe()
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

            # This should override the value from extraMacros
            self.cfg.configLine('macros thing value')
            # And this should override the default value
            self.cfg.configLine('macros bindir /binaries')

            recipeObj = recipeClass(self.cfg, None, None,
                extraMacros={'thing': 'wrong'})
            self.assertEqual(recipeObj.macros.name, 'test1')
            self.assertEqual(recipeObj.macros.version, '1.0')
            self.assertEqual(recipeObj.macros.bindir, '/binaries')
        finally:
            os.environ['PATH'] = oldPath
Example #23
0
    def testCrossCompileSetupMacrosOverride(self):

        macroOverrides = {'crossdir' : 'foo'}
        oldPath = os.environ['PATH']
        try:
            self.addTestPkg(1)
            repos = self.openRepository()
            loader = loadrecipe.recipeLoaderFromSourceComponent('test1:source', 
                                                               self.cfg, repos)[0]
            recipeClass = loader.getRecipe()
            self.overrideBuildFlavor('is:x86(!i686,!i586,i486)')
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

            # cross compiling something for x86_64
            cross1 = recipeClass(self.cfg, None, None, macroOverrides, 
                                 (None, 'x86_64', False))

            assert(cross1.macros.target == 'x86_64-unknown-linux')
            assert(cross1.macros.host == 'x86_64-unknown-linux')
            assert(cross1.macros.build == 'i486-unknown-linux')
            assert(use.Arch.x86_64)
            assert(cross1.macros.crossprefix == '/opt/foo')
        finally:
            os.environ['PATH'] = oldPath
Example #24
0
 def testSetBuildFlagsFromFlavor(self):
     Flavor = deps.parseFlavor
     use.setBuildFlagsFromFlavor(None, Flavor('is: ppc'))
     assert(use.Arch.ppc)
     self.assertRaises(RuntimeError, use.setBuildFlagsFromFlavor,
         None, Flavor('is: x86 ppc'))
     use.setBuildFlagsFromFlavor(None, Flavor('is: x86'))
     assert(use.Arch.x86)
     assert(not use.Arch.ppc)
     self.assertRaises(RuntimeError, use.setBuildFlagsFromFlavor, None, Flavor('is: ppc x86_64'))
     self.assertRaises(AttributeError, use.setBuildFlagsFromFlavor,
                       None, 'fjdkf')
     self.logFilter.add()
     use.setBuildFlagsFromFlavor(None, Flavor('fjdkf,!ssl'), error=False,
                                  warn=True)
     self.logFilter.compare('warning: ignoring unknown Use flag fjdkf')
     assert(not use.Use.ssl)
     use.setBuildFlagsFromFlavor(None, Flavor('ssl'), error=False)
Example #25
0
 def testSetBuildFlagsFromFlavor(self):
     Flavor = deps.parseFlavor
     use.setBuildFlagsFromFlavor(None, Flavor('is: ppc'))
     assert (use.Arch.ppc)
     self.assertRaises(RuntimeError, use.setBuildFlagsFromFlavor, None,
                       Flavor('is: x86 ppc'))
     use.setBuildFlagsFromFlavor(None, Flavor('is: x86'))
     assert (use.Arch.x86)
     assert (not use.Arch.ppc)
     self.assertRaises(RuntimeError, use.setBuildFlagsFromFlavor, None,
                       Flavor('is: ppc x86_64'))
     self.assertRaises(AttributeError, use.setBuildFlagsFromFlavor, None,
                       'fjdkf')
     self.logFilter.add()
     use.setBuildFlagsFromFlavor(None,
                                 Flavor('fjdkf,!ssl'),
                                 error=False,
                                 warn=True)
     self.logFilter.compare('warning: ignoring unknown Use flag fjdkf')
     assert (not use.Use.ssl)
     use.setBuildFlagsFromFlavor(None, Flavor('ssl'), error=False)
Example #26
0
 def testMultilib(self):
     depSet = deps.DependencySet()
     depSet.addDeps(deps.InstructionSetDependency, arch.flags_x86_64()[0])
     use.setBuildFlagsFromFlavor(None, depSet)
     self.assertTrue(use.Arch.x86_64)
     self.assertFalse(use.Arch.x86)
Example #27
0
    try:
        # get the correct environment variables from this root
        # some packages depend on environment variables e.g. $QTDIR that
        # are set by other packages.
        setupEnvironment()

        # now override flags set in flavor
        # don't need to reset this flavor ever, because
        # we are in a fork
        flavorutil.setLocalFlags(localFlags)
        packageName = name.split(':')[0]
        # this shouldn't matter for group recipes as it will get overridden
        # by the behavior in cookGroupObject.  But it matters for some other
        # recipe types.  That should be fixed and all that code should be
        # moved inside cookObject so I could get rid of this.
        use.setBuildFlagsFromFlavor(packageName, cfg.buildFlavor, error=False)
        use.resetUsed()
        use.setUsed(usedFlags)

        # we don't want to sign packages here, if necessary, we can sign
        # them at a higher level.
        cfg.signatureKeyMap = {}
        cfg.signatureKey = None
        crossCompile = flavorutil.getCrossCompile(cfg.buildFlavor)

        # add extra buildreqs manually added for this trove
        # by the builder.  Only add them if the recipe is of the
        # right type, and the cfg file we're passed in understands them
        # (it might be a simple conary cfg file).
        if (hasattr(recipeClasses[0], 'buildRequires')
                and hasattr(cfg, 'defaultBuildReqs')):
Example #28
0
    try:
        # get the correct environment variables from this root
        # some packages depend on environment variables e.g. $QTDIR that 
        # are set by other packages.  
        setupEnvironment()

        # now override flags set in flavor
        # don't need to reset this flavor ever, because
        # we are in a fork
        flavorutil.setLocalFlags(localFlags)
        packageName = name.split(':')[0]
        # this shouldn't matter for group recipes as it will get overridden
        # by the behavior in cookGroupObject.  But it matters for some other
        # recipe types.  That should be fixed and all that code should be
        # moved inside cookObject so I could get rid of this.
        use.setBuildFlagsFromFlavor(packageName, cfg.buildFlavor, error=False)
        use.resetUsed()
        use.setUsed(usedFlags)


        # we don't want to sign packages here, if necessary, we can sign
        # them at a higher level.
        cfg.signatureKeyMap = {}
        cfg.signatureKey = None
        crossCompile = flavorutil.getCrossCompile(cfg.buildFlavor)

        # add extra buildreqs manually added for this trove
        # by the builder.  Only add them if the recipe is of the
        # right type, and the cfg file we're passed in understands them
        # (it might be a simple conary cfg file).
        if (hasattr(recipeClasses[0], 'buildRequires')
Example #29
0
 def _setArchFlags(flavor):
     # given an flavor, make use.Arch match that flavor.
     for flag in use.Arch._iterAll():
         flag._set(False)
     use.setBuildFlagsFromFlavor(self.name, flavor, error=False,
                                 useCross=False)
Example #30
0
 def testTargetFlavor(self):
     use.setBuildFlagsFromFlavor(None, self.cfg.buildFlavor, error=False)
     targetFlavor = str(use.createFlavor(None, use.Arch._iterAll(), targetDep=True))
     assert(targetFlavor)
     flavor = str(use.createFlavor(None, use.Arch._iterAll(), targetDep=False))
     assert(targetFlavor.replace('target', 'is') == flavor)
Example #31
0
 def testMultilib(self):
     depSet = deps.DependencySet()
     depSet.addDeps(deps.InstructionSetDependency, arch.flags_x86_64()[0])
     use.setBuildFlagsFromFlavor(None, depSet)
     self.assertTrue(use.Arch.x86_64)
     self.assertFalse(use.Arch.x86)
Example #32
0
def getBuildJob(buildConfig, conaryclient, troveSpecList,
                message=None, recurseGroups=BUILD_RECURSE_GROUPS_NONE, 
                configDict=None, oldTroveDict=None, updateSpecs=None,
                rebuild=False):
    trovesByContext = {}

    for troveSpec in list(troveSpecList):
        if not isinstance(troveSpec, tuple):
            troveSpec = cmdutil.parseTroveSpec(troveSpec)

        if len(troveSpec) == 3:
            context = ''
        else:
            context = troveSpec[3]
            troveSpec = troveSpec[:3]

        if troveSpec[2] is None:
            troveSpec = (troveSpec[0], troveSpec[1], deps.parseFlavor(''))
        trovesByContext.setdefault(context, []).append(troveSpec)

    job = buildjob.BuildJob()

    # don't store all the contexts with this job - they're useless past the
    # initialization step.
    if configDict:
        mainConfig = configDict['']
        job.setMainConfig(configDict[''])
    else:
        cfg = copy.deepcopy(buildConfig)
        cfg.dropContexts()
        mainConfig = cfg
    mainConfig.recurseGroups = int(recurseGroups)
    job.setMainConfig(mainConfig)

    baseMatchRules = mainConfig.matchTroveRule
    for contextStr, troveSpecList in trovesByContext.iteritems():
        contextBaseMatchRules = baseMatchRules
        if configDict and contextStr in configDict:
            cfg = configDict[contextStr]
        elif contextStr:
            # making this a copy is critical
            cfg = copy.deepcopy(buildConfig)
            for context in contextStr.split(','):
                cfg.setContext(context)
            cfg.dropContexts()
        else:
            # don't bother with baseMatchRules in the base config.
            contextBaseMatchRules = []
            cfg = copy.deepcopy(buildConfig)
            cfg.dropContexts()
            contextStr = ''
            job.setMainConfig(cfg)
        cfg.initializeFlavors()
        use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False)
        if not cfg.buildLabel and cfg.installLabelPath:
            cfg.buildLabel = cfg.installLabelPath[0]
        troveSpecList = list(set(troveSpecList))
        troveList = getTrovesToBuild(cfg, conaryclient, troveSpecList,
                         message=None,
                         recurseGroups=recurseGroups,
                         matchSpecs=contextBaseMatchRules + cfg.matchTroveRule,
                         reposName=mainConfig.reposName,
                         updateSpecs=updateSpecs)
        if updateSpecs and oldTroveDict and contextStr in oldTroveDict:
            troveList = _matchUpdateRestrictions(mainConfig.reposName,
                                                 oldTroveDict[contextStr],
                                                 troveList,
                                                 updateSpecs)
        if rebuild:
            prebuiltBinaries = _findLatestBinariesForTroves(conaryclient,
                                                        mainConfig.reposName,
                                                        troveList)
            if not job.getMainConfig().prebuiltBinaries:
                job.getMainConfig().prebuiltBinaries = prebuiltBinaries
            else:
                job.getMainConfig().prebuiltBinaries.extend(prebuiltBinaries)
        if mainConfig.prepOnly:
            buildType = buildtrove.TROVE_BUILD_TYPE_PREP
        else:
            buildType = buildtrove.TROVE_BUILD_TYPE_NORMAL

        for name, version, flavor in troveList:
            if flavor is None:
                flavor = deps.parseFlavor('')
            bt = buildtrove.BuildTrove(None, name, version, flavor,
                                       context=contextStr,
                                       buildType=buildType)
            job.addTrove(name, version, flavor, contextStr, bt)
            job.setTroveConfig(bt, cfg)
    return job
Example #33
0
    def testCrossCompileSetup(self):
        siteConfigPath = os.path.abspath(resources.get_archive('site'))
        def _checkSite(macros, *paths):
            self.assertEquals(macros.env_siteconfig,
                          ' '.join([siteConfigPath + '/' + x for x in paths]))

        self.cfg.siteConfigPath = [ siteConfigPath]
        oldPath = os.environ['PATH']
        try:
            self.addTestPkg(1)
            repos = self.openRepository()
            if 'CONFIG_SITE' in os.environ: del os.environ['CONFIG_SITE']
            loader = loadrecipe.recipeLoaderFromSourceComponent('test1:source', 
                                                               self.cfg, repos)[0]
            recipeClass = loader.getRecipe()
            self.overrideBuildFlavor('is:x86(!i686,!i586,i486)')
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

            nocross = recipeClass(self.cfg, None, None, {})
            assert(nocross.macros.target == 'i486-unknown-linux')
            assert(nocross.macros.host == 'i486-unknown-linux')
            assert(nocross.macros.build == 'i486-unknown-linux')
            assert(not nocross.isCrossCompiling())
            assert(not nocross.isCrossCompileTool())
            assert(not nocross.needsCrossFlags())

            if 'CONFIG_SITE' in os.environ: del os.environ['CONFIG_SITE']
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

            try:
                invalid = recipeClass(self.cfg, None, None, {}, (None, '((', False))
            except errors.CookError:
                pass

            # cross compiling something for x86_64
            cross1 = recipeClass(self.cfg, None, None, {}, (None, 'x86_64', False))

            assert(cross1.macros.target == 'x86_64-unknown-linux')
            assert(cross1.macros.host == 'x86_64-unknown-linux')
            assert(cross1.macros.build == 'i486-unknown-linux')
            assert(cross1.hostmacros.lib == 'lib64')
            assert(cross1.targetmacros.lib == 'lib64')
            assert(cross1.buildmacros.lib == 'lib')
            assert(cross1.macros.lib == 'lib64')
            assert(cross1.isCrossCompiling())
            assert(not cross1.isCrossCompileTool())
            assert(cross1.needsCrossFlags())
            assert(use.Arch.x86_64)
            _checkSite(cross1.macros, 'x86_64', 'linux')
            _checkSite(cross1.buildmacros, 'x86', 'linux')
            _checkSite(cross1.hostmacros, 'x86_64', 'linux')

            if 'CONFIG_SITE' in os.environ: del os.environ['CONFIG_SITE']
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)

            # building a cross compiling tool for i686
            cross2 = recipeClass(self.cfg, None, None, {}, (None, 'x86(i686)', 
                                                                        True))
            assert(cross2.macros.target == 'i686-unknown-linux')
            assert(cross2.macros.host == 'i486-unknown-linux')
            # note the added _build here to differentiate host from build
            assert(cross2.macros.build == 'i486-unknown_build-linux')
            assert(use.Arch.x86.i686)

            # building a cross-compiler on i386 to run on x86_64 to compile
            # for ppc

            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)
            if 'CONFIG_SITE' in os.environ: del os.environ['CONFIG_SITE']
            cross3 = recipeClass(self.cfg, None, None, {}, ('x86_64', 'ppc',
                                                                        True))
            assert(cross3.macros.target == 'powerpc-unknown-linux')
            assert(cross3.macros.host == 'x86_64-unknown-linux')
            assert(cross3.macros.build == 'i486-unknown-linux')
            assert(cross3.macros.cc == 'i486-unknown-linux-gcc')
            assert(cross3.macros.cxx == 'i486-unknown-linux-g++')
            # this is a cross-tool, so we're building for the system machine
            # so buildcc == cc
            assert(cross3.macros.buildcc == 'i486-unknown-linux-gcc')
            assert(cross3.macros.buildcxx == 'i486-unknown-linux-g++')
            assert(cross3.macros.lib == 'lib')
            assert(cross3.hostmacros.lib == 'lib64')
            assert(cross3.targetmacros.lib == 'lib')
            assert(cross3.buildmacros.lib == 'lib')
            assert(use.Arch.x86_64)

            assert(not cross3.isCrossCompiling())
            assert(cross3.isCrossCompileTool())
            assert(cross3.needsCrossFlags())

            # When creating a cross compiler for a ppc system
            # on an x86_64 box, configure should return results for the x86_64
            # box, not the target arch.
            _checkSite(cross3.macros, 'x86_64', 'linux')
            _checkSite(cross3.buildmacros, 'x86', 'linux')
            _checkSite(cross3.hostmacros, 'x86_64', 'linux')

            # cross compiling for i486 on i486
            # buildcc should have /usr/bin/ in front
            use.setBuildFlagsFromFlavor('test1', self.cfg.buildFlavor)
            if 'CONFIG_SITE' in os.environ: del os.environ['CONFIG_SITE']
            cross4 = recipeClass(self.cfg, None, None, {}, (None, 'x86(i486)', False))
            assert(cross4.macros.target == 'i486-unknown-linux')
            assert(cross4.macros.host == 'i486-unknown-linux')
            assert(cross4.macros.build == 'i486-unknown_build-linux')
            assert(cross4.macros.buildcc == '/usr/bin/i486-unknown-linux-gcc')
            assert(cross4.macros.buildcxx == '/usr/bin/i486-unknown-linux-g++')
            assert(cross4.macros.cc == 'i486-unknown-linux-gcc')
            assert(cross4.macros.cxx == 'i486-unknown-linux-g++')

        finally:
            os.environ['PATH'] = oldPath
Example #34
0
def getRecipeObj(
    repos,
    name,
    version,
    flavor,
    trv,
    loadInstalledSource=None,
    installLabelPath=None,
    loadRecipeSpecs=None,
    buildLabel=None,
    groupRecipeSource=None,
    cfg=None,
):
    if cfg:
        cfg = copy.deepcopy(cfg)
    else:
        cfg = conarycfg.ConaryConfiguration(False)
    cfg.initializeFlavors()
    branch = version.branch()
    if not buildLabel:
        buildLabel = version.branch().label()
    if not installLabelPath:
        cfg.installLabelPath = [buildLabel]
    else:
        cfg.installLabelPath = installLabelPath
    cfg.buildFlavor = flavor
    cfg.defaultBasePackages = []
    name = name.split(":")[0]
    use.LocalFlags._clear()
    assert flavorutil.getArch(flavor)
    use.setBuildFlagsFromFlavor(name, flavor, error=False)
    use.resetUsed()
    use.track(True)
    ignoreInstalled = not loadInstalledSource
    macros = {"buildlabel": buildLabel.asString(), "buildbranch": version.branch().asString()}
    cfg.lookaside = tempfile.mkdtemp()
    try:
        loader = RecipeLoaderFromSourceTrove(
            trv,
            repos,
            cfg,
            name + ":source",
            branch,
            ignoreInstalled=ignoreInstalled,
            db=loadInstalledSource,
            buildFlavor=flavor,
        )
        recipeClass = loader.getRecipe()
        recipeClass._trove = trv
        if recipe.isGroupRecipe(recipeClass):
            recipeObj = recipeClass(repos, cfg, buildLabel, flavor, None, extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif (
            recipe.isPackageRecipe(recipeClass)
            or recipe.isFactoryRecipe(recipeClass)
            or recipe.isCapsuleRecipe(recipeClass)
        ):
            if recipe.isFactoryRecipe(recipeClass):
                # This requires a specific capability in conary
                compat.ConaryVersion().requireFactoryRecipeGeneration()
                # Load the FactoryRecipe
                factoryClass = recipeClass
                loaded = cook.loadFactoryRecipe(factoryClass, cfg, repos, flavor)
                recipeClass = loaded.getRecipe()
            lcache = lookaside.RepositoryCache(repos)
            recipeObj = recipeClass(cfg, lcache, [], macros, lightInstance=True)
            recipeObj.sourceVersion = version
            recipeObj.populateLcache()
            if not recipeObj.needsCrossFlags():
                recipeObj.crossRequires = []
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif recipe.isInfoRecipe(recipeClass):
            recipeObj = recipeClass(cfg, None, None, macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isRedirectRecipe(recipeClass):
            binaryBranch = version.getBinaryVersion().branch()
            recipeObj = recipeClass(repos, cfg, binaryBranch, flavor)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isFileSetRecipe(recipeClass):
            recipeObj = recipeClass(repos, cfg, buildLabel, flavor, extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        else:
            raise RuntimeError, "Unknown class type %s for recipe %s" % (recipeClass, name)
    finally:
        util.rmtree(cfg.lookaside)
    return recipeObj, loader
Example #35
0
def getBuildJob(buildConfig, conaryclient, troveSpecList,
                message=None, recurseGroups=BUILD_RECURSE_GROUPS_NONE, 
                configDict=None, oldTroveDict=None, updateSpecs=None,
                rebuild=False):
    trovesByContext = {}

    for troveSpec in list(troveSpecList):
        if not isinstance(troveSpec, tuple):
            troveSpec = cmdutil.parseTroveSpec(troveSpec)

        if len(troveSpec) == 3:
            context = ''
        else:
            context = troveSpec[3]
            troveSpec = troveSpec[:3]

        if troveSpec[2] is None:
            troveSpec = (troveSpec[0], troveSpec[1], deps.parseFlavor(''))
        trovesByContext.setdefault(context, []).append(troveSpec)

    job = buildjob.BuildJob()

    # don't store all the contexts with this job - they're useless past the
    # initialization step.
    if configDict:
        mainConfig = configDict['']
        job.setMainConfig(configDict[''])
    else:
        cfg = copy.deepcopy(buildConfig)
        cfg.dropContexts()
        mainConfig = cfg
    mainConfig.recurseGroups = int(recurseGroups)
    job.setMainConfig(mainConfig)

    baseMatchRules = mainConfig.matchTroveRule
    for contextStr, troveSpecList in trovesByContext.iteritems():
        contextBaseMatchRules = baseMatchRules
        if configDict and contextStr in configDict:
            cfg = configDict[contextStr]
        elif contextStr:
            # making this a copy is critical
            cfg = copy.deepcopy(buildConfig)
            for context in contextStr.split(','):
                cfg.setContext(context)
            cfg.dropContexts()
        else:
            # don't bother with baseMatchRules in the base config.
            contextBaseMatchRules = []
            cfg = copy.deepcopy(buildConfig)
            cfg.dropContexts()
            contextStr = ''
            job.setMainConfig(cfg)
        cfg.initializeFlavors()
        use.setBuildFlagsFromFlavor(None, cfg.buildFlavor, error=False)
        if not cfg.buildLabel and cfg.installLabelPath:
            cfg.buildLabel = cfg.installLabelPath[0]
        troveSpecList = list(set(troveSpecList))
        troveList = getTrovesToBuild(cfg, conaryclient, troveSpecList,
                         message=None,
                         recurseGroups=recurseGroups,
                         matchSpecs=contextBaseMatchRules + cfg.matchTroveRule,
                         reposName=mainConfig.reposName,
                         updateSpecs=updateSpecs)
        if updateSpecs and oldTroveDict and contextStr in oldTroveDict:
            troveList = _matchUpdateRestrictions(mainConfig.reposName,
                                                 oldTroveDict[contextStr],
                                                 troveList,
                                                 updateSpecs)
        if rebuild:
            prebuiltBinaries = _findLatestBinariesForTroves(conaryclient,
                                                        mainConfig.reposName,
                                                        troveList)
            if not job.getMainConfig().prebuiltBinaries:
                job.getMainConfig().prebuiltBinaries = prebuiltBinaries
            else:
                job.getMainConfig().prebuiltBinaries.extend(prebuiltBinaries)
        if mainConfig.prepOnly:
            buildType = buildtrove.TROVE_BUILD_TYPE_PREP
        else:
            buildType = buildtrove.TROVE_BUILD_TYPE_NORMAL

        for name, version, flavor in troveList:
            if flavor is None:
                flavor = deps.parseFlavor('')
            bt = buildtrove.BuildTrove(None, name, version, flavor,
                                       context=contextStr,
                                       buildType=buildType)
            job.addTrove(name, version, flavor, contextStr, bt)
            job.setTroveConfig(bt, cfg)
    return job
Example #36
0
def getRecipeObj(repos,
                 name,
                 version,
                 flavor,
                 trv,
                 loadInstalledSource=None,
                 installLabelPath=None,
                 loadRecipeSpecs=None,
                 buildLabel=None,
                 groupRecipeSource=None,
                 cfg=None):
    if cfg:
        cfg = copy.deepcopy(cfg)
    else:
        cfg = conarycfg.ConaryConfiguration(False)
    cfg.initializeFlavors()
    branch = version.branch()
    if not buildLabel:
        buildLabel = version.branch().label()
    if not installLabelPath:
        cfg.installLabelPath = [buildLabel]
    else:
        cfg.installLabelPath = installLabelPath
    cfg.buildFlavor = flavor
    cfg.defaultBasePackages = []
    name = name.split(':')[0]
    use.LocalFlags._clear()
    assert (flavorutil.getArch(flavor))
    use.setBuildFlagsFromFlavor(name, flavor, error=False)
    use.resetUsed()
    use.track(True)
    ignoreInstalled = not loadInstalledSource
    macros = {
        'buildlabel': buildLabel.asString(),
        'buildbranch': version.branch().asString()
    }
    cfg.lookaside = tempfile.mkdtemp()
    try:
        loader = RecipeLoaderFromSourceTrove(trv,
                                             repos,
                                             cfg,
                                             name + ':source',
                                             branch,
                                             ignoreInstalled=ignoreInstalled,
                                             db=loadInstalledSource,
                                             buildFlavor=flavor)
        recipeClass = loader.getRecipe()
        recipeClass._trove = trv
        if recipe.isGroupRecipe(recipeClass):
            recipeObj = recipeClass(repos,
                                    cfg,
                                    buildLabel,
                                    flavor,
                                    None,
                                    extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif (recipe.isPackageRecipe(recipeClass)
              or recipe.isFactoryRecipe(recipeClass)
              or recipe.isCapsuleRecipe(recipeClass)):
            if recipe.isFactoryRecipe(recipeClass):
                #This requires a specific capability in conary
                compat.ConaryVersion().requireFactoryRecipeGeneration()
                #Load the FactoryRecipe
                factoryClass = recipeClass
                loaded = cook.loadFactoryRecipe(factoryClass, cfg, repos,
                                                flavor)
                recipeClass = loaded.getRecipe()
            lcache = lookaside.RepositoryCache(repos)
            recipeObj = recipeClass(cfg,
                                    lcache, [],
                                    macros,
                                    lightInstance=True)
            recipeObj.sourceVersion = version
            recipeObj.populateLcache()
            if not recipeObj.needsCrossFlags():
                recipeObj.crossRequires = []
            recipeObj.loadPolicy()
            recipeObj.setup()
        elif recipe.isInfoRecipe(recipeClass):
            recipeObj = recipeClass(cfg, None, None, macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isRedirectRecipe(recipeClass):
            binaryBranch = version.getBinaryVersion().branch()
            recipeObj = recipeClass(repos, cfg, binaryBranch, flavor)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        elif recipe.isFileSetRecipe(recipeClass):
            recipeObj = recipeClass(repos,
                                    cfg,
                                    buildLabel,
                                    flavor,
                                    extraMacros=macros)
            recipeObj.sourceVersion = version
            recipeObj.setup()
        else:
            raise RuntimeError, 'Unknown class type %s for recipe %s' % (
                recipeClass, name)
    finally:
        util.rmtree(cfg.lookaside)
    return recipeObj, loader