From e9c529d1a1075ee604b625517662aebe2794e78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Fri, 15 Dec 2023 11:01:07 +0100 Subject: [PATCH] Use GenerateFileFromTemplate task from arcade instead of repo copy They were both based on some aspnetcore build tooling, the only difference in the arcade one is that is uses key=value strings for the replacement properties instead of msbuild items. Also fix an issue in workloads-testing.targets where we didn't use a separate MSBuild evaluation for the Restore task which meant that the build tasks weren't loaded in the Pack task. --- eng/Tools.props | 1 + eng/testing/workloads-testing.targets | 6 +- src/coreclr/.nuget/Directory.Build.props | 1 + .../pkg/projects/Directory.Build.props | 1 + .../Directory.Build.targets | 2 - ...Microsoft.NETCore.App.MonoCrossAOT.sfxproj | 8 +- src/mono/nuget/Directory.Build.props | 1 + src/mono/nuget/Directory.Build.targets | 1 - ...oft.NET.Runtime.LibraryBuilder.Sdk.pkgproj | 2 +- ...t.NET.Runtime.MonoAOTCompiler.Task.pkgproj | 2 +- ...rosoft.NET.Runtime.MonoTargets.Sdk.pkgproj | 2 +- ...rosoft.NET.Runtime.WebAssembly.Sdk.pkgproj | 2 +- ...t.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj | 2 +- ...ad.Mono.Toolchain.Current.Manifest.pkgproj | 6 +- ...kload.Mono.Toolchain.net6.Manifest.pkgproj | 4 +- ...kload.Mono.Toolchain.net7.Manifest.pkgproj | 4 +- ...kload.Mono.Toolchain.net8.Manifest.pkgproj | 4 +- .../GenerateFileFromTemplate.cs | 150 ------------------ 18 files changed, 25 insertions(+), 174 deletions(-) delete mode 100644 src/tasks/WorkloadBuildTasks/GenerateFileFromTemplate.cs diff --git a/eng/Tools.props b/eng/Tools.props index 2c3560f68a3e5..01cae1f2b2303 100644 --- a/eng/Tools.props +++ b/eng/Tools.props @@ -7,6 +7,7 @@ + diff --git a/eng/testing/workloads-testing.targets b/eng/testing/workloads-testing.targets index d205af6fbdfde..f0ab33a3ebe2b 100644 --- a/eng/testing/workloads-testing.targets +++ b/eng/testing/workloads-testing.targets @@ -169,10 +169,6 @@ TaskName="Microsoft.Workload.Build.Tasks.InstallWorkloadFromArtifacts" AssemblyFile="$(WorkloadBuildTasksAssemblyPath)" /> - - + diff --git a/src/installer/pkg/projects/Directory.Build.props b/src/installer/pkg/projects/Directory.Build.props index 5f04dc0003053..2917964afb8aa 100644 --- a/src/installer/pkg/projects/Directory.Build.props +++ b/src/installer/pkg/projects/Directory.Build.props @@ -127,5 +127,6 @@ + diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.targets b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.targets index 550a2e775fd61..eed1e6c5a65e3 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.targets +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.targets @@ -12,7 +12,5 @@ - - diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.MonoCrossAOT.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.MonoCrossAOT.sfxproj index ba42baee58498..ba8c34dd6b69b 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.MonoCrossAOT.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.MonoCrossAOT.sfxproj @@ -46,11 +46,11 @@ @@ -58,4 +58,8 @@ + + + + diff --git a/src/mono/nuget/Directory.Build.props b/src/mono/nuget/Directory.Build.props index 0dd0a252d5295..93723d1fd4d9b 100644 --- a/src/mono/nuget/Directory.Build.props +++ b/src/mono/nuget/Directory.Build.props @@ -1,6 +1,7 @@ + diff --git a/src/mono/nuget/Directory.Build.targets b/src/mono/nuget/Directory.Build.targets index a1811e7fcb86a..8524f404e9ea4 100644 --- a/src/mono/nuget/Directory.Build.targets +++ b/src/mono/nuget/Directory.Build.targets @@ -1,5 +1,4 @@ - diff --git a/src/mono/nuget/Microsoft.NET.Runtime.LibraryBuilder.Sdk/Microsoft.NET.Runtime.LibraryBuilder.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.LibraryBuilder.Sdk/Microsoft.NET.Runtime.LibraryBuilder.Sdk.pkgproj index 81017a4279a17..e1400e8d572ad 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.LibraryBuilder.Sdk/Microsoft.NET.Runtime.LibraryBuilder.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.LibraryBuilder.Sdk/Microsoft.NET.Runtime.LibraryBuilder.Sdk.pkgproj @@ -32,7 +32,7 @@ diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj index e5a5b52244306..b1fed9a63ed28 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj @@ -23,7 +23,7 @@ diff --git a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj index f2db3fcf82d2d..5cbb2f074832c 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/Microsoft.NET.Runtime.MonoTargets.Sdk.pkgproj @@ -28,7 +28,7 @@ diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj index 4a7bb43d67e9d..cce9b07be426b 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj @@ -36,7 +36,7 @@ diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj index df4dab00016a9..0ecece2893dd3 100644 --- a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj @@ -33,7 +33,7 @@ diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest.pkgproj b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest.pkgproj index b342a2bbcc197..dba78adeee06f 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest.pkgproj @@ -56,17 +56,17 @@ diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest.pkgproj b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest.pkgproj index 91ad9379b54d3..eb7d0af17dae9 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net6.Manifest.pkgproj @@ -48,12 +48,12 @@ diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest.pkgproj b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest.pkgproj index af11a5c6a6059..8779f945c9dca 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest.pkgproj @@ -50,12 +50,12 @@ diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest.pkgproj b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest.pkgproj index 59f77406140cf..79db301832b9d 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest/Microsoft.NET.Workload.Mono.Toolchain.net8.Manifest.pkgproj @@ -50,12 +50,12 @@ diff --git a/src/tasks/WorkloadBuildTasks/GenerateFileFromTemplate.cs b/src/tasks/WorkloadBuildTasks/GenerateFileFromTemplate.cs deleted file mode 100644 index 7598ab9357710..0000000000000 --- a/src/tasks/WorkloadBuildTasks/GenerateFileFromTemplate.cs +++ /dev/null @@ -1,150 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Text; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - -/// -/// -/// Generates a new file at . -/// -/// -/// The can define variables for substitution using . -/// -/// -/// The input file might look like this: -/// -/// 2 + 2 = ${Sum} -/// -/// When the task is invoked like this, it will produce "2 + 2 = 4" -/// -/// <GenerateFileFromTemplate Properties="Sum=4;OtherValue=123;" ... > -/// -/// -/// -public class GenerateFileFromTemplate : Task -{ - /// - /// The template file. - /// Variable syntax: ${VarName} - /// If your template file needs to output this format, you can escape the dollar sign with a backtick, e.g. `${NotReplaced} - /// - [NotNull] - [Required] - public string? TemplateFile { get; set; } - - /// - /// The destination for the generated file. - /// - [NotNull] - [Required] - public string? OutputPath { get; set; } - - /// - /// Key=value pairs of values - /// - [NotNull] - [Required] - public ITaskItem[]? Properties { get; set; } - - public override bool Execute() - { - string outputPath = Path.GetFullPath(OutputPath); - if (!File.Exists(TemplateFile)) - { - Log.LogError($"File {TemplateFile} does not exist"); - return false; - } - - var template = File.ReadAllText(TemplateFile); - var values = new Dictionary(); - foreach (ITaskItem item in Properties) - values.Add(item.ItemSpec, item.GetMetadata("Value")); - - var result = Replace(template, values); - string? dir = Path.GetDirectoryName(outputPath); - if (dir != null) - Directory.CreateDirectory(dir); - File.WriteAllText(outputPath, result); - - return true; - } - - public string Replace(string template, IDictionary values) - { - var sb = new StringBuilder(); - var varNameSb = new StringBuilder(); - var line = 1; - for (var i = 0; i < template.Length; i++) - { - var ch = template[i]; - var nextCh = i + 1 >= template.Length - ? '\0' - : template[i + 1]; - - // count lines in the template file - if (ch == '\n') - { - line++; - } - - if (ch == '`' && (nextCh == '$' || nextCh == '`')) - { - // skip the backtick for known escape characters - i++; - sb.Append(nextCh); - continue; - } - - if (ch != '$' || nextCh != '{') - { - // variables begin with ${. Moving on. - sb.Append(ch); - continue; - } - - varNameSb.Clear(); - i += 2; - for (; i < template.Length; i++) - { - ch = template[i]; - if (ch != '}') - { - varNameSb.Append(ch); - } - else - { - // Found the end of the variable substitution - var varName = varNameSb.ToString(); - if (values.TryGetValue(varName, out var value)) - { - sb.Append(value); - } - else - { - Log.LogWarning(null, null, null, TemplateFile, - line, 0, 0, 0, - message: $"No property value is available for '{varName}'"); - } - - varNameSb.Clear(); - break; - } - } - - if (varNameSb.Length > 0) - { - Log.LogWarning(null, null, null, TemplateFile, - line, 0, 0, 0, - message: "Expected closing bracket for variable placeholder. No substitution will be made."); - sb.Append("${").Append(varNameSb); - } - } - - return sb.ToString(); - } -}