def __init__(self, log: Log, xmlElement: ET.Element,
                 filename: str) -> None:
        super().__init__(log, xmlElement)
        #raise Exception("ExtendedProject not implemented");
        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

        variableProcessor = VariableProcessor(log)
        self.AbsoluteParentConfigFilename = variableProcessor.ResolveAbsolutePathWithLeadingEnvironmentVariablePath(
            self.ParentConfigFilename)
        self.XmlPackageConfiguration = _LoadPackageConfigurations(
            log, xmlElement,
            filename)  # type: List[XmlConfigPackageConfiguration]
        self.XmlRootDirectories = _LoadAddRootDirectory(
            log, xmlElement,
            filename)  # 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.XmlCompilerConfiguration = _LoadCompilerConfiguration(
            log, xmlElement,
            filename)  # type: List[XmlConfigCompilerConfiguration]
        self.XmlExperimental = _TryLoadExperimental(
            log, xmlElement, filename)  # type: Optional[XmlExperimental]
    def __init__(
            self, basicConfig: BasicConfig,
            basedUponXML: XmlConfigFileAddTemplateImportDirectory) -> None:
        super().__init__()

        self.BasedOn = basedUponXML
        self.Name = self.BasedOn.Name

        variableProcessor = VariableProcessor(basicConfig)

        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TrySplitLeadingEnvironmentVariablesNameAndPath(
            self.Name)
        envName = tupleResult[0]
        rest = tupleResult[1]
        if envName is None:
            raise Exception(
                "Template import dirs are expected to contain environment variables"
            )
        rest = rest if rest is not None else ""

        self.DecodedName = envName
        self.BashName = IOUtil.Join('$' + self.DecodedName, rest)
        self.DosName = IOUtil.Join('%' + self.DecodedName + '%', rest)
        if self.Name is None:
            raise XmlException2(
                basedUponXML.XmlElement,
                "Dirs are expected to contain environment variables")
        self.ResolvedPath = IOUtil.Join(
            IOUtil.GetEnvironmentVariableForDirectory(self.DecodedName), rest)
        self.ResolvedPathEx = "{0}/".format(
            self.ResolvedPath) if len(self.ResolvedPath) > 0 else ""
    def __init__(
        self, basicConfig: BasicConfig,
        basedUponXML: XmlConfigFileAddNewProjectTemplatesRootDirectory
    ) -> None:
        super().__init__()
        self.BasedOn = basedUponXML
        self.Id = basedUponXML.Id
        self.Name = basedUponXML.Name
        self.DynamicName = basedUponXML.Name

        variableProcessor = VariableProcessor(basicConfig)

        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, True)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "Root dirs are expected to contain environment variables '{0}'"
                .format(self.DynamicName))
        remainingPath = remainingPath if remainingPath is not None else ""

        resolvedPath = IOUtil.GetEnvironmentVariableForDirectory(
            env) + remainingPath
        self.BashName = '${0}{1}'.format(env, remainingPath)
        self.DosName = '%{0}%{1}'.format(env, remainingPath)
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)
        self.ResolvedPathEx = "{0}/".format(
            self.ResolvedPath) if len(self.ResolvedPath) > 0 else ""
        self.__EnvironmentVariableName = env
Exemple #4
0
    def __TryCreateReadonlyCache(
        self, log: Log, basedUponXML: Optional[
            XmlExperimentalDefaultThirdPartyInstallReadonlyCacheDirectory]
    ) -> Optional[ToolConfigExperimentalDefaultThirdPartyInstallDirectory]:
        entryName = "DefaultThirdPartyInstallReadonlyCacheDirectory"
        if basedUponXML is None:
            raise Exception(
                "No '{0}' was defined in the xml".format(entryName))

        variableProcessor = VariableProcessor(log)
        env = variableProcessor.TryExtractLeadingEnvironmentVariableName(
            basedUponXML.Name, False)
        if env is None:
            raise Exception(
                "The {0} is expected to contain a environment variable '{1}'".
                format(entryName, basedUponXML.Name))

        resolvedPath = IOUtil.TryGetEnvironmentVariable(env)
        if resolvedPath is None:
            log.LogPrintVerbose(
                2,
                "Read only cache environment variable {0} not set, disabling cache"
                .format(env))
            return None

        return ToolConfigExperimentalDefaultThirdPartyInstallDirectory(
            log, basedUponXML, entryName, True)
    def __init__(self, basicConfig: BasicConfig,
                 basedUponXML: XmlConfigFileTemplateFolder) -> None:
        super().__init__()
        self.BasedOn = basedUponXML
        self.Name = self.BasedOn.Name

        variableProcessor = VariableProcessor(basicConfig)

        self.ResolvedPath = variableProcessor.ResolveAbsolutePathWithLeadingEnvironmentVariablePathAsDir(
            self.Name)
Exemple #6
0
    def __init__(self,
                 log: Log,
                 basedUponXML: Optional[XmlConfigFileAddRootDirectory],
                 projectId: ProjectId,
                 dynamicSourceRootDir: Union[
                     Optional[XmlConfigFileAddRootDirectory],
                     Optional['ToolConfigRootDirectory']] = None,
                 dynamicRootName: Optional[str] = None,
                 dynamicPath: Optional[str] = None) -> None:
        super().__init__()
        dirMustExist = True
        self.ProjectId = projectId
        if basedUponXML is not None:
            self.BasedOn = basedUponXML  # type: Union[XmlConfigFileAddRootDirectory, 'ToolConfigRootDirectory']
            self.Name = basedUponXML.Name  # type: str
            self.DynamicName = basedUponXML.Name  # type: str
            dirMustExist = not basedUponXML.Create
        else:
            if dynamicSourceRootDir is None:
                raise Exception("dynamicSourceRootDir can not be none")
            if dynamicRootName is None:
                raise Exception("dynamicRootName can not be none")
            if dynamicPath is None:
                raise Exception("dynamicPath can not be none")
            self.BasedOn = dynamicSourceRootDir
            self.Name = dynamicRootName
            self.DynamicName = dynamicPath
        variableProcessor = VariableProcessor(log)
        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, dynamicSourceRootDir != None)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "Root dirs are expected to contain environment variables '{0}'"
                .format(self.DynamicName))
        remainingPath = remainingPath if remainingPath is not None else ""

        resolvedPath = IOUtil.GetEnvironmentVariableForDirectory(
            env, dirMustExist)
        if not IOUtil.Exists(resolvedPath):
            IOUtil.SafeMakeDirs(resolvedPath)
        if not IOUtil.IsDirectory(resolvedPath):
            raise EnvironmentError(
                "The {0} environment variable content '{1}' does not point to a valid directory"
                .format(env, resolvedPath))

        resolvedPath = resolvedPath + remainingPath
        self.BashName = '${0}{1}'.format(env, remainingPath)  # type: str
        self.DosName = '%{0}%{1}'.format(env, remainingPath)  # type: str
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)  # type: str
        self.ResolvedPathEx = "{0}/".format(self.ResolvedPath) if len(
            self.ResolvedPath) > 0 else ""  # type: str
        self.__EnvironmentVariableName = env  # type: str
Exemple #7
0
    def __init__(self, log: Log, platformName: str,
                 generatorName: str,
                 compilerGeneratorName: str, recipeBuilderSetup: Optional[RecipeBuilderSetup]) -> None:
        super().__init__(log)

        self.HostPlatformName = self.__DetermineHostPlatformName(platformName)
        self.PlatformName = platformName # type: str
        self.GeneratorName = generatorName # type: str
        self.GeneratorCompilerName = compilerGeneratorName # type: str
        self.VariableProcessor = VariableProcessor(log)
        self.PathBuilder = PathBuilder(log, self.VariableProcessor, platformName)
        self.RecipePathBuilder = RecipePathBuilder(log, self.VariableProcessor, recipeBuilderSetup, platformName, compilerGeneratorName)
Exemple #8
0
    def __init__(self, log: Log, basedUponXML: Optional[
        Union[XmlExperimentalDefaultThirdPartyInstallDirectory,
              XmlExperimentalDefaultThirdPartyInstallReadonlyCacheDirectory]],
                 entryName: str, isReadonlyCache: bool) -> None:
        super(ToolConfigExperimentalDefaultThirdPartyInstallDirectory,
              self).__init__()

        if basedUponXML is None:
            raise Exception(
                "No '{0}' was defined in the xml".format(entryName))

        self.__Log = log  # type: Log
        self.BasedOn = basedUponXML
        self.Name = basedUponXML.Name  # type: str
        self.DynamicName = basedUponXML.Name  # type: str
        self.IsReadonlyCache = isReadonlyCache  # type: bool

        variableProcessor = VariableProcessor(log)

        # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575
        tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath(
            self.DynamicName, False)
        env = tupleResult[0]
        remainingPath = tupleResult[1]
        if env is None:
            raise Exception(
                "The {0} is expected to contain a environment variable '{1}'".
                format(entryName, self.DynamicName))

        resolvedPath = self.__GetEnvironmentVariable(env)

        self.__EnvironmentVariableName = env  # type: str
        self.BashName = '${0}{1}'.format(env, remainingPath)  # type: str
        self.DosName = '%{0}%{1}'.format(env, remainingPath)  # type: str
        self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath)  # type: str
        self.ResolvedPathEx = "{0}/".format(self.ResolvedPath) if len(
            self.ResolvedPath) > 0 else ""  # type: str
    def __init__(self, log: Log, errorHelpManager: ErrorHelpManager,
                 platformName: str, generatorName: str,
                 generatorInfo: GeneratorInfo,
                 cmakeConfig: GeneratorCMakeConfig,
                 recipeBuilderSetup: Optional[RecipeBuilderSetup]) -> None:
        super().__init__(log)

        self.ErrorHelpManager = errorHelpManager
        self.HostPlatformName = self.__DetermineHostPlatformName(platformName)
        self.PlatformName = platformName  # type: str
        self.GeneratorName = generatorName  # type: str
        self.GeneratorInfo = generatorInfo
        self.CMakeConfig = cmakeConfig
        self.VariableProcessor = VariableProcessor(log)
        self.PathBuilder = PathBuilder(log, self.VariableProcessor,
                                       platformName)
        self.RecipePathBuilder = RecipePathBuilder(log, self.VariableProcessor,
                                                   recipeBuilderSetup,
                                                   platformName, cmakeConfig)
    def __LoadFromXml(self,
                      log: Log,
                      xmlElement: ET.Element,
                      filename: str,
                      canExtend: bool = True) -> None:
        self.Version = '1'  # type: str
        self.RootDirectory = LocalInvalidValues.INVALID_FILE_NAME  # type: str
        self.DefaultPackageLanguage = PackageLanguage.CPP  # type: int
        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.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
                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.XmlRootDirectories = _LoadAddRootDirectory(
                    log, projectElem, filename)
                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.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")