示例#1
0
    def __init__(self, log: Log, xmlElement: ET.Element, filename: str) -> None:
        super().__init__(log, xmlElement)
        #raise Exception("ExtendedProject not implemented");
        self.ProjectName = self._ReadAttrib(xmlElement, 'Name') # type: str
        self.ShortProjectName = self._TryReadAttrib(xmlElement, 'ShortName') # type: Optional[str]
        self.ProjectVersion = self._ReadAttrib(xmlElement, 'Version', "1.0.0.0") # type: str
        self.RootDirectory = IOUtil.GetDirectoryName(filename)
        self.Parent = self._ReadAttrib(xmlElement, 'Parent')  # type: str
        self.ParentRoot = self._ReadAttrib(xmlElement, 'ParentRoot')  # type: str
        configFilename = IOUtil.GetFileName(filename)   # type: str
        self.ParentConfigFilename = IOUtil.Join(self.ParentRoot, configFilename)  # type: str
        self.SourceFileName = filename  # type: str

        self.ProjectId = ProjectId(self.ProjectName, self.ShortProjectName)

        variableProcessor = VariableProcessor(log)
        self.AbsoluteParentConfigFilename = variableProcessor.ResolveAbsolutePathWithLeadingEnvironmentVariablePath(self.ParentConfigFilename)
        self.XmlPackageConfiguration = _LoadPackageConfigurations(log, xmlElement, filename)  # type: List[XmlConfigPackageConfiguration]
        self.XmlBasePackages = _LoadAddBasePackage(log, xmlElement, filename) # type: List[XmlConfigFileAddBasePackage]
        self.XmlRootDirectories = _LoadAddRootDirectory(log, xmlElement, filename, self.ProjectId) # type: List[XmlConfigFileAddRootDirectory]
        self.XmlNewProjectTemplatesRootDirectories = LoadUtil.LoadAddNewProjectTemplatesRootDirectory(log, xmlElement, filename)
        self.XmlBuildDocConfiguration = _LoadBuildDocConfiguration(log, xmlElement, filename)  # type: List[XmlBuildDocConfiguration]
        self.XmlClangFormatConfiguration = _LoadClangFormatConfiguration(log, xmlElement, filename)  # type: List[XmlClangFormatConfiguration]
        self.XmlClangTidyConfiguration = _LoadClangTidyConfiguration(log, xmlElement, filename)  # type: List[XmlClangTidyConfiguration]
        self.XmlCMakeConfiguration = _LoadCMakeConfiguration(log, xmlElement, filename)  # type: List[XmlCMakeConfiguration]
        self.XmlCompilerConfiguration = _LoadCompilerConfiguration(log, xmlElement, filename)  # type: List[XmlConfigCompilerConfiguration]
        self.XmlExperimental = _TryLoadExperimental(log, xmlElement, filename)  # type: Optional[XmlExperimental]
 def __FindProjectContext(self, config: Config, genFile: XmlGenFile) -> PackageProjectContext:
     """
     Associate the package with the 'project' that it belongs to
     """
     if genFile.PackageLocation is None:
         if genFile.Type != PackageType.TopLevel:
             raise UsageErrorException("Package '{0}' did not contain a valid location".format(genFile.Name))
         # The top level package is not associated with a project context
         topLevelProjectContext = PackageProjectContext(ProjectId("__TopLevel__"), "__TopLevel__", "0.0.0.0", [])
         self.__ProjectContextCache.Add(topLevelProjectContext)
         return topLevelProjectContext
     projectContext = ToolConfigPackageProjectContextUtil.FindProjectContext(config.ToolConfig.ProjectInfo.Contexts, genFile.PackageLocation.ResolvedPath)
     basePackages = self.__CreateBasePackageList(projectContext.BasePackages)
     packageProjectContext = self.__ProjectContextCache.TryGet(projectContext.ProjectName)
     if packageProjectContext is None:
         packageProjectContext = PackageProjectContext(projectContext.ProjectId, projectContext.ProjectName, projectContext.ProjectVersion, basePackages)
         self.__ProjectContextCache.Add(packageProjectContext)
     return packageProjectContext
示例#3
0
    def __LoadFromXml(self,
                      log: Log,
                      xmlElement: ET.Element,
                      filename: str,
                      canExtend: bool = True) -> None:
        self.Version = '1'  # type: str
        self.ProjectName = "not set"
        self.ProjectVersion = "0.0.0.0"
        self.RootDirectory = LocalInvalidValues.INVALID_FILE_NAME  # type: str
        self.DefaultPackageLanguage = PackageLanguage.CPP  # type: PackageLanguage
        self.DefaultCompany = LocalInvalidValues.INVALID_COMPANY_NAME  # type: str
        self.ToolConfigFile = LocalInvalidValues.INVALID_FILE_NAME  # type: str
        self.RequirePackageCreationYear = False
        self.XmlExperimental = None  # type: Optional[XmlExperimental]
        self.XmlPackageConfiguration = [
        ]  # type: List[XmlConfigPackageConfiguration]
        self.XmlBasePackages = []  # type: List[XmlConfigFileAddBasePackage]
        self.XmlRootDirectories = [
        ]  #  type: List[XmlConfigFileAddRootDirectory]
        self.XmlNewProjectTemplatesRootDirectories = [
        ]  # type: List[XmlConfigFileAddNewProjectTemplatesRootDirectory]
        self.XmlCompilerConfiguration = [
        ]  # type: List[XmlConfigCompilerConfiguration]
        self.SourceFileName = LocalInvalidValues.INVALID_FILE_NAME  # type: str
        self.DefaultTemplate = MagicStrings.VSDefaultCPPTemplate  # type: str
        self.ExtendedProject = []  # type: List[XmlExtendedProject]
        if xmlElement is not None:
            extendedElement = xmlElement.find(
                "ExtendedProject") if canExtend else None
            if extendedElement is None:
                rootDirectory = IOUtil.GetDirectoryName(filename)
                variableEnvironment = VariableEnvironment(self.Log)
                variableEnvironment.Set("PROJECT_ROOT", rootDirectory)
                variableProcessor = VariableProcessor(self.Log,
                                                      variableEnvironment)
                self.Version = self._ReadAttrib(xmlElement, 'Version')
                self.RootDirectory = rootDirectory
                projectElem = XmlBase._GetElement(
                    self, xmlElement, "Project")  # type: ET.Element
                self.ProjectName = self._ReadAttrib(projectElem, 'Name')
                self.ShortProjectName = self._TryReadAttrib(
                    projectElem, 'ShortName')
                self.ProjectId = ProjectId(self.ProjectName,
                                           self.ShortProjectName)
                self.ProjectVersion = self._ReadAttrib(projectElem, 'Version',
                                                       "1.0.0.0")
                toolConfigFilePath = self._ReadAttrib(
                    projectElem, 'ToolConfigFile')  # type: str
                self.DefaultPackageLanguage = self.__GetDefaultPackageLanguage(
                    projectElem)
                self.DefaultCompany = self._ReadAttrib(projectElem,
                                                       'DefaultCompany')
                # if this is set to true each package is required to contian a 'CreationYear=""' attribute
                self.RequirePackageCreationYear = self._ReadBoolAttrib(
                    projectElem, 'RequirePackageCreationYear', False)
                self.ToolConfigFile = variableProcessor.ResolvePathToAbsolute(
                    toolConfigFilePath, self.XMLElement)
                self.XmlPackageConfiguration = _LoadPackageConfigurations(
                    log, projectElem, filename)
                self.XmlBasePackages = _LoadAddBasePackage(
                    log, projectElem, filename)
                self.XmlRootDirectories = _LoadAddRootDirectory(
                    log, projectElem, filename, self.ProjectId)
                self.XmlNewProjectTemplatesRootDirectories = LoadUtil.LoadAddNewProjectTemplatesRootDirectory(
                    log, projectElem, filename)
                self.XmlBuildDocConfiguration = _LoadBuildDocConfiguration(
                    log, projectElem, filename)
                self.XmlClangFormatConfiguration = _LoadClangFormatConfiguration(
                    log, projectElem, filename)
                self.XmlClangTidyConfiguration = _LoadClangTidyConfiguration(
                    log, projectElem, filename)
                self.XmlCMakeConfiguration = _LoadCMakeConfiguration(
                    log, projectElem, filename)
                self.XmlCompilerConfiguration = _LoadCompilerConfiguration(
                    log, projectElem, filename)
                self.XmlExperimental = _TryLoadExperimental(
                    log, projectElem, filename)
                self.SourceFileName = filename
                self.DefaultTemplate = self._ReadAttrib(
                    projectElem, 'DefaultTemplate',
                    MagicStrings.VSDefaultCPPTemplate)
            else:
                # Do something with the extended element
                extendedProject = XmlExtendedProject(log, extendedElement,
                                                     filename)
                parentFileName = extendedProject.AbsoluteParentConfigFilename
                parentElem = self.__LoadXml(log, parentFileName)
                self.__LoadFromXml(log, parentElem, parentFileName,
                                   True)  # True to allow multiple extensions
                self.ExtendedProject.append(extendedProject)
                self.__ApplyExtended(self.XmlPackageConfiguration,
                                     extendedProject.XmlPackageConfiguration,
                                     True)
                self.__ApplyExtended(self.XmlRootDirectories,
                                     extendedProject.XmlRootDirectories, False)
                self.__ApplyExtended(
                    self.XmlNewProjectTemplatesRootDirectories,
                    extendedProject.XmlNewProjectTemplatesRootDirectories,
                    False)
                self.__ApplyExtended(self.XmlBuildDocConfiguration,
                                     extendedProject.XmlBuildDocConfiguration,
                                     False)
                self.__ApplyExtended(
                    self.XmlClangFormatConfiguration,
                    extendedProject.XmlClangFormatConfiguration, False)
                self.__ApplyExtended(self.XmlCompilerConfiguration,
                                     extendedProject.XmlCompilerConfiguration,
                                     False)
                self.__ApplyExtendedExperimental(
                    self.XmlExperimental, extendedProject.XmlExperimental)

        if self.RootDirectory == LocalInvalidValues.INVALID_FILE_NAME:
            raise Exception("RootDirectory not configured")
        if self.DefaultCompany == LocalInvalidValues.INVALID_COMPANY_NAME:
            raise Exception("Default company not configured")
        if self.ToolConfigFile == LocalInvalidValues.INVALID_FILE_NAME:
            raise Exception("ToolConfigFile not configured")
        if self.SourceFileName == LocalInvalidValues.INVALID_FILE_NAME:
            raise Exception("SourceFileName not configured")
        if len(self.XmlBuildDocConfiguration) > 1:
            raise Exception(
                "There can only be one BuildDocConfiguration entry")
        if len(self.XmlClangFormatConfiguration) > 1:
            raise Exception(
                "There can only be one ClangFormatConfiguration entry")
        if len(self.XmlClangTidyConfiguration) > 1:
            raise Exception(
                "There can only be one ClangTidyConfiguration entry")
        if len(self.XmlCMakeConfiguration) > 1:
            raise Exception("There can only be one CMakeConfiguration entry")