Пример #1
0
    def __init__(self, log: Log, filename: str) -> None:
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate config file %s",
                                        filename)

        tree = ET.parse(filename)
        elem = tree.getroot()
        if elem.tag != 'FslBuildGeneratorVSProjectTemplateCustomization':
            raise XmlInvalidRootElement(
                "The file did not contain the expected root tag 'FslBuildGeneratorVSProjectTemplateCustomization'"
            )

        super().__init__(log, elem)
        strVersion = self._ReadAttrib(elem, 'Version')
        if strVersion != "1":
            raise Exception("Unsupported version")

        xmlConfiguration = self.__LoadTemplateConfiguration(log, elem)
        if len(xmlConfiguration) != 1:
            raise XmlException(
                "The file did not contain exactly one BuildOutput element")

        self.Version = 1
        self.BuildOutput = xmlConfiguration[0]
        self.Path = IOUtil.GetDirectoryName(filename)
Пример #2
0
    def __init__(self, log: Log, filename: str) -> None:
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate config file %s", filename)

        tree = ET.parse(filename)
        elem = tree.getroot()
        if elem.tag == 'FslBuildGeneratorVSProjectTemplate':
            pass
        elif elem.tag == 'FslBuildNewVSProjectTemplate':
            log.LogPrintWarning("Template file '{0}' using legacy template FslBuildNewVSProjectTemplate update it to FslBuildGeneratorVSProjectTemplate".format(filename))
        else:
            raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGeneratorVSProjectTemplate'")

        super().__init__(log, elem)
        strVersion = self._ReadAttrib(elem, 'Version')
        if strVersion != "1":
            raise Exception("Unsupported version")

        xmlTemplate = self.__LoadTemplateConfiguration(log, elem)
        if len(xmlTemplate) != 1:
            raise XmlException("The file did not contain exactly one Template element")

        directoryName = IOUtil.GetDirectoryName(filename)
        self.Name = IOUtil.GetFileName(directoryName)
        self.Id = self.Name.lower()
        self.Version = 1
        self.Template = xmlTemplate[0]
        self.Path = IOUtil.GetDirectoryName(filename)
        self.Prefix = ("%s_" % (self.Name)).upper()

        if self.Name != self.Template.Name:
            raise Exception("The parent template directory name '{0}' does not match the template name '{1}' {2}".format(self.Name, self.Template.Name, self.Path))
    def __init__(self, log: Log, filename: str, projectRootConfig: XmlProjectRootConfigFile) -> None:
        if projectRootConfig is None:
            raise Exception("projectRootConfig can not be None")
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate config file %s", filename)

        tree = ET.parse(filename)
        elem = tree.getroot()
        if elem.tag != 'FslBuildGenConfig':
            raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGenConfig'")

        super().__init__(log, elem)
        currentVersion = '2'
        fileVersion = self._ReadAttrib(elem, 'Version')
        if fileVersion != currentVersion:
            raise XmlException("The file was not of the expected version {0}".format(currentVersion))

        # In V2 we do not support local AddRootDirectory elements, we use the ones in ProjectRootConfig
        rootDirs = projectRootConfig.XmlRootDirectories
        if len(rootDirs) < 1:
            raise XmlException("The file did not contain at least one AddRootDirectory element")

        templateImportDirectory = self.__LoadAddTemplateImportDirectory(elem)

        self.__CheckForLegacyElements(elem, filename)

        # In V2 we do not support local PackageConfiguration elements, we use the ones in ProjectRootConfig
        xmlPackageConfigurations = projectRootConfig.XmlPackageConfiguration  # type: List[XmlConfigPackageConfiguration]
        if len(xmlPackageConfigurations) < 1:
            if projectRootConfig.SourceFileName is None:
                raise XmlException("The file '{0}' did not contain at least one PackageConfiguration element".format(filename))
            else:
                raise XmlException("The file '{0}' and {1} did not contain at least one PackageConfiguration element".format(filename, projectRootConfig.SourceFileName))

        newProjectTemplatesRootDirectories = LoadUtil.LoadAddNewProjectTemplatesRootDirectory(log, elem, filename)
        newProjectTemplatesRootDirectories = self.__MergeNewProjectTemplatesRootDirectories(newProjectTemplatesRootDirectories, projectRootConfig.XmlNewProjectTemplatesRootDirectories)

        xmlContentBuilderConfiguration = self.__LoadContentBuilderConfiguration(elem)

        xmlConfigFileTemplateFolder = self.__LoadTemplateFolder(elem)

        self.Version = int(fileVersion)  # type: int
        self.RootDirectories = rootDirs  # type: List[XmlConfigFileAddRootDirectory]
        self.TemplateImportDirectories = templateImportDirectory  # type: List[XmlConfigFileAddTemplateImportDirectory]
        self.PackageConfiguration = self.__ResolvePackageConfiguration(xmlPackageConfigurations)  # type: Dict[str, XmlConfigPackageConfiguration]
        self.NewProjectTemplateRootDirectories = newProjectTemplatesRootDirectories  # type: List[XmlConfigFileAddNewProjectTemplatesRootDirectory]
        self.TemplateFolder = xmlConfigFileTemplateFolder  # type: XmlConfigFileTemplateFolder
        self.GenFileName = self.__LoadGenFileName(elem)  # type: XmlConfigFileGenFile
        self.ContentBuilderConfiguration = xmlContentBuilderConfiguration  # type: XmlConfigContentBuilderConfiguration
        self.BuildDocConfiguration = projectRootConfig.XmlBuildDocConfiguration # type: List[XmlBuildDocConfiguration]
        self.ClangFormatConfiguration = projectRootConfig.XmlClangFormatConfiguration  # type: List[XmlClangFormatConfiguration]
        self.ClangTidyConfiguration = projectRootConfig.XmlClangTidyConfiguration  # type: List[XmlClangTidyConfiguration]
        self.CMakeConfiguration = projectRootConfig.XmlCMakeConfiguration  # type: List[XmlCMakeConfiguration]
        self.CompilerConfiguration = projectRootConfig.XmlCompilerConfiguration  # type: List[XmlConfigCompilerConfiguration]
        self.Experimental = self.__ResolveExperimental(projectRootConfig.XmlExperimental)  # type: Optional[XmlExperimental]
    def __LoadXml(self, log: Log, filename: str) -> ET.Element:
        """ Careful this code must be self contained as it can be used before the parent class is initialized """
        if filename is None:
            raise Exception("filename can not be None")

        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate config file %s", filename)
        tree = ET.parse(filename)
        xmlElement = tree.getroot()
        if xmlElement.tag != 'FslBuildGenProjectRoot':
            raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGenProjectRoot'")
        return xmlElement
Пример #5
0
    def __init__(self, log: Log, requirementTypes: List[str], filename: str) -> None:
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate gen file %s", filename)

        tree = ET.parse(filename)
        xmlElement = tree.getroot()
        if xmlElement.tag != 'FslBuildTemplate':
            raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildTemplate'")

        super().__init__(log, requirementTypes, xmlElement)

        self.Name = IOUtil.GetFileNameWithoutExtension(filename)
        self.DirectRequirements = self._GetXMLRequirements(xmlElement)
    def __init__(self, config: Config, filename: str,
                 subPackageSupport: SubPackageSupportConfig) -> None:
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate gen file %s",
                                        filename)

        tree = ET.parse(filename)
        xmlElement = tree.getroot()
        if xmlElement.tag != 'FslBuildTemplate':
            raise XmlInvalidRootElement(
                "The file did not contain the expected root tag 'FslBuildTemplate'"
            )

        super().__init__(config, xmlElement, subPackageSupport)

        self.Name = IOUtil.GetFileNameWithoutExtension(filename)
        self.DirectRequirements = self._GetXMLRequirements(xmlElement)
    def __init__(self, log: Log, filename: str) -> None:
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate config file %s", filename)

        tree = ET.parse(filename)
        elem = tree.getroot()
        if elem.tag != 'FslBuildNewTemplate':
            raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGenConfig'")

        super().__init__(log, elem)
        fileVersion = self._ReadAttrib(elem, 'Version')
        if fileVersion != '1':
            raise Exception("The template file version was not correct")

        xmlTemplate = self.__LoadTemplateConfiguration(log, elem)
        if len(xmlTemplate) != 1:
            raise XmlException("The file did not contain exactly one Template element")

        self.Name = IOUtil.GetFileName(IOUtil.GetDirectoryName(filename))
        self.Id = self.Name.lower()
        self.Version = int(fileVersion)  # type: int
        self.Template = xmlTemplate[0]
        self.Path = IOUtil.GetDirectoryName(filename)
        self.Prefix = ("%s_" % (self.Name)).upper()
Пример #8
0
    def Load(self, config: Config,
             packageTemplateLoader: PackageTemplateLoader,
             packageFile: PackageFile) -> None:
        filename = packageFile.AbsoluteFilePath
        if not os.path.isfile(filename):
            raise FileNotFoundException("Could not locate gen file %s",
                                        filename)

        self.SourceFilename = filename
        self.PackageLocation = packageFile.PackageRootLocation

        fileContent = IOUtil.ReadFile(filename)
        self.SourceFileHash = self.__CalcContentHash(fileContent)
        elem = ET.fromstring(fileContent)
        if elem.tag != 'FslBuildGen':
            raise XmlInvalidRootElement(
                "The file did not contain the expected root tag 'FslBuildGen'")

        elem, theType = self.__FindPackageElementAndType(elem)

        packageName = self._ReadAttrib(elem, 'Name')
        defaultValues = self.__GetDefaultValues(elem, packageName)
        allowNoInclude = self._ReadBoolAttrib(elem, 'NoInclude', False)
        companyName = self._ReadAttrib(elem, 'Company',
                                       config.ToolConfig.DefaultCompany)

        if config.ToolConfig.RequirePackageCreationYear:
            creationYear = self._ReadAttrib(elem, 'CreationYear')
        else:
            creationYear = self._ReadAttrib(
                elem, 'CreationYear', PackageCreationYearString.NotDefined)

        templateType = self._ReadAttrib(elem, 'TemplateType', "")
        self.AllowCheck = self._ReadBoolAttrib(elem, 'AllowCheck', True)
        # if this is set we allow '.cc' files for C++ code.
        self.EnableExtendedSourceExtensions = self._ReadBoolAttrib(
            elem, 'EnableExtendedSourceExtensions', False)

        self.BaseIncludePath = self._ReadAttrib(elem, 'OverrideInclude',
                                                'include')
        self.BaseSourcePath = self._ReadAttrib(elem, 'OverrideSource',
                                               'source')
        self.AllowCombinedDirectory = self._ReadBoolAttrib(
            elem, 'AllowCombinedDirectory', False)
        self.PackageNameBasedIncludePath = self._ReadBoolAttrib(
            elem, 'PackageNameBasedIncludePath', True)

        self.BaseLoad(
            elem, SubPackageSupportConfig(theType, config.SubPackageSupport))

        requirements = self._GetXMLRequirements(elem)
        allowRecipes = self.__DoesTypeAllowRecipes(theType)

        # Add recipe and dependencies
        self.DirectExperimentalRecipe = self._TryGetExperimentalRecipe(
            elem, packageName, allowRecipes)
        if self.DirectExperimentalRecipe is not None:
            self.DirectDependencies += self.__AddExperimentalRecipeDependencies(
                self.DirectDependencies, [], self.DirectExperimentalRecipe)

        platforms = self.__GetXMLPlatforms(elem, packageName,
                                           self.DirectDependencies,
                                           allowRecipes, defaultValues)
        self.BuildCustomization = self.__GetBuildCustomizations(
            elem, packageName)

        templates = self.__GetXMLImportTemplates(elem)
        self.__ImportTemplates(packageTemplateLoader, templates, requirements,
                               self.DirectDependencies,
                               self.ExternalDependencies, self.DirectDefines)

        if self.BaseIncludePath == self.BaseSourcePath and not self.AllowCombinedDirectory:
            raise XmlException2(
                elem,
                "Package '{0}' uses the same directory for include and source '{1}'"
                .format(packageName, self.BaseIncludePath))

        self.SourcePackageFile = packageFile
        self.XMLElement = elem
        self.Name = packageName
        self.ShortName = None
        self.Namespace = None
        self.SetType(theType)
        self.Platforms = platforms
        self.DirectRequirements = requirements
        self.AbsolutePath = None
        self.AbsoluteIncludePath = None
        self.AbsoluteSourcePath = None
        self.CompanyName = companyName
        self.CreationYear = creationYear
        self.TemplateType = templateType
        self.PlatformDefaultSupportedValue = defaultValues.Platform_Supported
        self.SystemDefaultValues = defaultValues

        self._ValidateName(elem, self.Name)
        # This check was moved to the package loader where it belongs
        #self.__ValidateFilename(config, filename)
        self.__ResolveNames(self.Name)
        self.__ValidateBasicDependencyCorrectness()
        self.__ValidateDefines()
        self.__ResolvePaths(config, filename, allowNoInclude)