def CreateDefineRootDirectoryEnvironmentAsVariables(
        toolConfig: ToolConfig, projectContext: ToolConfigProjectContext,
        includeParents: bool, snippet: str) -> str:
    allProjectContextRootDirs = []  # List[ToolConfigRootDirectory]
    context = projectContext  # type: Optional[ToolConfigProjectContext]
    while context is not None:
        rootDir = toolConfig.TryFindRootDirectory(
            context.Location.ResolvedPath)
        if rootDir is None:
            raise Exception("could not locate root directory")
        allProjectContextRootDirs.append(rootDir)
        context = context.ParentContext if includeParents else None

    allRootDirs = []  # List[ToolConfigRootDirectory]
    for entry in allProjectContextRootDirs:
        allRootDirs.append(entry)
        for rootDir in toolConfig.RootDirectories:
            if entry != rootDir and entry.ProjectId == rootDir.ProjectId:
                allRootDirs.append(rootDir)

    allRootDirs.sort(key=lambda s: s.Name.lower())
    result = []  # List[str]
    for entry in allRootDirs:
        content = snippet
        content = content.replace("##ENVIRONMENT_VARIABLE_NAME##",
                                  entry.GetEnvironmentVariableName())
        result.append(content)
    return "\n\n".join(result)
Example #2
0
    def TryFindClosestFileInRoot(log: Log, toolConfig: ToolConfig,
                                 startDirectory: str,
                                 findFilename: str) -> Optional[str]:
        foundPath = IOUtil.TryFindFileInCurrentOrParentDir(
            startDirectory, findFilename)
        if foundPath is None:
            return None

        foundDir = IOUtil.GetDirectoryName(foundPath)
        rootDir = toolConfig.TryFindRootDirectory(foundDir)
        return foundDir if rootDir is not None else None
Example #3
0
    def FindClosestFileInRoot(log: Log, toolConfig: ToolConfig,
                              startDirectory: str, findFilename: str) -> str:
        foundPath = FileFinder.LocateFileInParentTree(log, startDirectory,
                                                      findFilename)
        foundDir = IOUtil.GetDirectoryName(foundPath)

        rootDir = toolConfig.TryFindRootDirectory(foundDir)
        if rootDir is None:
            raise Exception(
                "Could not find a '{0}' file inside the project root".format(
                    findFilename))
        return foundDir
Example #4
0
    def __init__(self, toolConfig: ToolConfig, packageBuildPath: str,
                 contentBuildPath: str, contentPathPath: str) -> None:
        super().__init__()
        self.PackageBuild = packageBuildPath
        self.ContentBuild = contentBuildPath
        self.Content = contentPathPath

        rootDir = toolConfig.TryFindRootDirectory(packageBuildPath)
        if rootDir is None:
            raise Exception(
                "Could not find a project root for the path '{0}'".format(
                    packageBuildPath))
        self.ProjectRoot = rootDir.ResolvedPath  # type: str
Example #5
0
def GetAddExtendedPackageParent(toolConfig: ToolConfig, projectContext: ToolConfigProjectContext, snippet: str) -> str:
    parentContext = projectContext.ParentContext
    if parentContext is None:
        return ""

    rootDir = toolConfig.TryFindRootDirectory(parentContext.Location.ResolvedPath)
    if rootDir is None:
        raise Exception("could not locate root directory")

    content = snippet
    content = content.replace("##PARENT_NAME##", parentContext.ProjectName)
    content = content.replace("##PARENT_ROOT##", "${{{0}}}".format(rootDir.GetEnvironmentVariableName()))
    return content