Ejemplo n.º 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
Ejemplo n.º 2
0
def _createVersion(package, helper, version):
    '''
    Pick a new version for package I{package} using I{version} as the
    new upstream version.
    '''
    newBranch = Branch([helper.plan.getTargetLabel()])
    newRevision = Revision('%s-0' % version)
    newVersion = newBranch.createVersion(newRevision)
    newVersion.incrementSourceCount()
    return newVersion
Ejemplo n.º 3
0
    def testCompareVersionSequence(self):
        # CNY-2020
        v1 = VersionSequence([Label('foo@bar:baz')])
        v2 = VersionSequence([Label('foo@bar:beep')])
        self.assertEqual(v1, v1)
        self.assertTrue(cmp(v1, v2) in [-1, 1])
        self.assertTrue(cmp(v2, v1) in [-1, 1])
        self.assertEqual(cmp(v1, v2) + cmp(v2, v1), 0)

        # This should work, even if we return NotImplemented
        v3 = VersionSequence([Revision('1-1-1')])
        self.assertTrue(cmp(v1, v3) in [-1, 1])
        self.assertTrue(cmp(v3, v1) in [-1, 1])
        self.assertEqual(cmp(v1, v3) + cmp(v3, v1), 0)

        # Compare with a random string, and make sure it's stable too
        v3 = 'abc'
        self.assertTrue(cmp(v1, v3) in [-1, 1])
        self.assertTrue(cmp(v3, v1) in [-1, 1])
        self.assertEqual(cmp(v1, v3) + cmp(v3, v1), 0)
Ejemplo n.º 4
0
    def testSerialNumber(self):
        assert not SerialNumber("0")
        assert SerialNumber("1")

    def testRevision(self):
        try:
            Revision("-")
        except ParseError, e:
            assert str(e) == "bad release string: -"
        else:
            self.fail("ParseError expected")

        self.assertRaises(ParseError, Revision, "1-abc")
        self.assertRaises(ParseError, Revision, "1-3:4")

        v = Revision(".2a-3")
        assert v.getVersion() == ".2a"

        v = Revision("1.2a-3")
        assert v.getVersion() == "1.2a"

        self.assertRaises(AttributeError, v.__setattr__, "foo", 1)

        v2 = Revision("1.2a-3")
        assert v == v2
        assert v2 == v

        v2 = Revision("1.2a-2")
        assert not v == v2
        v2._incrementSourceCount(0)
        assert v == v2
Ejemplo n.º 5
0
    def testShadows(self):
        self.doTestVersion('/foo@spc:linux//shadow/1-1.2')
        self.doTestVersion('/foo@spc:linux//shadow/1-1-1.2')
        self.doTestVersion('/foo@spc:linux//shadow/1-1-1/branch//shadow2/1.1')
        self.doTestVersion('/foo@spc:linux//shadow/1-1-1/branch//shadow2/'
                           '/shadow3/1.1.1')

        self.assertRaises(ParseError, VersionFromString,
                          '/foo@spc:linux//shadow/1-1.2.3')
        self.assertRaises(ParseError, VersionFromString,
                          '/foo@spc:linux//shadow/1-1-1.2.3')
        self.assertRaises(ParseError, VersionFromString,
                          '/foo@spc:linux//shadow/1-1-1/branch/1.1')
        self.assertRaises(
            ParseError, VersionFromString,
            '/foo@spc:linux//shadow/1-1-1/branch//shadow2/1.1.1')
        self.assertRaises(
            ParseError, VersionFromString,
            '/foo@spc:linux//shadow/1-1-1/branch//shadow2/'
            '/shadow3/1.1.1.1')

        trunk = VersionFromString('/foo@spc:linux')
        assert (not trunk.isShadow())
        assert (not trunk.hasParentBranch())
        shadow = trunk.createShadow(Label('foo@spc:shadow'))
        assert (shadow.isShadow())
        assert (shadow.asString() == '/foo@spc:linux//shadow')
        assert (shadow.hasParentBranch())
        assert (shadow.parentBranch() == trunk)
        version = shadow.createVersion(Revision('1.1-1'))
        assert (version.isShadow())
        assert (not version.isModifiedShadow())
        assert (version.asString() == '/foo@spc:linux//shadow/1.1-1')
        assert (
            version.canonicalVersion().asString() == '/foo@spc:linux/1.1-1')
        assert (version.shadowLength() == 1)
        newVer = version.createShadow(Label("foo@spc:shadow2"))
        assert (newVer.asString() == '/foo@spc:linux//shadow//shadow2/1.1-1')
        assert (newVer.shadowLength() == 2)
        assert (newVer.parentVersion().asString() ==
                '/foo@spc:linux//shadow/1.1-1')
        assert (newVer.parentVersion().parentVersion().asString() ==
                '/foo@spc:linux/1.1-1')
        assert (newVer.canonicalVersion().asString() == '/foo@spc:linux/1.1-1')
        assert (newVer.isShadow())
        assert (not newVer.canonicalVersion().isShadow())
        assert (not newVer.canonicalVersion().isModifiedShadow())

        self.assertRaises(AssertionError, newVer.createBranch,
                          Label("foo@spc:shadow2"))
        self.assertRaises(VersionStringError, newVer.createShadow,
                          Label("foo@spc:shadow2"))

        branch = newVer.createBranch(Label("foo@spc:branch"))
        assert (branch.asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch')

        branchVer = newVer.createBranch(Label("foo@spc:branch"),
                                        withVerRel=True)
        assert (branchVer.asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch/1')
        assert (branchVer.shadowLength() == 0)
        assert (not branchVer.isShadow())

        newVer.incrementSourceCount()
        assert (
            newVer.asString() == '/foo@spc:linux//shadow//shadow2/1.1-1.0.1')
        assert (newVer.isModifiedShadow())
        branchVer.incrementSourceCount()
        assert (branchVer.asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch/2')
        assert (ThawVersion(branchVer.freeze()) == branchVer)

        newShadow = branchVer.createShadow(Label('foo@spc:shadow3'))
        assert (newShadow.asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch//shadow3/2')
        assert (newShadow.parentVersion().asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch/2')
        assert (newShadow.parentVersion().parentVersion().asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1')
        assert (newShadow.parentVersion().parentVersion().parentVersion().
                asString() == '/foo@spc:linux//shadow/1.1-1')
        assert (newShadow.parentVersion().parentVersion().parentVersion().
                parentVersion().asString() == '/foo@spc:linux/1.1-1')
        assert (newShadow.canonicalVersion().asString() ==
                '/foo@spc:linux//shadow//shadow2/1.1-1/branch/2')

        # shadowed binary has a parent version
        v = VersionFromString("/foo@spc:linux//shadow/1.2-1-1")
        assert (v.hasParentVersion())
        # shadowed source has a parent version
        v = VersionFromString("/foo@spc:linux//shadow/1.2-1")
        assert (v.hasParentVersion())
        # cooked shadowed binary doesn't has a parent version
        v = VersionFromString("/foo@spc:linux//shadow/1.2-1-0.1")
        assert (not v.hasParentVersion())

        v = VersionFromString("/foo@spc:linux//shadow/1.2-1").copy()
        assert (v.hasParentVersion())
        v.incrementBuildCount()
        assert (v.asString() == "/foo@spc:linux//shadow/1.2-1-0.1")
        assert (not v.hasParentVersion())
        v2 = v.createBranch(LocalLabel(), withVerRel=True)
        assert (v2.asString() ==
                "/foo@spc:linux//shadow/1.2-1-0.1/local@local:LOCAL/1")

        v = VersionFromString("/foo@spc:linux//shadow/1.2-1.1").copy()
        v.incrementBuildCount()
        assert (v.asString() == "/foo@spc:linux//shadow/1.2-1.1-1")
        assert (not v.hasParentVersion())

        # test to make sure versions don't count -0 having a build count
        v = VersionFromString('/a@b:c/4.1.25-18-0/d//e/22.3-1')
        assert (not v.hasParentVersion())

        # If you create a pristine shadow of a modified shadow,
        # that version should NOT be a modifiedShadow
        v = VersionFromString("/foo@spc:linux//shadow//shadow2/1.2-1.1")
        assert (v.isShadow() and not v.isModifiedShadow())
        v = v.parentVersion()
        assert (v.isShadow() and v.isModifiedShadow())

        v = VersionFromString("/foo@spc:linux//shadow//shadow2/1.2-1.0.1")
        assert (v.isShadow() and v.isModifiedShadow())
Ejemplo n.º 6
0
 def testRevision(self):
     try:
         Revision("-")
     except ParseError, e:
         assert (str(e) == "bad release string: -")
Ejemplo n.º 7
0
    def testVersion(self):
        self.assertRaises(ParseError, VersionFromString, '0.50.1')

        verStr = "/foo.com@spc:bar/1.000:1.2-3/bang.com@spc:branch/10.000:2.4-5"
        verStr2 = "/foo.com@spc:bar/1.000:1.2-3/bang.com@spc:branch/15.000:2.4-6"
        v = ThawVersion(verStr)
        assert (v.freeze() == verStr)
        assert (v.asString(VersionFromString("/foo.com@spc:bar")) ==
                "1.2-3/bang.com@spc:branch/2.4-5")
        assert (v.timeStamps() == [1, 10])
        v = v.copy()
        v.incrementSourceCount()
        assert (v.asString() == ThawVersion(verStr2).asString())
        assert (v.getHost() == 'bang.com')

        # test that cPickle works on a Version object (the changeset cache
        # database pickles versions)
        vpickled = cPickle.dumps(v)
        vunpickled = cPickle.loads(vpickled)
        assert (vunpickled.asString() == v.asString())

        v2 = VersionFromString(
            "/foo.com@spc:bar/1.2-3/bang.com@spc:branch/2.4-5",
            timeStamps=[1.000, 10.000])
        assert (v2.freeze() == verStr)
        assert ([x.asString() for x in v2.iterLabels()
                 ] == ['foo.com@spc:bar', 'bang.com@spc:branch'])

        last = v.trailingRevision()
        assert (last.asString() == "2.4-6")
        assert (not v.onLocalLabel())
        assert (not v.isInLocalNamespace())
        assert (not v.onEmergeLabel())
        assert (not v.onLocalCookLabel())
        assert (v2.getHost() == 'bang.com')

        assert (v.trailingLabel() == Label('bang.com@spc:branch'))

        branch = v.branch()
        assert (branch.getHost() == 'bang.com')
        strrep = branch.asString()
        assert (strrep == "/foo.com@spc:bar/1.2-3/bang.com@spc:branch")
        branch2 = VersionFromString(branch.asString())
        assert (branch == branch2)

        frozen = branch.freeze()
        branch2 = ThawVersion(frozen)
        assert (branch2 == branch)

        newVer = branch2.createVersion(Revision("1.1-2"))
        assert (newVer.asString() ==
                "/foo.com@spc:bar/1.2-3/bang.com@spc:branch/1.1-2")
        assert (not newVer.onLocalLabel())
        assert (not newVer.isInLocalNamespace())
        assert (not newVer.onEmergeLabel())
        assert (not newVer.onLocalCookLabel())
        assert (not newVer.isOnLocalHost())

        assert (newVer.canonicalVersion() == newVer)
        assert (v.hasParentVersion())
        parent = v.parentVersion()
        assert (not parent.hasParentVersion())
        assert (parent.asString() == "/foo.com@spc:bar/1.2-3")

        # check emerge label
        emerge = parent.createBranch(EmergeLabel(), withVerRel=1)
        assert (emerge.getHost() == 'local')
        assert (
            emerge.asString() == "/foo.com@spc:bar/1.2-3/local@local:EMERGE/3")
        assert (not emerge.onLocalLabel())
        assert (emerge.onEmergeLabel())
        assert (not emerge.onRollbackLabel())
        assert (not emerge.onLocalCookLabel())
        assert (emerge.isOnLocalHost())
        assert (emerge.isInLocalNamespace())

        # check local cook label
        cook = parent.createBranch(CookLabel(), withVerRel=1)
        assert (cook.asString() == "/foo.com@spc:bar/1.2-3/local@local:COOK/3")
        assert (not cook.onLocalLabel())
        assert (not cook.onEmergeLabel())
        assert (not cook.onRollbackLabel())
        assert (cook.onLocalCookLabel())
        assert (cook.isOnLocalHost())
        assert (cook.isInLocalNamespace())

        # check local rollback label
        branch2 = parent.createBranch(RollbackLabel(), withVerRel=1)
        assert (branch2.asString() ==
                "/foo.com@spc:bar/1.2-3/local@local:ROLLBACK/3")
        assert (not branch2.onLocalLabel())
        assert (not branch2.onEmergeLabel())
        assert (branch2.onRollbackLabel())
        assert (not branch2.onLocalCookLabel())
        assert (branch2.isOnLocalHost())
        assert (branch2.isInLocalNamespace())

        # check local branch label
        branch2 = parent.createBranch(LocalLabel(), withVerRel=1)
        assert (
            branch2.asString() == "/foo.com@spc:bar/1.2-3/local@local:LOCAL/3")
        assert (branch2.onLocalLabel())
        assert (not branch2.onEmergeLabel())
        assert (not branch2.onRollbackLabel())
        assert (not branch2.onLocalCookLabel())
        assert (branch2.isOnLocalHost())
        assert (branch2.isInLocalNamespace())

        branch3 = VersionFromString(branch2.asString())
        assert (branch2 == branch3)

        branch2 = branch2.branch()
        assert (
            branch2.asString() == "/foo.com@spc:bar/1.2-3/local@local:LOCAL")

        parent = v.parentVersion()
        assert (parent.asString() == "/foo.com@spc:bar/1.2-3")
        branch2 = parent.createBranch(LocalLabel())
        assert (
            branch2.asString() == "/foo.com@spc:bar/1.2-3/local@local:LOCAL")

        shadow = parent.branch().createShadow(Label('foo.com@spc:shadow'))
        assert (shadow.asString() == "/foo.com@spc:bar//shadow")
        assert (shadow.getHost() == 'foo.com')

        branch = VersionFromString("/foo.com@spc:bar")
        v = VersionFromString("1.2-3", branch)
        assert (v.asString() == "/foo.com@spc:bar/1.2-3")

        # test getBinaryVersion and getSourceVersion
        v = ThawVersion(verStr)
        b = v.getBinaryVersion()
        assert (b.asString() ==
                "/foo.com@spc:bar/1.2-3-0/bang.com@spc:branch/2.4-5")

        # make sure slots are working
        v = ThawVersion("/foo.com@spec:bar/10:1.2-3")
        self.assertRaises(AttributeError, v.__setattr__, "foo", 1)
        v = ThawVersion(v.freeze())
        self.assertRaises(AttributeError, v.__setattr__, "foo", 1)

        v = VersionFromString('/localhost@rpl:linux/1.0-1-0/'
                              'local@local:EMERGE/1/COOK/2')
        assert (VersionFromString(v.asString()) == v)
Ejemplo n.º 8
0
    def testSerialNumber(self):
        assert (not SerialNumber('0'))
        assert (SerialNumber('1'))

    def testRevision(self):
        try:
            Revision("-")
        except ParseError, e:
            assert (str(e) == "bad release string: -")
        else:
            self.fail("ParseError expected")

        self.assertRaises(ParseError, Revision, "1-abc")
        self.assertRaises(ParseError, Revision, "1-3:4")

        v = Revision(".2a-3")
        assert (v.getVersion() == ".2a")

        v = Revision("1.2a-3")
        assert (v.getVersion() == "1.2a")

        self.assertRaises(AttributeError, v.__setattr__, "foo", 1)

        v2 = Revision("1.2a-3")
        assert (v == v2)
        assert (v2 == v)

        v2 = Revision("1.2a-2")
        assert (not v == v2)
        v2._incrementSourceCount(0)
        assert (v == v2)