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,
74 .GlobDirectories($
"{pathHash}_*")
75 .Where(p => !p.Name.Contains(contentHash.ToString()))
76 .ForEach(p => p.DeleteDirectory());
81 internal static AbsolutePath CompileProject(AbsolutePath projectPath, AbsolutePath outputDirIn)
83 ulong projectHash = xxHash64.ComputeHash(File.ReadAllText(projectPath));
84 ulong hash = projectPath.Parent.GlobFiles(
"**/*.cs")
85 .Aggregate(projectHash, (h, p) =>
86 h ^ xxHash64.ComputeHash(File.ReadAllText(p))
89 var dllName = projectPath.NameWithoutExtension;
90 var outputDir = outputDirIn / $
"{dllName}_{hash}";
91 var dllPath = outputDir / (dllName +
".dll");
93 if (outputDir.DirectoryExists() && dllPath.FileExists())
98 $
"Compiling project {projectPath}".Log();
100 outputDir.CreateOrCleanDirectory();
102 DotNetTasks.DotNetBuild(_ => _
104 .SetProjectFile(projectPath)
105 .SetOutputDirectory(outputDir)
106 .SetConfiguration(
"Debug")
107 .SetProcessWorkingDirectory(projectPath.Parent)
111 .GlobDirectories($
"{dllName}_*")
112 .Where(p => !p.Name.Contains(hash.ToString()))
113 .ForEach(p => p.DeleteDirectory());
121 internal static IEnumerable<Importable>
GetBuildInterfaces(
this Assembly assembly, AbsolutePath? sourcePath =
null,
bool importViaSource =
false)
122 => assembly.GetTypes()
123 .Where(t => t.IsInterface)
124 .Where(t => t.GetInterfaces().Any(i => i.FullName ==
"Nuke.Common.INukeBuild"))
125 .Select(t =>
new Importable(t, sourcePath, importViaSource));
127 internal static void Log(
this string text)
129 if (!Environment.CommandLine.Contains(
" :complete"))
131 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.