def __init__(self, config: Config, packages: List[Package], dstMakeFilename: str, templateExe: str, templateLib: str) -> None:
     super().__init__()
     self.BldTemplate = IOUtil.ReadFile(IOUtil.Join(config.SDKConfigTemplatePath, "build.sh"))
     self.TemplateMakefileCPU = IOUtil.ReadFile(IOUtil.Join(config.SDKConfigTemplatePath, "QNXmakefileCPU"))
     self.TemplateMakefileVariant = IOUtil.ReadFile(IOUtil.Join(config.SDKConfigTemplatePath, "QNXmakefileVariant"))
     self.TemplateCommonMk = IOUtil.ReadFile(IOUtil.Join(config.SDKConfigTemplatePath, "QNXcommonmk"))
     self.TemplateMakefileTop = IOUtil.ReadFile(IOUtil.Join(config.SDKConfigTemplatePath, "QNXmakefileTop"))
     for package in packages:
         if not package.ResolvedPlatformNotSupported:
             if package.Type == PackageType.Executable or package.Type == PackageType.Library:
                 self.__GenerateFolderStructure(config, package)
Ejemplo n.º 2
0
 def GetVersionStringFromSourceProperties(sdkPath: str) -> str:
     filePath = IOUtil.Join(sdkPath, 'source.properties')
     content = IOUtil.ReadFile(filePath)
     searchString = 'Pkg.Revision'
     index = content.find(searchString)
     if index < 0:
         raise Exception(
             "source.properties at '{0} did not contain the expected '{1}' entry"
             .format(filePath, searchString))
     index += len(searchString)
     endIndex = content.find('\n', index)
     endIndex = endIndex if endIndex >= index else len(content)
     content = content[index:endIndex]
     content = content.strip()
     if len(content) <= 0:
         raise Exception(
             "Failed to retrieve version from '{0}' entry".format(filePath))
     if content[0] != '=':
         raise Exception(
             "source.properties at '{0} did not contain the expected '{1}=' entry"
             .format(filePath, searchString))
     content = content[1:len(content)].strip()
     if not AndroidUtil.IsValidVersionString(content):
         raise Exception(
             "Failed to retrieve version from '{0}' entry as was in a unexpected format"
             .format(filePath))
     return content
 def __init__(self, templatePath: str) -> None:
     super().__init__()
     fileEnvironmentBasedRootVariable = IOUtil.Join(
         templatePath,
         "CMakeAndroid/DefineEnvironmentBasedRootVariable.txt")
     self.DefineEnvironmentBasedRootVariable = IOUtil.ReadFile(
         fileEnvironmentBasedRootVariable)
Ejemplo n.º 4
0
 def __DoReadFile(self, absoluteTemplatePath: str, overrideDirName: str, filename: str) -> str:
     templateFilename = IOUtil.Join(absoluteTemplatePath, "{0}/{1}".format(overrideDirName, filename))
     res = IOUtil.TryReadFile(templateFilename)
     if res is None:
         templateFilename = IOUtil.Join(absoluteTemplatePath, filename)
         res = IOUtil.ReadFile(templateFilename)
     return res
 def __ParseExeFileList(self, path: str) -> List[str]:
     lines = IOUtil.ReadFile(path).split('\n')
     result = []
     for line in lines:
         line = line.strip()
         if len(line) > 0 and not line.startswith("#"):
             result.append(line)
     return result
 def __init__(self, config: Config, packages: List[Package],
              dstMakeFilename: str, templateExe: str, templateLib: str,
              generatorName: str) -> None:
     super(GeneratorGNUmakefile, self).__init__()
     self.BldTemplate = IOUtil.ReadFile(
         IOUtil.Join(config.SDKConfigTemplatePath, "build.sh"))
     self.ExeTemplate = IOUtil.ReadFile(
         IOUtil.Join(config.SDKConfigTemplatePath, templateExe))
     self.LibTemplate = IOUtil.ReadFile(
         IOUtil.Join(config.SDKConfigTemplatePath, templateLib))
     for package in packages:
         if not package.ResolvedPlatformNotSupported:
             if package.Type == PackageType.Library:
                 self.__GenerateLibraryBuildFile(config, generatorName,
                                                 package, dstMakeFilename)
             elif package.Type == PackageType.Executable:
                 self.__GenerateExecutableBuildFile(config, generatorName,
                                                    package,
                                                    dstMakeFilename)
Ejemplo n.º 7
0
 def __init__(self, package: Package, fileName: str) -> None:
     super(SourceFile, self).__init__()
     self.Package = package
     self.FileName = fileName
     self.Content = IOUtil.ReadFile(fileName)
     lines = self.Content.split('\n')
     self.LinesOriginal = [line.rstrip() for line in lines]
     self.BasePath = self.__TryDetermineFileBasePath(package, fileName) # type: Optional[str]
     self.LinesModded = list(self.LinesOriginal)
     self.__NormalizeTrailingEndingLines(self.LinesModded)
     if len(self.LinesModded[len(self.LinesModded)-1]) != 0:
         raise Exception("Not ending with a empty line")
 def _TryLoadConfigJson(configFile: str) -> Dict[str, str]:
     strConfigJson = IOUtil.ReadFile(configFile)
     jsonDict = json.loads(strConfigJson)
     if not isinstance(jsonDict, dict):
         raise Exception(
             "Incorrect configuration json file: '{0}'".format(configFile))
     finalDict = {}  # type: Dict[str,str]
     for key, value in jsonDict.items():
         if not isinstance(key, str) or not isinstance(value, str):
             raise Exception(
                 "Incorrect configuration json file: '{0}'. Json decode failed"
                 .format(configFile))
         finalDict[key] = value
     return finalDict
Ejemplo n.º 9
0
    def __Load(self, log: Log, path: str) -> None:
        if not os.path.exists(path):
            return
        content = IOUtil.ReadFile(path)

        self.Dirs = {}
        self.Entries = {}
        self.Removed = {}
        self.IsNew = True
        cacheHeader = GetCacheHeader()
        # if the file starts with a invalid header, we ignore it
        if not content.startswith(cacheHeader):
            log.LogPrint("Cache header invalid, ignoring cache")
            return

        entries = []  # type: List[ContentState]
        dirs = []
        lines = content.splitlines(False)
        if len(lines) < 3:
            log.LogPrintWarning("Cache at '{0}' is invalid, ignoring it.".format(path))
            return
        for line in lines:
            line = line.strip()
            if not line.startswith('#'):
                elements = line.split(GLOBAL_SEP)
                if len(elements) != 5:
                    log.LogPrint("Cache entry invalid, ignoring cache")
                    return
                contentState = ContentState()
                contentState.Name = elements[0]
                contentState.Length = int(elements[1])
                contentState.ModifiedDate = elements[2]
                contentState.Checksum = elements[3]
                contentState.TagChecksum = elements[4]
                if contentState.Length >= 0:
                    entries.append(contentState)
                else:
                    dirs.append(contentState)

        for entry in entries:
            self.Add(entry)
        for entry in dirs:
            self.AddDir(entry)
        self.IsNew = False
    def __CopyAndModifyFiles(self, config: Config,
                             dstPath: str,
                             filesToModify: List[TemplateFileRecord],
                             dstFilenameModifier: Optional[Callable[[str], str]]) -> None:
        for file in filesToModify:
            if not self.GenFileOnly or file.FileName == config.ToolConfig.GenFileName:
                dstFilename = IOUtil.Join(dstPath, file.RelativeDestPath)
                content = IOUtil.ReadFile(file.AbsoluteSourcePath)

                # Replace various strings using the 'template environment'
                for key, value in self.Environment.Dict.items():
                    strValue = "" if value is None else value
                    content = content.replace(key, strValue)
                    dstFilename = dstFilename.replace(key, strValue)

                if dstFilenameModifier is not None:
                    dstFilename = dstFilenameModifier(dstFilename)

                dirName = IOUtil.GetDirectoryName(dstFilename)
                if not config.DisableWrite:
                    IOUtil.SafeMakeDirs(dirName)
                    IOUtil.WriteFileIfChanged(dstFilename, content)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
def ReadJsonFile(filename: str) -> JsonDictType:
    content = IOUtil.ReadFile(filename)
    return cast(JsonDictType, json.loads(content))
    def __init__(self, log: Log, template: XmlNewVSProjectTemplateFile,
                subDirectory: str, vsVersion: int, useLinuxTools: bool,
                customization: XmlNewVSProjectTemplateCustomizationFile) -> None:
        super().__init__()
        strVSPath = template.Path

        strTemplatePath = IOUtil.Join(strVSPath, subDirectory)
        strTemplateSolutionPath = IOUtil.Join(strTemplatePath, "Template_sln")
        strTemplateProjectPath = IOUtil.Join(strTemplatePath, "Template_{0}".format(template.Template.ProjectExtension))
        strTemplateFilterPath = IOUtil.Join(strTemplatePath, "Template_filters")

        strTemplateNuGetPackageConfigPath = IOUtil.Join(strTemplatePath, "Template_packages_config")

        self.BuildOutputLocation = customization.BuildOutput.Location
        self.FilterExtension = "vcxproj.filters"
        self.SolutionExtension = "sln"
        self.ProjectExtension = template.Template.ProjectExtension

        self.TemplateFileRecordManager = TemplateFileRecordManager(strTemplatePath)

        nuGetPackageConfig = IOUtil.TryReadFile(IOUtil.Join(strTemplateNuGetPackageConfigPath, "Master.txt"))
        self.NuGetPackageConfig = NuGetPackageConfigSnippets(log, strTemplateNuGetPackageConfigPath, nuGetPackageConfig) if nuGetPackageConfig is not None else None

        self.TemplateSLN = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Master.txt"))
        self.SLNAddProject = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "AddProject.txt"))
        self.SLNSnippet1 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet1.txt"))
        self.SLNSnippet2 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet2.txt"))
        self.Master = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "Master.txt"))
        self.VariantProjectConfiguration = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantProjectConfiguration.txt"))
        self.ProjectReferences = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "ProjectReferences.txt"))
        self.ProjectReferences_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "ProjectReferences_1.txt"))
        self.PackageReferences = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "PackageReferences.txt"))
        self.PackageReferences_1 = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "PackageReferences_1.txt"))
        self.AssemblyReferenceSimple = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceSimple.txt"))
        self.AssemblyReferenceComplex = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceComplex.txt"))
        self.AssemblyReferenceComplex_Private = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceComplex_Private.txt"))
        self.AddHeaderFile = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "AddHeaderFile.txt"))
        self.AddSourceFile = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "AddSourceFile.txt"))
        self.AddNatvisFile = self.SafeReadFile(IOUtil.Join(strTemplateProjectPath, "AddNatvisFile.txt"), "")
        self.VariantConfiguration = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantConfiguration.txt"))
        self.VariantPropertySheets = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantPropertySheets.txt"))
        self.VariantPropertyGroups = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantPropertyGroups.txt"))
        self.VariantCompilerSettings = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings.txt"))
        self.VariantCompilerSettings_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings_1.txt"))
        self.VariantCompilerSettings_2 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings_2.txt"))
        self.WindowsTargetPlatformVersion = self.SafeReadFile(IOUtil.Join(strTemplateProjectPath, "WindowsTargetPlatformVersion.txt"), "")
        externalFileToOutput = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "ExternalFileToOutput.txt"))
        self.ExternalFileToOutput = "" if externalFileToOutput is None else externalFileToOutput
        copyFileToFolders = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "CopyFileToFolders.txt"))
        self.CopyFileToFolders = ""
        self.CopyFileToFoldersCopyConditions = ""
        if copyFileToFolders is not None:
            self.CopyFileToFolders = copyFileToFolders
            self.CopyFileToFoldersCopyConditions = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CopyFileToFolders_CopyConditions.txt"))
        self.Snippet9 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CustomBuildFiles.txt"))
        self.Snippet9_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CustomBuildFiles_1.txt"))

        # Filter master file
        self.FilterMaster = IOUtil.TryReadFile(IOUtil.Join(strTemplateFilterPath, "master.txt"))
        self.FilterItemGroup = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "itemgroup.txt"), "")
        self.FilterItemGroupNatvis = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "itemgroup_natvis.txt"), "")
        self.FilterItemHeader = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_header.txt"), "")
        self.FilterItemShader = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_shader.txt"), "")
        self.FilterItemSource = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_source.txt"), "")

        self.DebugOptimizations = {}  # type: Dict[int, TemplateOptimizationSetting]
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Disabled, strVSPath, "DEBUG", "disabled")
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Default, strVSPath, "DEBUG", "disabled")
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Full, strVSPath, "DEBUG", "full")

        snippet3FileName = IOUtil.Join(strTemplateSolutionPath, "Snippet3.txt")
        if IOUtil.IsFile(snippet3FileName):
            self.SLNSnippet3 = IOUtil.ReadFile(snippet3FileName)
            self.SLNSnippet4 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet4.txt"))
            self.SLNSnippet4_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet4_1.txt"))
        else:
            self.SLNSnippet3 = ""
            self.SLNSnippet4 = ""
            self.SLNSnippet4_1 = ""
 def __init__(self, log: Log, path: str, master: str) -> None:
     super().__init__()
     self.Master = master
     self.PackageEntry = IOUtil.ReadFile(IOUtil.Join(path, "PackageEntry.txt"))
    def __init__(self, config: Config, strTemplatePath: str, filePrefix: str,
                 hasManifest: bool) -> None:
        super(CodeTemplateCMake, self).__init__()
        self.TemplatePath = strTemplatePath
        self.AbsoluteTemplatePath = IOUtil.Join(config.SDKConfigTemplatePath,
                                                strTemplatePath)
        self.Master = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "{0}CMakeLists.txt".format(filePrefix)))
        self.PackageTargetIncludeDirectories = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "Package_TargetIncludeDirectories.txt"))
        self.PackageTargetIncludeDirEntry = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "Package_TargetIncludeDirEntry.txt"))
        self.PackageDependencyAddSubdirectories = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "PackageDependency_add_subdirectories.txt"))
        self.PackageDependencyTargetLinkLibraries = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "PackageDependency_target_link_libraries.txt"))
        self.PackageDependencyTargetCompileDefinitions = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "PackageDependency_target_compile_definitions.txt"))
        self.PackageDependencyFindPackage = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "PackageDependency_find_package.txt"))
        self.SnippetDefaultTargetCompileOptions = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "Snippet_DefaultTargetCompileOptions.txt"))
        self.SnippetDefaultTargetCompileFeatures = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath,
                        "Snippet_DefaultTargetCompileFeatures.txt"))
        self.AddImportedLibrary = IOUtil.ReadFile(
            IOUtil.Join(self.AbsoluteTemplatePath, "AddImportedLibrary.txt"))

        if filePrefix == 'Ext':
            self.PackageTargetIncludeDirectories = IOUtil.ReadFile(
                IOUtil.Join(
                    self.AbsoluteTemplatePath,
                    "{0}Package_TargetIncludeDirectories.txt".format(
                        filePrefix)))
        else:
            self.PackageTargetIncludeDirectories = IOUtil.ReadFile(
                IOUtil.Join(self.AbsoluteTemplatePath,
                            "Package_TargetIncludeDirectories.txt"))