private static void StaticGraphToDScript(string graphFile, string graphDirectory, string outputDirectory) { StaticGraph graph = ReadStaticGraph(graphFile); PrintPips(graph, graphDirectory, outputDirectory); Mount everythingMount = new Mount { Name = "Everything", Path = Path.GetPathRoot(Path.GetFullPath(graph.ProjectPath)), IsReadable = true, IsWritable = true, TrackSourceFileChanges = true }; Mount srcMount = new Mount { Name = "Src", Path = Path.GetDirectoryName(graph.ProjectPath), IsReadable = true, IsWritable = false, TrackSourceFileChanges = true }; Mount objMount = new Mount { Name = "Obj", Path = Path.Combine(Path.GetDirectoryName(graph.ProjectPath), "obj"), IsReadable = true, IsWritable = true, TrackSourceFileChanges = true }; Mount outputMount = new Mount { Name = "Output", Path = outputDirectory, IsReadable = true, IsWritable = true, TrackSourceFileChanges = true }; Mount binMount = new Mount { Name = "Bin", Path = Path.Combine(Path.GetDirectoryName(graph.ProjectPath), "bin"), IsReadable = true, IsWritable = true, TrackSourceFileChanges = true }; List <Mount> mounts = new List <Mount>() { everythingMount, TaskLauncherMount, ProgramDataMount, BreadcrumbStoreMount, srcMount, objMount, binMount, outputMount }; WriteConfigDsc(graphDirectory, mounts); WriteModuleConfigDsc(graphDirectory); Console.WriteLine(@"%PKGDOMINO%\bxl.exe /c:" + graphDirectory + @"\config.dsc"); }
private static int PrintPips(StaticGraph graph, string outputFolder, string outputDirectory) { StringBuilder specContents = new StringBuilder(); specContents.AppendLine("import {Cmd, Transformer} from \"Sdk.Transformers\";\n"); specContents.AppendLine( string.Format("const tool: Transformer.ToolDefinition = {{ exe: f`{0}`, dependsOnWindowsDirectories: true, prepareTempDirectory: true, runtimeDirectoryDependencies: [ Transformer.sealSourceDirectory(d`{1}`, Transformer.SealSourceDirectoryOption.allDirectories) ] }};\n", System.Reflection.Assembly.GetExecutingAssembly().Location, Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))); var ser = new DataContractJsonSerializer(typeof(StaticTarget)); int i = 0; foreach (var target in graph.StaticTargets) { StringBuilder stdIn = new StringBuilder(); using (var stream = new MemoryStream()) { ser.WriteObject(stream, target); stream.Position = 0; using (StreamReader sr = new StreamReader(stream)) { string line; while ((line = sr.ReadLine()) != null) { stdIn.AppendLine(line); } } } List <string> inputs = new List <string>() { $"Transformer.sealSourceDirectory(d`{Environment.GetEnvironmentVariable("ProgramData")}`, Transformer.SealSourceDirectoryOption.allDirectories)" }; foreach (var inputId in target.InputFileIds ?? Enumerable.Empty <long>()) { var staticFile = graph.Files.First(file => file.Id == inputId); if (!staticFile.ProducingTargetId.HasValue) { inputs.Add($"f`{staticFile.Path}`"); } else { inputs.Add($"target{staticFile.ProducingTargetId}.getOutputFile(p`{staticFile.Path}`)"); } } foreach (var task in target.Tasks) { if (!string.IsNullOrWhiteSpace(task.AssemblyFile)) { inputs.Add($"f`{task.AssemblyFile}`"); } } List <string> outputs = new List <string>(); foreach (var outputId in target.OutputFileIds ?? Enumerable.Empty <long>()) { outputs.Add($"p`{graph.Files[(int)outputId].Path}`"); } var envVars = new List <(string, string)>() { ("ProgramData", Environment.GetEnvironmentVariable("ProgramData")) }; specContents.AppendLine( $@"const {"target" + target.Id} = Transformer.execute( {{ tool: tool, arguments: [ Cmd.rawArgument(""run"") ], consoleInput: ""{NormalizeRawString(stdIn.ToString())}"", description: ""{target.Name + "_" + NormalizeRawString(target.LocationString)}"", workingDirectory: d`{Path.GetDirectoryName(graph.ProjectPath)}`, unsafe: {{ passThroughEnvironmentVariables: [""MICROSOFT_BUILD_TASKLAUNCHER_DEBUG"", ""MSBUILDDEBUGONSTART""] }}, environmentVariables: [{string.Join(",\n", envVars.Select(envVar => $"\t{{ name: \"{envVar.Item1}\", value: \"{envVar.Item2}\" }}"))}], consoleOutput: p`{Path.Combine(outputDirectory, "target" + i + ".out")}`, dependencies: [ {string.Join(",\n\t\t", inputs)} ], implicitOutputs: [{string.Join(",\n\t\t", outputs)}] }}); "); i++; } string specFile = Path.Combine(outputFolder, "spec.dsc"); File.Delete(specFile); File.WriteAllText(specFile, specContents.ToString()); return(0); }