24 private static LogFactory? DotnetScriptLogFactoryInstance =
null;
25 private static LogFactory DotnetScriptLogFactory => DotnetScriptLogFactoryInstance
26 ??=
new(type => (level, message, except) =>
28 if (level > LogLevel.Debug)
32 internal static ScriptDllLocation GetDllLocationOfScript(AbsolutePath scriptPath, AbsolutePath outputDirIn)
34 uint pathHash = xxHash32.ComputeHash(scriptPath);
35 ulong hash = xxHash64.ComputeHash(scriptPath.ReadAllText());
36 var dllName = hash.ToString();
37 var outputDir = outputDirIn / (pathHash.ToString() +
"_" + dllName);
38 return new(outputDir / (dllName +
".dll"), hash, pathHash);
51 internal static AbsolutePath
CompileScript(AbsolutePath scriptPath, AbsolutePath outputDirIn)
53 var (dllPath, contentHash, pathHash) = GetDllLocationOfScript(scriptPath, outputDirIn);
55 if (dllPath.FileExists())
58 $
"Compiling script {scriptPath}".Log();
60 dllPath.Parent.CreateOrCleanDirectory();
61 new PublishCommand(ScriptConsole.Default, DotnetScriptLogFactory).Execute(
new(
64 contentHash.ToString(),
66 OptimizationLevel.Debug,
68 ScriptEnvironment.Default.RuntimeIdentifier,
75 .GlobDirectories($
"{pathHash}_*")
76 .Where(p => !p.Name.Contains(contentHash.ToString()))
77 .ForEach(p => p.DeleteDirectory());
82 internal static AbsolutePath CompileProject(AbsolutePath projectPath, AbsolutePath outputDirIn)
84 ulong projectHash = xxHash64.ComputeHash(File.ReadAllText(projectPath));
85 ulong hash = projectPath.Parent.GlobFiles(
"**/*.cs")
86 .Aggregate(projectHash, (h, p) =>
87 h ^ xxHash64.ComputeHash(File.ReadAllText(p))
90 var dllName = projectPath.NameWithoutExtension;
91 var outputDir = outputDirIn / $
"{dllName}_{hash}";
92 var dllPath = outputDir / (dllName +
".dll");
94 if (outputDir.DirectoryExists() && dllPath.FileExists())
99 $
"Compiling project {projectPath}".Log();
101 outputDir.CreateOrCleanDirectory();
103 DotNetTasks.DotNetBuild(_ => _
105 .SetProjectFile(projectPath)
106 .SetOutputDirectory(outputDir)
107 .SetConfiguration(
"Debug")
108 .SetProcessWorkingDirectory(projectPath.Parent)
112 .GlobDirectories($
"{dllName}_*")
113 .Where(p => !p.Name.Contains(hash.ToString()))
114 .ForEach(p => p.DeleteDirectory());
122 internal static IEnumerable<Importable>
GetBuildInterfaces(
this Assembly assembly, AbsolutePath? sourcePath =
null,
bool importViaSource =
false)
123 => assembly.GetTypes()
124 .Where(t => t.IsInterface)
125 .Where(t => t.GetInterfaces().Any(i => i.FullName ==
"Nuke.Common.INukeBuild"))
126 .Select(t =>
new Importable(t, sourcePath, importViaSource));
128 internal static void Log(
this string text)
130 if (!Environment.CommandLine.Contains(
" :complete"))
132 Console.WriteLine(text);
static IEnumerable< Importable > GetBuildInterfaces(this Assembly assembly, AbsolutePath? sourcePath=null, bool importViaSource=false)
Get the build interfaces of an input assembly inheriting Nuke.Common.INukeBuild.