def setUp(self): self.__logger = TestRaptorXML.Logger() self.__nullSysDefRoot = generic_path.Path("smoke_suite/test_resources") self.__sysDefRoot = generic_path.Join( os.environ[raptor.build.env], "test/smoke_suite/test_resources") self.__sysDefFileRoot = generic_path.Join(os.environ[raptor.build.env], "test/metadata/system")
def resolveOutputPath(self): """ Get the outputpath """ try: evaluator = self._getEvaluator(self.meaning) # This is messy as some configs construct the path inside the FLM # rather than talking it from the XML: usually because of some # conditional logic... but maybe some refactoring could avoid that. releasepath = evaluator.Get("RELEASEPATH") if not releasepath: raise BadQuery("could not get RELEASEPATH for config '%s'" % self.fullname) variantplatform = evaluator.Get("VARIANTPLATFORM") varianttype = evaluator.Get("VARIANTTYPE") featurevariantname = evaluator.Get("FEATUREVARIANTNAME") platform = evaluator.Get("TRADITIONAL_PLATFORM") if platform == "TOOLS2": self.outputpath = releasepath else: if not variantplatform: raise BadQuery("could not get VARIANTPLATFORM for config '%s'" % self.fullname) if featurevariantname: variantplatform += featurevariantname if not varianttype: raise BadQuery("could not get VARIANTTYPE for config '%s'" % self.fullname) self.outputpath = str(generic_path.Join(releasepath, variantplatform, varianttype)) except Exception as e: # Unable to determine output path self.text = str(e)
def testInterface(self): aRaptor = raptor.build.Raptor() cache = aRaptor.cache cache.Load(generic_path.Join(aRaptor.home, "test", "config", "interface.xml")) base = cache.FindNamedInterface("Base.XYZ") p = base.GetParams(cache) self.failUnless(self.checkForParam(p, "A", None)) self.failUnless(self.checkForParam(p, "B", "baseB")) self.failUnless(self.checkForParam(p, "C", "baseC")) extended = cache.FindNamedInterface("Extended.XYZ") p = extended.GetParams(cache) self.failUnless(self.checkForParam(p, "A", None)) self.failUnless(self.checkForParam(p, "B", "baseB")) self.failUnless(self.checkForParam(p, "C", "extC")) self.failUnless(self.checkForParam(p, "D", None)) f = extended.GetFLMIncludePath(cache=cache) self.assertEqual(f.File(), "ext.flm") extended = cache.FindNamedInterface("Extended2.XYZ") p = extended.GetParams(cache) self.failUnless(self.checkForParam(p, "A", None)) self.failUnless(self.checkForParam(p, "B", "baseB")) self.failUnless(self.checkForParam(p, "C", "extC")) self.failUnless(self.checkForParam(p, "D", None)) f = extended.GetFLMIncludePath(cache) self.assertEqual(f.File(), "base.flm")
def testClassLinux(self): if self.isWin32(): return local1 = generic_path.Path('some/folder/another/') local2 = generic_path.Join(local1, "test", "tmp") self.assertEqual(str(local2), "some/folder/another/test/tmp") msys1 = generic_path.Path('some/folder/another/') msys2 = generic_path.Join(msys1, "test", "tmp") self.assertEqual(str(msys2), "some/folder/another/test/tmp") # Absolute local1 = generic_path.Path('some/folder') self.failIf(local1.isAbsolute()) abs1 = local1.Absolute() self.assertEqual(str(abs1), self.cwd + "/some/folder") local2 = generic_path.Path('/some/folder') self.failUnless(local2.isAbsolute()) abs2 = local2.Absolute() self.assertEqual(str(abs2), "/some/folder") root = generic_path.Path("/") self.assertEqual(str(root), "/") # Path path = generic_path.Path("some/thing/") self.assertEqual(str(path), "some/thing") # SpaceSafePath # This doesn't mean much on non-Windows platforms, but we confirm nothing breaks if it is used pathwithspaces = "/Program Files/Some tool installed with spaces/no_spaces/s p c/no_more_spaces" path2 = generic_path.Path(pathwithspaces) spacesafe = path2.GetSpaceSafePath() self.assertEqual(spacesafe, None)
def testProducts(self): r = raptor.build.Raptor(dotargets=False) r.cache.Load(generic_path.Join(r.home, "test", "configapi", "api.xml")) api = raptor.api.Context(r) products = api.getproducts() # type == "product" self.failUnlessEqual(len(products), 2) self.failUnlessEqual(set(["product_A", "product_C"]), set(p.name for p in products)) productlist = [p.name for p in products] # verify that the list is sorted self.failUnlessEqual(["product_A", "product_C"], productlist)
def testGroup2(self): r = raptor.build.Raptor() r.cache.Load( generic_path.Join(r.home, "test", "config", "arm.xml") ) buildUnits = r.cache.FindNamedGroup("G2").GenerateBuildUnits(r.cache) self.assertEqual( len(buildUnits), 8 ) self.assertEqual(buildUnits[0].name, "ARMV5_UREL.MOD1") self.assertEqual(buildUnits[1].name, "ARMV5_UDEB.MOD1.MOD2") self.assertEqual(buildUnits[2].name, "ALIAS_1") self.assertEqual(buildUnits[3].name, "ALIAS_2.MOD1.MOD2.MOD1") self.assertEqual(buildUnits[4].name, "ARMV5_UREL.MOD2") self.assertEqual(buildUnits[5].name, "ARMV5_UDEB.MOD2") self.assertEqual(buildUnits[6].name, "MOD1") self.assertEqual(buildUnits[7].name, "MOD2")
def testEvaluator(self): self.SetEnv("EPOCROOT", "/C") aRaptor = raptor.build.Raptor() cache = aRaptor.cache aRaptor.debugOutput = True cache.Load(generic_path.Join(aRaptor.home, "test", "config", "arm.xml")) var = cache.FindNamedVariant("ARMV5_UREL") eval = aRaptor.GetEvaluator( None, var.GenerateBuildUnits(aRaptor.cache)[0]) self.RestoreEnv("EPOCROOT") # test the Get method varcfg = eval.Get("VARIANT_CFG") self.assertEqual(varcfg, "/C/variant/variant.cfg") # test the Resolve wrt EPOCROOT varcfg = eval.Resolve("VARIANT_CFG") self.assertEqual(varcfg, "/C/variant/variant.cfg")
def testAliases(self): r = raptor.build.Raptor(dotargets=False) r.cache.Load(generic_path.Join(r.home, "test", "configapi", "api.xml")) api = raptor.api.Context(r) aliases = api.getaliases() # type == "" self.failUnlessEqual(len(aliases), 4) self.failUnlessEqual(set(["alias_A", "alias_B", "s1", "s2"]), set(a.name for a in aliases)) aliaslist = [a.name for a in aliases] # verify that the list is sorted self.failUnlessEqual(["alias_A", "alias_B", "s1", "s2"], aliaslist) aliases = api.getaliases(raptor.api.ALL) # ignore type self.failUnlessEqual(len(aliases), 6) aliases = api.getaliases("X") # type == "X" self.failUnlessEqual(len(aliases), 1) self.failUnlessEqual(aliases[0].name, "alias_D") self.failUnlessEqual(aliases[0].meaning, "a.b.c.d")
def testClassCommon(self): p1 = generic_path.Path("a", "b") p2 = p1.Append("c") self.assertEqual(str(p2), "a/b/c") p3 = p1.Append("c", "d") self.assertEqual(str(p3), "a/b/c/d") p4 = p1.Prepend("z") self.assertEqual(str(p4), "z/a/b") p5 = p1.Prepend("y", "z") self.assertEqual(str(p5), "y/z/a/b") self.assertEqual(str(p5.Dir()), "y/z/a") self.assertEqual(p5.File(), "b") p6 = generic_path.Join("test") self.assertEqual(str(p6.Dir()), "") self.assertEqual(p6.File(), "test")
def testConfig(self): r = raptor.build.Raptor(dotargets=False) r.cache.Load(generic_path.Join(r.home, "test", "configapi", "api.xml")) api = raptor.api.Context(r) if r.filesystem == "unix": path = "/home/raptor/foo/bar" else: path = "C:/home/raptor/foo/bar" config = api.getconfig("buildme") self.failUnlessEqual(config.meaning, "buildme") self.failUnlessEqual(config.outputpath, path) self.failIfEqual(config.metadata, None) # metadata metadatamacros = [ str(x.name + "=" + x.value) if x.value else str(x.name) for x in config.metadata.platmacros ] metadatamacros.sort() results = ['SBSV2=_____SBSV2', '__GNUC__=3'] results.sort() self.failUnlessEqual(metadatamacros, results) includepaths = [str(x.path) for x in config.metadata.includepaths] includepaths.sort() # This result is highly dependent on the epocroot being used to test against. # with an SF baseline or an old Symbian one one might see this: # expected_includepaths = [raptor_tests.ReplaceEnvs("$(EPOCROOT)/epoc32/include/variant"), # raptor_tests.ReplaceEnvs("$(EPOCROOT)/epoc32/include"), "." # With another one might see: expected_includepaths = [ raptor_tests.ReplaceEnvs("$(EPOCROOT)/epoc32/include"), raptor_tests.ReplaceEnvs("$(EPOCROOT)/epoc32/include"), "." ] expected_includepaths.sort() self.failUnlessEqual(includepaths, expected_includepaths) preincludefile = str(config.metadata.preincludeheader.file) # Another baseline dependent result # self.failUnlessEqual(preincludefile, raptor_tests.ReplaceEnvs("$(EPOCROOT)/epoc32/include/variant/Symbian_OS.hrh")) self.failUnlessEqual( preincludefile, raptor_tests.ReplaceEnvs( "$(EPOCROOT)/epoc32/include/feature_settings.hrh")) # build sourcemacros = [ str(x.name + "=" + x.value) if x.value else str(x.name) for x in config.build.sourcemacros ] results = [ '__BBB__', '__AAA__', '__DDD__=first_value', '__CCC__', '__DDD__=second_value' ] self.failUnlessEqual(sourcemacros, results) compilerpreincludefile = str( config.build.compilerpreincludeheader.file) self.failUnlessEqual( compilerpreincludefile, raptor_tests.ReplaceEnvs( "$(EPOCROOT)/epoc32/include/preinclude.h")) expectedtypes = ["one", "two"] expectedtypes.sort() types = [t.name for t in config.build.targettypes] types.sort() self.failUnlessEqual(types, expectedtypes) # general config = api.getconfig("buildme.foo") self.failUnlessEqual(config.meaning, "buildme.foo") self.failUnlessEqual(config.outputpath, path) config = api.getconfig("s1") self.failUnlessEqual(config.meaning, "buildme.foo") self.failUnlessEqual(config.outputpath, path) config = api.getconfig("s2.product_A") self.failUnlessEqual(config.meaning, "buildme.foo.bar.product_A") self.failUnlessEqual(config.outputpath, path)
def testSystemDefinitionProcessing(self): # Make formatting neater print("") expectedBldInfs = [generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "basics/helloworld/Bld.inf")] sysdefs = ["1.4.1", "1.3.1", "1.5.1"] for sysdef in sysdefs: systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_" + sysdef + ".xml"), self.__sysDefRoot) self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) sourceroot = "" if 'SOURCEROOT' in os.environ: sourceroot = os.environ['SOURCEROOT'] os.environ['SOURCEROOT'] = self.__sysDefRoot.GetLocalString() systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__nullSysDefRoot) self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) del os.environ["SOURCEROOT"] systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__sysDefRoot) self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) os.environ["SOURCEROOT"] = 'i_am_not_a_valid_path_at_all' systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__sysDefRoot) self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) del os.environ["SOURCEROOT"] systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_3.0.0.xml"), self.__sysDefRoot) self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) # Additionally confirm that layers are returned correctly in a v3 context (where <meta/> and <api/> tags are also present) layers = systemModel.GetLayerNames() self.assertTrue(len(layers) == 1) self.assertEqual("testlayer", layers[0]) self.__logger.Clear() systemModel = raptor.sysdef.SystemModel( self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_multi_layers.xml"), self.__sysDefRoot) self.assertTrue(len(self.__logger.errors) == 0) # Confirm components returned from layers are correct expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_dll/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_implib/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_lib/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_stringtable/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_test/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_plugin/bld.inf")] self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents()) expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\ generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf")] self.__compareFileLists(expectedBldInfs, systemModel.GetLayerComponents("Second Layer")) self.__compareFileLists([], systemModel.GetLayerComponents("Fifth Layer")) self.__compareFileLists([], systemModel.GetLayerComponents("Sixth Layer")) # Check that the overall "buildability" of layers is returned correctly # Note that a layer is still buildable if some bld.infs in it are missing as long as at least 1 exists # However, errors should always be generated for missing bld.infs when a layer is checked self.assertTrue(systemModel.IsLayerBuildable("First Layer")) self.assertFalse(systemModel.IsLayerBuildable("Sixth Layer")) self.__logger.Clear() self.assertTrue(systemModel.IsLayerBuildable("Seventh Layer")) self.assertTrue(len(self.__logger.errors) == 1) sbsHome = os.environ["SBS_HOME"] sysDefPath = os.path.join( sbsHome, "test/metadata/system/system_definition_multi_layers.xml") sysDefPath = sysDefPath.replace("\\", "/") bldInfPath = os.path.join( sbsHome, "test/smoke_suite/test_resources/does_not_exist/bld.inf") bldInfPath = bldInfPath.replace("\\", "/") self.assertEquals(self.__logger.errors[0], ( "System Definition layer \"Seventh Layer\" from system definition file \"%s\" refers to non existent bld.inf file %s" % (sysDefPath, bldInfPath))) # Probably redundant, but return local environment (at least its dictionary) to pre-test state os.environ["SOURCEROOT"] = sourceroot
def testClassWin32(self): if not self.isWin32(): return local1 = generic_path.Path('some\\folder\\another\\') local2 = generic_path.Join(local1, "test", "tmp") self.assertEqual(str(local2), "some/folder/another/test/tmp") # Absolute local1 = generic_path.Path('some\\folder') self.failIf(local1.isAbsolute()) abs1 = local1.Absolute() self.assertEqual( str(abs1).lower(), (self.cwd + "/some/folder").lower()) local2 = generic_path.Path('C:\\some\\folder') self.failUnless(local2.isAbsolute()) abs2 = local2.Absolute() self.assertEqual(str(abs2), "C:/some/folder") local3 = generic_path.Path('\\somerandomfolder') self.failUnless(re.match('^[A-Za-z]:/somerandomfolder$', str(local3))) local4 = generic_path.Path('\\my\\folder\\') self.failUnless(re.match('^[A-Za-z]:/my/folder$', str(local4))) local5 = generic_path.Path('\\') self.failUnless(re.match('^[A-Za-z]:$', str(local5))) local6 = generic_path.Path("C:") self.failUnless(local6.isAbsolute()) self.failUnless(local6.isDir()) self.failUnless(local6.Exists()) local7 = local6.Absolute() self.assertEqual(str(local7), "C:") local8 = generic_path.Path("C:/") self.failUnless(local8.isAbsolute()) self.failUnless(local8.isDir()) self.failUnless(local8.Exists()) local9 = local8.Absolute() self.assertEqual(str(local9), "C:") # Drives driveD = generic_path.Path("D:\\", "folder") self.assertEqual(str(driveD), "D:/folder") driveA = generic_path.Path("a:\\") self.assertEqual(str(driveA), "a:") self.assertEqual(str(driveA.Dir()), "a:") driveZ = generic_path.Path("Z:\\test") self.assertEqual(str(driveZ), "Z:/test") joinC = generic_path.Join("C:\\", "something") self.assertEqual(str(joinC), "C:/something") joinM = generic_path.Join("M:", "something") self.assertEqual(str(joinM), "M:/something") # Path path2 = generic_path.Path("m:/sys/thing/") self.assertEqual(str(path2), "m:/sys/thing") path3 = generic_path.Path("m:\\sys\\thing\\") self.assertEqual(str(path3), "m:/sys/thing") path4 = generic_path.Path("m:\\") self.assertEqual(str(path4), "m:") path5 = generic_path.Path("\\sys\\thing\\") self.failUnless(re.match('^[A-Za-z]:/sys/thing$', str(path5))) path6 = generic_path.Path("m:/") self.assertEqual(str(path6), "m:") # SpaceSafePath epocroot = os.path.abspath(os.environ.get('EPOCROOT')).replace( '\\', '/').rstrip('/') pathwithspaces = epocroot + "/epoc32/build/Program Files/Some tool installed with spaces/no_spaces/s p c/no_more_spaces" path7 = generic_path.Path(pathwithspaces) # SpaceSafe paths on Windows are 8.3 format, and these can only be deduced if they actually exist. os.makedirs(pathwithspaces) spacesafe = path7.GetSpaceSafePath() self.assertTrue( spacesafe.endswith("PROGRA~1/SOMETO~1/NO_SPA~1/SPC~1/NO_MOR~1")) os.removedirs(pathwithspaces) spacesafe = path7.GetSpaceSafePath() self.assertEqual(spacesafe, None)
def __ProcessSystemModelElement(self, aElement): """Search for XML <unit/> elements with 'bldFile' attributes and resolve concrete bld.inf locations with an appreciation of different schema versions.""" # Metadata elements are processed separately - there are no further child nodes # to process in this context if aElement.tagName == "meta": return self.__ProcessSystemModelMetaElement(aElement) # The effective "layer" is the item whose parent does not have an id (or name in 2.x and earlier) if not aElement.parentNode.hasAttribute(self.__IdAttribute): currentLayer = aElement.getAttribute(self.__IdAttribute) if currentLayer not in self.__LayerDetails: self.__LayerDetails[currentLayer] = [] if not currentLayer in self.__LayerList: self.__LayerList.append(currentLayer) elif aElement.tagName == "unit" and aElement.hasAttributes(): bldFileValue = aElement.getAttribute("bldFile") if bldFileValue: bldInfRoot = self.__ComponentRoot if self.__Version['MAJOR'] == 1: # version 1.x schema paths can use DOS slashes bldFileValue = bldFileValue.replace('\\', '/') elif self.__Version['MAJOR'] >= 2: # version 2.x.x schema paths are subject to a "root" attribute off-set, if it exists rootValue = aElement.getAttribute("root") if rootValue: if rootValue in os.environ: bldInfRoot = generic_path.Path( os.environ[rootValue]) else: # Assume that this is an error i.e. don't attempt to resolve in relation to SOURCEROOT bldInfRoot = None self.__Logger.Error( "Cannot resolve \'root\' attribute value \"{0}\" in {1}" .format(rootValue, self.__SystemDefinitionFile)) return bldinfval = generic_path.Path(bldFileValue) if self.__Version['MAJOR'] < 3: # absolute paths are not changed by root var in 1.x and 2.x if not bldinfval.isAbsolute() and bldInfRoot: bldinfval = generic_path.Join(bldInfRoot, bldinfval) else: # relative paths for v3 if not bldinfval.isAbsolute(): bldinfval = generic_path.Join( generic_path.Join( self.__SystemDefinitionFile).Dir(), bldinfval) # absolute paths for v3 # are relative to bldInfRoot if set, or relative to the drive root otherwise elif bldInfRoot: bldinfval = generic_path.Join(bldInfRoot, bldinfval) if self.__fullbldinfs: bldinf = bldinfval.FindCaseless() else: bldinf = generic_path.Join(bldinfval, "bld.inf").FindCaseless() if bldinf == None: # recording layers containing non existent bld.infs bldinfname = bldinfval.GetLocalString() if not self.__fullbldinfs: bldinfname = bldinfname + '/' + 'bld.inf' layer = self.__GetEffectiveLayer(aElement) if not layer in self.__MissingBldInfs: self.__MissingBldInfs[layer] = [] self.__MissingBldInfs[layer].append(bldinfname) else: component = self.__CreateComponent(bldinf, aElement) layer = component.GetLayerName() if layer: self.__LayerDetails[layer].append(component) self.__TotalComponents += 1 else: self.__Logger.Error( "No containing layer found for {0} in {1}".format( str(bldinf), self.__SystemDefinitionFile)) # search the sub-elements for child in aElement.childNodes: if child.nodeType == child.ELEMENT_NODE: self.__ProcessSystemModelElement(child)