private bool NeedsRebuilding(ProjectContext project, ProjectDependenciesFacade dependencies) { var compilerIO = GetCompileIO(project, dependencies); // rebuild if empty inputs / outputs if (!(compilerIO.Outputs.Any() && compilerIO.Inputs.Any())) { Reporter.Output.WriteLine($"Project {project.GetDisplayName()} will be compiled because it either has empty inputs or outputs"); return(true); } //rebuild if missing inputs / outputs if (AnyMissingIO(project, compilerIO.Outputs, "outputs") || AnyMissingIO(project, compilerIO.Inputs, "inputs")) { return(true); } // find the output with the earliest write time var minOutputPath = compilerIO.Outputs.First(); var minDateUtc = File.GetLastWriteTimeUtc(minOutputPath); foreach (var outputPath in compilerIO.Outputs) { if (File.GetLastWriteTimeUtc(outputPath) >= minDateUtc) { continue; } minDateUtc = File.GetLastWriteTimeUtc(outputPath); minOutputPath = outputPath; } // find inputs that are older than the earliest output var newInputs = compilerIO.Inputs.FindAll(p => File.GetLastWriteTimeUtc(p) >= minDateUtc); if (!newInputs.Any()) { Reporter.Output.WriteLine($"Project {project.GetDisplayName()} was previously compiled. Skipping compilation."); return(false); } Reporter.Output.WriteLine($"Project {project.GetDisplayName()} will be compiled because some of its inputs were newer than its oldest output."); Reporter.Verbose.WriteLine(); Reporter.Verbose.WriteLine($" Oldest output item:"); Reporter.Verbose.WriteLine($" {minDateUtc.ToLocalTime()}: {minOutputPath}"); Reporter.Verbose.WriteLine(); Reporter.Verbose.WriteLine($" Inputs newer than the oldest output item:"); foreach (var newInput in newInputs) { Reporter.Verbose.WriteLine($" {File.GetLastWriteTime(newInput)}: {newInput}"); } Reporter.Verbose.WriteLine(); return(true); }
private void StampProjectWithSDKVersion(ProjectContext project) { if (File.Exists(DotnetFiles.VersionFile)) { var projectVersionFile = project.GetSDKVersionFile(_args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue); var parentDirectory = Path.GetDirectoryName(projectVersionFile); if (!Directory.Exists(parentDirectory)) { Directory.CreateDirectory(parentDirectory); } File.Copy(DotnetFiles.VersionFile, projectVersionFile, true); } else { Reporter.Verbose.WriteLine($"Project {project.GetDisplayName()} was not stamped with a CLI version because the version file does not exist: {DotnetFiles.VersionFile}"); } }
private static bool AnyMissingIO(ProjectContext project, IEnumerable <string> items, string itemsType) { var missingItems = items.Where(i => !File.Exists(i)).ToList(); if (!missingItems.Any()) { return(false); } Reporter.Verbose.WriteLine($"Project {project.GetDisplayName()} will be compiled because expected {itemsType} are missing."); foreach (var missing in missingItems) { Reporter.Verbose.WriteLine($" {missing}"); } Reporter.Verbose.WriteLine();; return(true); }