61 BuildContext context =
new(NukeBuild.TemporaryDirectory, NukeBuild.RootDirectory);
62 var intermediateScriptPath = context.Temporary /
"Intermediate.csx";
63 var intermediateAssembliesRoot = context.Temporary /
"IntermediateAssemblies";
64 var noPluginsFoundIndicator = context.Temporary /
"NoPlugins.txt";
66 if (AttemptReuseCompiledPlugins())
68 if (noPluginsFoundIndicator.FileExists())
70 $
"Skipped building build plugins entirely. Executing build from {typeof(T).Name}".Log();
71 return defaultExecute();
74 if (intermediateScriptPath.FileExists())
76 var (dllPath, _, _) =
DotnetCommon.GetDllLocationOfScript(
77 intermediateScriptPath,
78 intermediateAssembliesRoot
80 if (dllPath.FileExists())
82 "Reusing plugins which has been already compiled.".Log();
83 return ExecuteExternal(dllPath);
88 noPluginsFoundIndicator.ExistingFile()?.DeleteFile();
97 foreach(var engine
in engines)
99 engine.InitializeEngine(context);
102 var sources = engines
103 .SelectMany(e => e.GatherPlugins(context))
104 .ForEachLazy(p => $
"Using plugin {p.SourcePath}".Log())
107 if (sources.IsEmpty())
109 $
"No build plugins were found. Executing build from {typeof(T).Name}".Log();
110 noPluginsFoundIndicator.WriteAllText(
"1");
111 return defaultExecute();
114 sources.AsParallel().ForAll(s => s.Compile(context));
116 var buildInterfaces = sources.SelectMany(s => s.BuildInterfaces);
117 var assemblyPaths = buildInterfaces
118 .DistinctBy(i => i.ToString());
120 var dllRefs =
string.Join(
123 .Where(p => p.Source !=
null)
124 .Select(p => p.ImportViaSource
125 ? $
"\n// dll: {p.Interface.Assembly.Location}\n#load \"{p}\""
129 var interfaces =
string.Join(
", ", buildInterfaces.Select(i => GetCSharpName(i.Interface)));
130 var baseName = GetCSharpName(typeof(T));
131 var currentAssembly = Assembly.GetEntryAssembly()?.Location;
133 Assert.NotNull(currentAssembly);
135 var intermediateScriptSource =
137 #r "nuget: System.Linq.Expressions, 4.3.0
"
138 #r "{{currentAssembly}}
"
141 public class {{OutputBuildClass}} : {{baseName}}, {{interfaces}}
143 public static int {{ExecuteWithPlugins}}() => Execute<{{OutputBuildClass}}>();
147 File.WriteAllText(intermediateScriptPath, intermediateScriptSource);
150 "Preparing intermediate assembly".Log();
151 return ExecuteExternal(