static bool TryCreateGitWorkingSet(DirectoryReference RootDir, DirectoryReference ProjectDir, out GitSourceFileWorkingSet OutWorkingSet) { GitSourceFileWorkingSet WorkingSet = null; // Create the working set for the engine directory if (DirectoryReference.Exists(DirectoryReference.Combine(RootDir, ".git"))) { WorkingSet = new GitSourceFileWorkingSet(GitPath, RootDir, WorkingSet); } // Try to create a working set for the project directory if (ProjectDir != null) { if (WorkingSet == null || !ProjectDir.IsUnderDirectory(RootDir)) { if (DirectoryReference.Exists(DirectoryReference.Combine(ProjectDir, ".git"))) { WorkingSet = new GitSourceFileWorkingSet(GitPath, ProjectDir, WorkingSet); } else if (DirectoryReference.Exists(DirectoryReference.Combine(ProjectDir.ParentDirectory, ".git"))) { WorkingSet = new GitSourceFileWorkingSet(GitPath, ProjectDir.ParentDirectory, WorkingSet); } } } // Set the output value OutWorkingSet = WorkingSet; return(WorkingSet != null); }
/// <summary> /// Constructor /// </summary> /// <param name="GitPath">Path to the Git executable</param> /// <param name="RootDir">Root directory to run queries from (typically the directory containing the .git folder, to ensure all subfolders can be searched)</param> /// <param name="Inner">An inner working set. This allows supporting multiple Git repositories (one containing the engine, another containing the project, for example)</param> public GitSourceFileWorkingSet(string GitPath, DirectoryReference RootDir, GitSourceFileWorkingSet Inner) { this.RootDir = RootDir; this.Files = new HashSet <FileReference>(); this.Directories = new List <DirectoryReference>(); this.ErrorOutput = new List <string>(); this.Inner = Inner; Log.WriteLine(LogEventType.Console, "Using 'git status' to determine working set for adaptive non-unity build ({0}).", RootDir); BackgroundProcess = new Process(); BackgroundProcess.StartInfo.FileName = GitPath; BackgroundProcess.StartInfo.Arguments = "status --porcelain"; BackgroundProcess.StartInfo.WorkingDirectory = RootDir.FullName; BackgroundProcess.StartInfo.RedirectStandardOutput = true; BackgroundProcess.StartInfo.RedirectStandardError = true; BackgroundProcess.StartInfo.UseShellExecute = false; BackgroundProcess.ErrorDataReceived += ErrorDataReceived; BackgroundProcess.OutputDataReceived += OutputDataReceived; try { BackgroundProcess.Start(); BackgroundProcess.BeginErrorReadLine(); BackgroundProcess.BeginOutputReadLine(); } catch { BackgroundProcess.Dispose(); BackgroundProcess = null; } }
/// <summary> /// Create an ISourceFileWorkingSet instance suitable for the given project or root directory /// </summary> /// <param name="RootDir">The root directory</param> /// <param name="ProjectDir">The current project</param> /// <returns>Working set instance for the given directory</returns> public static ISourceFileWorkingSet Create(DirectoryReference RootDir, DirectoryReference ProjectDir) { if (Provider == ProviderType.None || ProjectFileGenerator.bGenerateProjectFiles) { return(new EmptySourceFileWorkingSet()); } else if (Provider == ProviderType.Git) { GitSourceFileWorkingSet WorkingSet; if (!String.IsNullOrEmpty(RepositoryPath)) { WorkingSet = new GitSourceFileWorkingSet(GitPath, DirectoryReference.Combine(RootDir, RepositoryPath), null); } else if (!TryCreateGitWorkingSet(RootDir, ProjectDir, out WorkingSet)) { WorkingSet = new GitSourceFileWorkingSet(GitPath, RootDir, null); } return(WorkingSet); } else if (Provider == ProviderType.Perforce) { return(new PerforceSourceFileWorkingSet()); } else { GitSourceFileWorkingSet WorkingSet; if (TryCreateGitWorkingSet(RootDir, ProjectDir, out WorkingSet)) { return(WorkingSet); } else { return(new PerforceSourceFileWorkingSet()); } } }