From 50ef2a7a68bb549c3b6c3e4339a2f82a8d5975a1 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Fri, 25 Jun 2021 21:17:17 -0400 Subject: [PATCH] Squashed commit of the following: commit 14747dcf058a2129bbbcafacfd8f8adbc47ffef9 Merge: fb9b27c1fb0 118c530033b Author: Ankit Jain Date: Fri Jun 25 20:48:51 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit fb9b27c1fb006556d9b71cee6663088c88d17c38 Author: Ankit Jain Date: Fri Jun 25 15:15:26 2021 -0400 Fix remaining tests commit 6d43522dbac7768d33b18c4004a7d148d15154df Merge: 42e42afaedf fc4a42746d9 Author: Ankit Jain Date: Fri Jun 25 12:03:53 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit 42e42afaedf4c9fb29b93840163f7f6283d030a5 Author: Ankit Jain Date: Fri Jun 25 01:55:52 2021 -0400 copy nuget.config for blazor test too commit 4456b1a3dc00e9b5ec7d129c3498d774f789a0d0 Author: Ankit Jain Date: Fri Jun 25 00:33:57 2021 -0400 fix build commit ccc2c89c403a7349eb6bb9debccfed4e729e5bb8 Author: Ankit Jain Date: Thu Jun 24 23:33:13 2021 -0400 Isolate the nuget environment commit 53adc7d55c700795f3cbabaf64200a319afec525 Author: Ankit Jain Date: Thu Jun 24 20:11:51 2021 -0400 Bump sdk for workloads to 6.0.100-preview.6.21324.1 commit fbaf2ce408cf53dab2b4db5348e353b037a1a90b Author: Ankit Jain Date: Thu Jun 24 20:09:30 2021 -0400 fix tests commit ba8b922e055547ff9373391a1f215487ed9240a5 Author: Ankit Jain Date: Thu Jun 24 18:50:14 2021 -0400 skip first time experience commit a07a59586e8482871fb0ed71877b8853e8e3fb41 Author: Ankit Jain Date: Thu Jun 24 18:47:38 2021 -0400 fix build error commit c1487458f7defe608c7a3eaaddc5ea671dc4456d Author: Ankit Jain Date: Thu Jun 24 18:45:49 2021 -0400 fix nuget error commit 5199e9ce862e7fba7dee1d930e81915fbc5a503c Merge: 0c68049b6ca 1e5ebfed32e Author: Ankit Jain Date: Thu Jun 24 17:59:13 2021 -0400 Merge branch 'wasm-native-libs-workloads-pr' into wasm-native-libs-workloads commit 1e5ebfed32e4c22f6c33a5ad622375c138123d86 Merge: 643c8212d8f c88da290531 Author: Ankit Jain Date: Thu Jun 24 16:49:24 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads-pr commit 643c8212d8f2bb45684531d3445e12c75c37839c Author: Ankit Jain Date: Thu Jun 24 16:49:22 2021 -0400 fix linux build commit 9b064d96dc8de5a21afc994c8efc4d7c27d88729 Merge: 5fd632f031a abccfadbf57 Author: Ankit Jain Date: Thu Jun 24 12:20:39 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads-pr commit 5fd632f031a854bf36d98a7647c7ef6e15d5ae59 Author: Ankit Jain Date: Thu Jun 24 12:12:18 2021 -0400 fix casing for runtime pack path commit b4d48f37bbaa4a899e2444aac47e1d550bbad23b Author: Ankit Jain Date: Thu Jun 24 02:33:09 2021 -0400 fix runscript commit 0c68049b6cac1fabce76af950d6c15c01d9952e1 Author: Ankit Jain Date: Thu Jun 24 02:15:49 2021 -0400 refactorings commit 425e2e3c8f84ba1f536a134b70941f939942a1ae Author: Ankit Jain Date: Thu Jun 24 01:20:16 2021 -0400 set sdk path for helix commit 9652f8b82a5e000dadc2e9bf0015ab769d1faae7 Merge: 999de6d4441 dae9156dd0d Author: Ankit Jain Date: Wed Jun 23 23:46:59 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit 999de6d44419ca804ffabc719eba02c6b1ed230e Author: Ankit Jain Date: Wed Jun 23 23:19:42 2021 -0400 Add missing UsingTask commit 7636d3823db3f9e6e3223a22ba5ef57e99c6e641 Merge: 2468045aedc 4f3e30e6d34 Author: Ankit Jain Date: Wed Jun 23 22:21:38 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit 2468045aedcece825bbba39a8163c97bdc796fd7 Merge: 16c83d7d62b f3af8d8b146 Author: Ankit Jain Date: Wed Jun 23 21:23:55 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit 16c83d7d62b91499a51a81dac63ce8f60ee16d83 Author: Ankit Jain Date: Wed Jun 23 21:23:48 2021 -0400 Add hack to manually generate sdk.props for the cross compiler commit 8f9ddfbfced4fbf512df59648fa08df15c2f6bb1 Merge: 57b2950ba4a 0416c3469b7 Author: Ankit Jain Date: Wed Jun 23 12:59:32 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit 57b2950ba4a10f66d7aedcf497579a5e8c64ae9d Author: Ankit Jain Date: Tue Jun 22 19:21:51 2021 -0400 trying to fix the build commit 63089822f25848d190ab1d8b06468c293e2b9d2a Author: Ankit Jain Date: Tue Jun 22 15:38:09 2021 -0400 Don't build Wasm.Build.Tests for linker-tests pipeline commit 49d5dba9783694a8f57c621e020bfb481ee8971f Author: Ankit Jain Date: Tue Jun 22 15:34:34 2021 -0400 Make sure to restore runtime pack project commit fb4348b38b6061be1a64a2112fed9a8615dbb840 Author: Ankit Jain Date: Tue Jun 22 14:36:50 2021 -0400 disable Microsoft.NETCore.Platforms.Tests on wasm This is already not being sent to CI with `IgnoreForCI=true`. It fails on CI with: ``` /_/src/Shared/NativeMethodsShared.cs(855,29): error IL1005: Microsoft.Build.Shared.NativeMethodsShared.SystemInformation.get: Error processing method 'Microsoft.Build.Shared.NativeMethodsShared.SystemInformationData.SystemInformationData()' in assembly 'Microsoft.Build.Utilities.Core.dll' [/__w/1/s/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj] \##[error]/_/src/Shared/NativeMethodsShared.cs(855,29): error IL1005: (NETCORE_ENGINEERING_TELEMETRY=Build) Microsoft.Build.Shared.NativeMethodsShared.SystemInformation.get: Error processing method 'Microsoft.Build.Shared.NativeMethodsShared.SystemInformationData.SystemInformationData()' in assembly 'Microsoft.Build.Utilities.Core.dll' Mono.Linker.LinkerFatalErrorException: /_/src/Shared/NativeMethodsShared.cs(855,29): error IL1005: Microsoft.Build.Shared.NativeMethodsShared.SystemInformation.get: Error processing method 'Microsoft.Build.Shared.NativeMethodsShared.SystemInformationData.SystemInformationData()' in assembly 'Microsoft.Build.Utilities.Core.dll' ---> System.NotImplementedException: switch at Mono.Linker.Steps.UnreachableBlocksOptimizer.BodyReducer.IsConstantBranch(OpCode opCode, Int32 operand) in illink.dll:token 0x6000770+0x41 at Mono.Linker.Steps.UnreachableBlocksOptimizer.BodyReducer.RemoveConditions() in illink.dll:token 0x6000768+0x22a at Mono.Linker.Steps.UnreachableBlocksOptimizer.BodyReducer.RewriteBody() in illink.dll:token 0x6000766+0xa at Mono.Linker.Steps.UnreachableBlocksOptimizer.ProcessStack() in illink.dll:token 0x60004e9+0x102 at Mono.Linker.Steps.UnreachableBlocksOptimizer.ProcessMethod(MethodDefinition method) in illink.dll:token 0x60004e5+0x44 at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, Scope& scope) in illink.dll:token 0x600040e+0x9b at Mono.Linker.Steps.MarkStep.ProcessQueue() in illink.dll:token 0x6000399+0x24 --- End of inner exception stack trace --- at Mono.Linker.Steps.MarkStep.ProcessQueue() in illink.dll:token 0x6000399+0xaa at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() in illink.dll:token 0x6000396+0xa at Mono.Linker.Steps.MarkStep.Process() in illink.dll:token 0x6000393+0x0 at Mono.Linker.Steps.MarkStep.Process(LinkContext context) in illink.dll:token 0x600038a+0x41 at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) in illink.dll:token 0x6000264+0x0 at Mono.Linker.Pipeline.Process(LinkContext context) in illink.dll:token 0x6000263+0xf at Mono.Linker.Driver.Run(ILogger customLogger) in illink.dll:token 0x60000fd+0x20 Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink /__w/1/s/.dotnet/sdk/6.0.100-preview.4.21255.9/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ILLink.targets(80,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/__w/1/s/src/libraries/Microsoft.NETCore.Platforms/tests/Microsoft.NETCore.Platforms.Tests.csproj] \##[error].dotnet/sdk/6.0.100-preview.4.21255.9/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ILLink.targets(80,5): error NETSDK1144: (NETCORE_ENGINEERING_TELEMETRY=Build) Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. ``` commit 480373505d9e25c361555d9b0506c70da3287dd5 Author: Ankit Jain Date: Tue Jun 22 14:10:06 2021 -0400 cleanup commit 911c54ae28dea7becc7ade908b7ac801bfcc40fa Merge: f6f8e26b1c6 62b8d02fdbf Author: Ankit Jain Date: Tue Jun 22 13:26:38 2021 -0400 Merge remote-tracking branch 'origin/main' into wasm-native-libs-workloads commit f6f8e26b1c69826a4489482580e9ecaa4b45896b Author: Ankit Jain Date: Tue Jun 22 13:20:10 2021 -0400 Directly invoke runtime pack sfxproj, to get the package commit 998c83d5f6c062ed3e9c16fe1d67c8bddb940d8b Author: Ankit Jain Date: Tue Jun 22 13:03:12 2021 -0400 cleanup commit 81373d93eff8e5ee77984f589434693774624823 Author: Ankit Jain Date: Tue Jun 22 03:27:00 2021 -0400 Use dotnet6 feed to restore packages commit c8ca41007128b9ec4723486bee504afc69ac3343 Author: Ankit Jain Date: Tue Jun 22 02:58:02 2021 -0400 get the version from envvar commit c66de8622cb4566ff883f6c84cadf0f9bb1a0a7e Author: Ankit Jain Date: Sun Jun 20 18:00:04 2021 -0400 Fix to use the correct ref pack commit 4554f301941f56731da352393cc525c0c607a69a Author: Ankit Jain Date: Sun Jun 20 17:10:04 2021 -0400 fixes commit 8f01a0aebe32aa8376be37d61bf10f0a443faac1 Author: Ankit Jain Date: Sun Jun 20 15:54:51 2021 -0400 fix tests commit 99e84734dd415abb3117584c60f2e3c0d5cf4852 Author: Ankit Jain Date: Sun Jun 20 14:41:49 2021 -0400 this seems to get the runtime pack building commit 967d60e06d3206eec83752cea5bb8f0d79961bf4 Author: Ankit Jain Date: Sun Jun 20 11:42:48 2021 -0400 fix build commit 3c1ef3355cf0ec57c16534d52200e31fa5d6fdf6 Author: Ankit Jain Date: Sun Jun 20 11:24:44 2021 -0400 fix DirectoryCopy commit a20102c574528a6835598958730e9c26e655e533 Author: Ankit Jain Date: Sun Jun 20 08:57:13 2021 -0400 fix net6.0 test builds commit 2fa559ec0ed5822834a7c9b0f905e496a4c7c5db Author: Ankit Jain Date: Sun Jun 20 08:18:21 2021 -0400 cleanup commit 0ffd96cf7d1dbff748512b8d1d3b6548233b2b4e Author: Ankit Jain Date: Sun Jun 20 04:23:21 2021 -0400 debug commit 8e754bf7650f2ab83d1a45a5e096d8fcaf080fc4 Author: Ankit Jain Date: Sun Jun 20 03:16:33 2021 -0400 fix build, move doesn't work on CI - invalid cross-device link commit 53ec67103d90e3cfda73b5423b6a416b67a58b88 Author: Ankit Jain Date: Sun Jun 20 02:12:39 2021 -0400 undo changes to wasm samples commit 1fe8601850289bf97a1ede3415276773e6eec079 Author: Ankit Jain Date: Sun Jun 20 02:11:52 2021 -0400 cleanup commit 529fb8698165376b6246448ff5be76e6fe4adf54 Author: Eric StJohn Date: Sat Jun 19 13:31:12 2021 -0700 Remove System.Security.Cryptography.Cng from ASP.NET transport package (#54428) commit 04e7a11ecd7eb1826d14634d7c08bff4665b17e9 Author: Bruce Forstall Date: Sat Jun 19 10:07:59 2021 -0700 Disable tests for #54007 (#54207) commit d0798cd272bb71194a21350da1f10e624bb62fbd Author: Ankit Jain Date: Sun Jun 20 00:40:56 2021 -0400 fix running dotnet-install.sh on linux commit fe05df865629e14b92af6af4233a59ae9ac935cf Author: Ankit Jain Date: Sat Jun 19 22:46:55 2021 -0400 fix helix build commit 3a224d38593e5e60334ff2d1debe26ff395506e8 Author: Ankit Jain Date: Sat Jun 19 09:03:16 2021 -0400 try helix commit 5c5212479503aeaef3d7335e5c011e5548f758b5 Author: Ankit Jain Date: Sat Jun 19 05:55:09 2021 -0400 fix order of args to emcc commit 84750efbaf73a84596700832c699ddfea73573da Author: Ankit Jain Date: Sat Jun 19 05:30:35 2021 -0400 fixed commit 4e0318f09eaac0113da8a5c82634ef8997b43a46 Author: Ankit Jain Date: Sat Jun 19 04:08:18 2021 -0400 add BuildEnvironment.cs commit 0b8766423fc677f44c0580fe21f812d7ff6e9cd4 Author: Ankit Jain Date: Sat Jun 19 02:58:09 2021 -0400 remove native-libs sample commit 55cbd78aa21dab49f3daab53a89b092cd05e3761 Author: Ankit Jain Date: Sat Jun 19 02:28:04 2021 -0400 [wip] wasm native libs, and testing wbt with workloads Run wasm.build.tests with, and without workloads cleanup remove old copy of test wip Fix helix job for non-workload run umm.. wip.. till previous commit, it works on helix.. try to fix non-workloads test run cleanup, and fix windows command line cleanup Remove redundant functional tests build samples in parallel Revert Utils.DirectoryCopy, and creat dirs wher needed fix windows build fix build fix dir copy don't build samples, and functional tests on eat, aot lanes cleanup Test with latest sdk (6.0.100-preview.7.21326.4) rename runscript trying on windows add test for checking UnixFilePermissions.xml in the packs cleanup cleanup --- Directory.Build.props | 2 + eng/Versions.props | 1 + eng/pipelines/runtime-staging.yml | 1 + eng/testing/tests.mobile.targets | 9 + eng/testing/tests.targets | 6 +- eng/testing/tests.wasm.targets | 5 + src/libraries/Directory.Build.props | 7 + src/libraries/Directory.Build.targets | 88 ++++ src/libraries/pretest.proj | 3 + src/libraries/sendtohelix.proj | 19 +- src/libraries/sendtohelixhelp.proj | 103 ++-- src/libraries/tests.proj | 9 +- ...rosoft.NET.Runtime.WebAssembly.Sdk.pkgproj | 14 +- .../Sdk/AutoImport.props | 5 - .../Sdk/AutoImport.props.in | 8 + ...T.Workload.Mono.Toolchain.Manifest.pkgproj | 8 +- .../WorkloadManifest.json.in | 2 +- ...st.targets => WorkloadManifest.targets.in} | 22 + src/mono/wasm/build/WasmApp.targets | 5 + .../aot-tests/ProxyProjectForAOTOnHelix.proj | 2 +- src/mono/wasm/wasm.proj | 2 +- src/tasks/Common/Utils.cs | 4 +- .../WorkloadBuildTasks/InstallWorkload.cs | 475 ++++++++++++++++++ .../WorkloadBuildTasks.csproj | 2 + 24 files changed, 751 insertions(+), 51 deletions(-) delete mode 100644 src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props create mode 100644 src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props.in rename src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/{WorkloadManifest.targets => WorkloadManifest.targets.in} (77%) create mode 100644 src/tasks/WorkloadBuildTasks/InstallWorkload.cs diff --git a/Directory.Build.props b/Directory.Build.props index 53be3bd5c9b01..e681457ecfa18 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -71,6 +71,7 @@ $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AndroidAppBuilder', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmAppBuilder', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmBuildTasks', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) + $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WorkloadBuildTasks', 'Debug', '$(NetCoreAppToolCurrent)', 'publish')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoAOTCompiler', 'Debug', '$(NetCoreAppToolCurrent)')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'RuntimeConfigParser', 'Debug', '$(NetCoreAppToolCurrent)')) @@ -82,6 +83,7 @@ $([MSBuild]::NormalizePath('$(AndroidAppBuilderDir)', 'AndroidAppBuilder.dll')) $([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll')) $([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll')) + $([MSBuild]::NormalizePath('$(WorkloadBuildTasksDir)', 'WorkloadBuildTasks.dll')) $([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll')) $([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(Configuration)')) diff --git a/eng/Versions.props b/eng/Versions.props index 60393072c37ff..608ba5ba260b4 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -159,6 +159,7 @@ 2.0.4 4.12.0 2.14.3 + 6.0.100-preview.7.21326.4 5.0.0-preview-20201009.2 diff --git a/eng/pipelines/runtime-staging.yml b/eng/pipelines/runtime-staging.yml index 666641354bf5a..cf984c7984773 100644 --- a/eng/pipelines/runtime-staging.yml +++ b/eng/pipelines/runtime-staging.yml @@ -389,6 +389,7 @@ jobs: extraHelixArguments: /p:BrowserHost=windows scenarios: - normal + - buildwasmapps condition: >- or( eq(variables['librariesContainsChange'], true), diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 83d95eae00859..e46aba5219de5 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -7,6 +7,10 @@ true BundleTestAppleApp;BundleTestAndroidApp + + + true @@ -289,5 +293,10 @@ AfterTargets="Build" DependsOnTargets="Publish;$(BundleTestAppTargets);ArchiveTests" /> + + diff --git a/eng/testing/tests.targets b/eng/testing/tests.targets index dd40856e629b1..1e7ec3b173dc3 100644 --- a/eng/testing/tests.targets +++ b/eng/testing/tests.targets @@ -1,13 +1,15 @@ - + RunnerTemplate.cmd RunnerTemplate.sh AppleRunnerTemplate.sh AndroidRunnerTemplate.sh WasmRunnerTemplate.sh WasmRunnerTemplate.cmd + - $(MSBuildThisFileDirectory)$(RunScriptInputName) + + $(MSBuildThisFileDirectory)$(RunScriptInputName) RunTests.sh RunTests.cmd diff --git a/eng/testing/tests.wasm.targets b/eng/testing/tests.wasm.targets index aa4fb305dbd42..cd2fa3e4e131d 100644 --- a/eng/testing/tests.wasm.targets +++ b/eng/testing/tests.wasm.targets @@ -60,6 +60,11 @@ $(BundleTestWasmAppDependsOn);_BundleAOTTestWasmAppForHelix + + + + + --interpreter + + $(ArtifactsBinDir)dotnet-workload\ + $([MSBuild]::NormalizeDirectory($(SdkPathForWorkloadTesting))) + + $(SdkPathForWorkloadTesting)version-$(SdkVersionForWorkloadTesting).stamp + + diff --git a/src/libraries/Directory.Build.targets b/src/libraries/Directory.Build.targets index 051d90878db1a..8fef37d7fd866 100644 --- a/src/libraries/Directory.Build.targets +++ b/src/libraries/Directory.Build.targets @@ -7,6 +7,11 @@ $(TestStrongNameKeyId) + + true + $(SdkPathForWorkloadTesting)workload.stamp + + @@ -356,4 +361,87 @@ Text="Analyzers must only target netstandard2.0 since they run in the compiler which targets netstandard2.0. The following files were found to target '%(_AnalyzerPackFile.TargetFramework)': @(_AnalyzerPackFile)" /> + + + + + + + + + + <_DotNetInstallScriptPath Condition="!$([MSBuild]::IsOSPlatform('windows'))">$(DOTNET_INSTALL_DIR)/dotnet-install.sh + <_DotNetInstallScriptPath Condition=" $([MSBuild]::IsOSPlatform('windows'))">$(DOTNET_INSTALL_DIR)/dotnet-install.ps1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_NuGetSourceForWorkloads Include="dotnet6" Value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" /> + + + + + + + + $(SdkPathForWorkloadTesting)packs\Microsoft.NETCore.App.Runtime.AOT.$(NETCoreSdkRuntimeIdentifier).Cross.$(RuntimeIdentifier)\$(PackageVersion) + + + + + + + + <_SdkPropsProperties Condition="!$([MSBuild]::IsOsPlatform('Windows'))" Include="ExeSuffix" Value="" /> + <_SdkPropsProperties Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="ExeSuffix" Value=".exe" /> + <_SdkPropsProperties Include="TargetRid" Value="browser-wasm" /> + + + + + + + + diff --git a/src/libraries/pretest.proj b/src/libraries/pretest.proj index 3e924e083abd5..fc2fee13d5c33 100644 --- a/src/libraries/pretest.proj +++ b/src/libraries/pretest.proj @@ -22,6 +22,9 @@ + + + - <_ProjectsToBuild Include="$(PerScenarioProjectFile)"> + <_BaseProjectsToBuild Include="$(PerScenarioProjectFile)" Condition="'%(_Scenarios.Identity)' != 'buildwasmapps'"> $(_PropertiesToPass);Scenario=%(_Scenarios.Identity);TestArchiveRuntimeFile=$(TestArchiveRuntimeFile) - %(_ProjectsToBuild.AdditionalProperties);NeedsToBuildWasmAppsOnHelix=$(NeedsToBuildWasmAppsOnHelix) - + %(_BaseProjectsToBuild.AdditionalProperties);NeedsToBuildWasmAppsOnHelix=$(NeedsToBuildWasmAppsOnHelix) + + + + + <_TestValues Include="true;false" /> + + <_OtherProjectsToBuild Include="$(PerScenarioProjectFile)"> + $(_PropertiesToPass);Scenario=BuildWasmApps;TestArchiveRuntimeFile=$(TestArchiveRuntimeFile);TestUsingWorkloads=%(_TestValues.Identity) + %(_OtherProjectsToBuild.AdditionalProperties);NeedsToBuildWasmAppsOnHelix=$(NeedsToBuildWasmAppsOnHelix) + + + + + <_ProjectsToBuild Include="@(_BaseProjectsToBuild);@(_OtherProjectsToBuild)" /> diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 12d402fcb7e39..49d45b7c6053a 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -7,6 +7,7 @@ true + true $(BUILD_BUILDNUMBER) @@ -53,6 +54,9 @@ $(WaitForWorkItemCompletion) true + + true + true @@ -97,7 +101,7 @@ true - true + true @@ -105,11 +109,21 @@ - - true - true - true - + + + + false + true + + + + + true + true + true + + + - powershell -command "New-SelfSignedCertificate -FriendlyName 'ASP.NET Core HTTPS development certificate' -DnsName @('localhost') -Subject 'CN = localhost' -KeyAlgorithm RSA -KeyLength 2048 -HashAlgorithm sha256 -CertStoreLocation 'Cert:\CurrentUser\My' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.1','1.3.6.1.4.1.311.84.1.1={hex}02','2.5.29.19={text}') -KeyUsage DigitalSignature,KeyEncipherment" && - - - $(HelixCommand)call RunTests.cmd - $(HelixCommand) --runtime-path %HELIX_CORRELATION_PAYLOAD% - - $(HelixCommand)./RunTests.sh - $(HelixCommand) --runtime-path "$HELIX_CORRELATION_PAYLOAD" - - @@ -224,6 +228,34 @@ + + @(HelixPreCommand) + $(HelixCommandPrefix) @(HelixCommandPrefixItem -> 'set %(Identity)', ' & ') + $(HelixCommandPrefix) @(HelixCommandPrefixItem, ' ') + true + + + + $(HelixCommandPrefix) + $(HelixCommandPrefix) & + + $(HelixCommand) dotnet dev-certs https && + + + $(HelixCommand) powershell -command "New-SelfSignedCertificate -FriendlyName 'ASP.NET Core HTTPS development certificate' -DnsName @('localhost') -Subject 'CN = localhost' -KeyAlgorithm RSA -KeyLength 2048 -HashAlgorithm sha256 -CertStoreLocation 'Cert:\CurrentUser\My' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.1','1.3.6.1.4.1.311.84.1.1={hex}02','2.5.29.19={text}') -KeyUsage DigitalSignature,KeyEncipherment" && + + + $(HelixCommand)call RunTests.cmd + $(HelixCommand) --runtime-path %HELIX_CORRELATION_PAYLOAD% + + $(HelixCommand)./RunTests.sh + $(HelixCommand) --runtime-path "$HELIX_CORRELATION_PAYLOAD" + + @@ -302,7 +334,15 @@ - + + + + + + + + @@ -311,7 +351,7 @@ - + @@ -374,7 +414,7 @@ - + @@ -392,6 +432,7 @@ + diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index c405468695244..4b137e3ffd698 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -352,9 +352,11 @@ Condition="'$(TestTrimming)' == 'true'" AdditionalProperties="%(AdditionalProperties);SkipTrimmingProjectsRestore=true" /> + + @@ -381,10 +383,11 @@ BuildInParallel="false" /> - + + + BuildInParallel="true" /> 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 874775fe7e47f..3db38ddbbe86a 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 @@ -3,6 +3,7 @@ Provides the tasks+targets, for consumption by wasm based workloads + $(IntermediateOutputPath)AutoImport.props @@ -10,12 +11,23 @@ - + + + + <_AutoImportValues Include="PackageVersion" Value="$(PackageVersion)" /> + + + + + diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props deleted file mode 100644 index f29ea9ae7da30..0000000000000 --- a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props +++ /dev/null @@ -1,5 +0,0 @@ - - - true - - \ No newline at end of file diff --git a/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props.in b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props.in new file mode 100644 index 0000000000000..f925992ce31e4 --- /dev/null +++ b/src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/AutoImport.props.in @@ -0,0 +1,8 @@ + + + true + true + ${PackageVersion} + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', '..', '..')) + + diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Manifest.pkgproj b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Manifest.pkgproj index 0f6c403f4104e..747da02070f2f 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Manifest.pkgproj +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/Microsoft.NET.Workload.Mono.Toolchain.Manifest.pkgproj @@ -13,11 +13,12 @@ $(IntermediateOutputPath)WorkloadManifest.json + $(IntermediateOutputPath)WorkloadManifest.targets - + @@ -37,6 +38,11 @@ TemplateFile="WorkloadManifest.json.in" Properties="@(_WorkloadManifestValues)" OutputPath="$(WorkloadManifestPath)" /> + + diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.json.in b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.json.in index 4c50a08f007c8..436c5b87664b9 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.json.in +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.json.in @@ -296,4 +296,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in similarity index 77% rename from src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets rename to src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in index 2102eabc36ce6..420dc6ccfff14 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Manifest/WorkloadManifest.targets.in @@ -1,4 +1,9 @@ + + ${PackageVersion} + true + + true $(WasmNativeWorkload) @@ -43,4 +48,21 @@ + + + + + + + + + + diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 034287436892b..7364188466631 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -81,7 +81,12 @@ false + + $([MSBuild]::NormalizeDirectory($(WorkloadPacksDir), 'Microsoft.NETCore.App.Runtime.Mono.browser-wasm', '$(RuntimePackInWorkloadVersion)')) + + $([MSBuild]::NormalizeDirectory($(NuGetPackageRoot), 'microsoft.netcore.app.runtime.mono.browser-wasm', '$(BundledNETCoreAppPackageVersion)')) + $([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackDir), 'runtimes', 'browser-wasm')) $([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir))) $([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir), 'native')) diff --git a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj index cdd5e95a4e210..3a7b66fac7389 100644 --- a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj @@ -22,7 +22,7 @@ - diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index ffc2fb92825ba..4c5983255908c 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -107,7 +107,7 @@ <_EmccVersionRaw>%(_ReversedVersionLines.Identity) - <_EmccVersionRegexPattern>^ *emcc \([^\)]+\) *([^ \(]+) *\(([^\)]+)\)$ + <_EmccVersionRegexPattern>^ *emcc \([^\)]+\) *([0-9\.]+).*\(([^\)]+)\)$ <_EmccVersion>$([System.Text.RegularExpressions.Regex]::Match($(_EmccVersionRaw), $(_EmccVersionRegexPattern)).Groups[1].Value) <_EmccVersionHash>$([System.Text.RegularExpressions.Regex]::Match($(_EmccVersionRaw), $(_EmccVersionRegexPattern)).Groups[2].Value) diff --git a/src/tasks/Common/Utils.cs b/src/tasks/Common/Utils.cs index ea2aba607dd8e..7b25107d56f98 100644 --- a/src/tasks/Common/Utils.cs +++ b/src/tasks/Common/Utils.cs @@ -185,12 +185,12 @@ internal static string CreateTemporaryBatchFile(string command) } #if NETCOREAPP - public static void DirectoryCopy(string sourceDir, string destDir, Func predicate) + public static void DirectoryCopy(string sourceDir, string destDir, Func? predicate=null) { string[] files = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories); foreach (string file in files) { - if (!predicate(file)) + if (predicate != null && !predicate(file)) continue; string relativePath = Path.GetRelativePath(sourceDir, file); diff --git a/src/tasks/WorkloadBuildTasks/InstallWorkload.cs b/src/tasks/WorkloadBuildTasks/InstallWorkload.cs new file mode 100644 index 0000000000000..063862273ad05 --- /dev/null +++ b/src/tasks/WorkloadBuildTasks/InstallWorkload.cs @@ -0,0 +1,475 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +#nullable enable + +namespace Microsoft.Workload.Build.Tasks +{ + public class InstallWorkload : Task + { + [Required, NotNull] + public ITaskItem? WorkloadId { get; set; } + + [Required, NotNull] + public ITaskItem? ManifestPackage { get; set; } + + [Required, NotNull] + public ITaskItem? BuiltNuGetsPath { get; set; } + + [Required, NotNull] + public string? OutputDir { get; set; } + + public ITaskItem[]? ExtraNuGetSources { get; set; } + public string? Rid { get; set; } + + private readonly string _tempDir = Path.Combine(Path.GetTempPath(), "install-workload", Path.GetRandomFileName()); + private string? _packsDir; + private const string s_stampFileName = ".installed.stamp"; + + private static string? GetRid() + { + if (OperatingSystem.IsWindows()) + return Environment.Is64BitProcess ? "win-x64": "win-x86"; + else if (OperatingSystem.IsMacOS()) + return "osx-x64"; + else if (OperatingSystem.IsLinux()) + return "linux-x64"; + else + return null; + } + + public override bool Execute() + { + Utils.Logger = Log; + + if (!HasMetadata(ManifestPackage, nameof(ManifestPackage), "VersionBand") || + !HasMetadata(ManifestPackage, nameof(ManifestPackage), "Version") || + !HasMetadata(WorkloadId, nameof(WorkloadId), "Name")) + { + return false; + } + + if (!Directory.Exists(OutputDir)) + { + Log.LogError($"Cannot find OutputDir={OutputDir}"); + return false; + } + + _packsDir = Path.Combine(OutputDir, "packs"); + Rid ??= GetRid(); + if (Rid == null) + { + Log.LogError("Unsupported platform"); + return false; + } + + if (!InstallWorkloadManifest(out ManifestInformation? manifest, out string? manifestNupkgPath)) + return false; + + IEnumerable references = GetPackageReferencesForWorkload(manifest, WorkloadId.ItemSpec); + IEnumerable remaining = LayoutPacksFromBuiltNuGets(references); + if (!remaining.Any()) + return !Log.HasLoggedErrors; + + if (!InstallPacksWithNuGetRestore(remaining)) + return false; + + return !Log.HasLoggedErrors; + } + + private bool InstallWorkloadManifest([NotNullWhen(true)] out ManifestInformation? manifest, [NotNullWhen(true)] out string? manifestNupkgPath) + { + manifest = null; + manifestNupkgPath = null; + + string builtNuGetsFullPath = BuiltNuGetsPath.GetMetadata("FullPath"); + string pkgName = ManifestPackage.ItemSpec; + string pkgVersion = ManifestPackage.GetMetadata("Version"); + + var nupkgFileName = $"{pkgName}.{pkgVersion}.nupkg"; + var nupkgPath = Path.Combine(builtNuGetsFullPath, nupkgFileName); + if (!File.Exists(nupkgPath)) + { + Log.LogError($"Could not find nupkg for the manifest at {nupkgPath}"); + return false; + } + + string baseManifestDir = Path.Combine(OutputDir, "sdk-manifests"); + + string tmpManifestDir = Path.Combine(_tempDir, "manifest"); + ZipFile.ExtractToDirectory(nupkgPath, tmpManifestDir); + + var sourceManifestDirectory = Path.Combine(tmpManifestDir, "data"); + var targetManifestDirectory = Path.Combine(baseManifestDir, ManifestPackage.GetMetadata("VersionBand"), WorkloadId.GetMetadata("Name")); + if (!CopyDirectory(sourceManifestDirectory, targetManifestDirectory)) + return false; + + string jsonPath = Path.Combine(targetManifestDirectory, "WorkloadManifest.json"); + if (!File.Exists(jsonPath)) + { + Log.LogError($"Could not find WorkloadManifest.json at {jsonPath}"); + return false; + } + + manifest = JsonSerializer.Deserialize( + File.ReadAllBytes(jsonPath), + new JsonSerializerOptions(JsonSerializerDefaults.Web) + { + AllowTrailingCommas = true, + ReadCommentHandling = JsonCommentHandling.Skip + }); + + if (manifest == null) + { + Log.LogError($"Could not parse manifest from {jsonPath}."); + return false; + } + + manifestNupkgPath = nupkgPath; + return true; + } + + private IEnumerable LayoutPacksFromBuiltNuGets(IEnumerable references) + { + string builtNuGetsFullPath = BuiltNuGetsPath.GetMetadata("FullPath"); + + var allFiles = string.Join($"{Environment.NewLine} ", Directory.EnumerateFiles(builtNuGetsFullPath, "*", new EnumerationOptions { RecurseSubdirectories = true })); + Log.LogMessage(MessageImportance.Low, $"Files in {builtNuGetsFullPath}: {allFiles}"); + + List remaining = new(references.Count()); + foreach (var reference in references) + { + var nupkgFileName = $"{reference.Name}.{reference.Version}.nupkg"; + var nupkgPath = Path.Combine(builtNuGetsFullPath, nupkgFileName); + if (!File.Exists(nupkgPath)) + { + string[] found = Directory.GetFiles(builtNuGetsFullPath, nupkgFileName, new EnumerationOptions + { + MatchCasing = MatchCasing.CaseInsensitive, + RecurseSubdirectories = true + }); + + if (found.Length == 0) + { + remaining.Add(reference); + continue; + } + + nupkgPath = found[0]; + nupkgFileName = Path.GetFileName(nupkgPath); + } + + string installedPackDir = Path.Combine(_packsDir!, reference.Name, reference.Version); + string stampFilePath = Path.Combine(installedPackDir, s_stampFileName); + if (!IsFileNewer(nupkgPath, stampFilePath)) + { + Log.LogMessage(MessageImportance.Normal, $"Skipping {reference.Name}/{reference.Version} as it is already installed in {installedPackDir}.{Environment.NewLine} {nupkgPath} is older than {stampFilePath}"); + continue; + } + + if (Directory.Exists(installedPackDir)) + { + Log.LogMessage(MessageImportance.Normal, $"Deleting {installedPackDir}"); + Directory.Delete(installedPackDir, recursive: true); + } + + Log.LogMessage(MessageImportance.High, $"Extracting {nupkgPath} => {installedPackDir}"); + ZipFile.ExtractToDirectory(nupkgPath, installedPackDir); + + // Add .nupkg.sha512, so it gets picked up when resolving nugets + File.WriteAllText(Path.Combine(installedPackDir, $"{nupkgFileName}.sha512"), string.Empty); + + File.WriteAllText(stampFilePath, string.Empty); + } + + return remaining; + } + + private IEnumerable GetPackageReferencesForWorkload(ManifestInformation manifest, string workloadId) + { + var workload = manifest.Workloads[workloadId]; + var subset = workload.Packs; + if (workload.Extends.Count > 0) + { + subset = new List(subset); + //FIXME: use exceptions! + if (!ProcessWorkload(workload)) + throw new KeyNotFoundException(); + } + + List references = new(); + foreach (var item in manifest.Packs) + { + if (subset != null && !subset.Contains(item.Key)) + { + Log.LogMessage(MessageImportance.Low, $"Ignoring pack {item.Key} as it is not in the workload"); + continue; + } + + var packageName = item.Key; + if (item.Value.AliasTo is Dictionary alias) + { + alias.TryGetValue(Rid!, out packageName); + } + + if (!string.IsNullOrEmpty(packageName) && !packageName.Contains("cross", StringComparison.InvariantCultureIgnoreCase)) + references.Add(new PackageReference(packageName, item.Value.Version)); + } + + return references; + + bool ProcessWorkload(WorkloadInformation workload) + { + if (workload.Extends == null || workload.Extends.Count == 0) + return true; + + foreach (var w in workload.Extends) + { + if (!manifest.Workloads.TryGetValue(w, out WorkloadInformation? depWorkload)) + { + Log.LogError($"Could not find workload {w} needed by {workload.Description} in the manifest"); + return false; + } + //FIXME: + + if (!ProcessWorkload(depWorkload)) + return false; + + subset.AddRange(depWorkload.Packs); + } + + return true; + } + } + + private bool InstallPacksWithNuGetRestore(IEnumerable references) + { + var remaining = SkipInstalledPacks(references); + if (!remaining.Any()) + return true; + + return TryRestorePackages(remaining, out PackageReference[]? restored) && + LayoutPacksFromRestoredNuGets(restored); + + IEnumerable SkipInstalledPacks(IEnumerable candidates) + { + List needed = new List(candidates.Count()); + foreach (PackageReference pr in candidates) + { + var installedPackDir = Path.Combine(_packsDir!, pr.Name, pr.Version); + var packStampFile = Path.Combine(installedPackDir, s_stampFileName); + + if (File.Exists(packStampFile)) + { + Log.LogMessage(MessageImportance.Normal, $"Skipping {pr.Name}/{pr.Version} as it is already installed in {installedPackDir}.{Environment.NewLine} {packStampFile} exists."); + continue; + } + + needed.Add(pr); + } + + return needed; + } + + bool LayoutPacksFromRestoredNuGets(IEnumerable restored) + { + foreach (var pkgRef in restored) + { + if (pkgRef.RestoredPath == null) + { + Log.LogError($"Failed to restore {pkgRef.Name}/{pkgRef.Version}"); + return false; + } + + var source = pkgRef.RestoredPath; + var destDir = Path.Combine(_packsDir!, pkgRef.Name, pkgRef.Version); + if (!CopyDirectory(source, destDir)) + return false; + } + + return true; + } + } + + private bool TryRestorePackages(IEnumerable references, [NotNullWhen(true)]out PackageReference[]? restoredPackages) + { + if (!references.Any()) + { + restoredPackages = Array.Empty(); + return true; + } + + restoredPackages = null; + + var restoreProject = Path.Combine(_tempDir, "restore", "Restore.csproj"); + var restoreProjectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(restoreProject)!); + + File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.props"), ""); + File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "Directory.Build.targets"), ""); + + StringBuilder projectFileBuilder = new(); + projectFileBuilder.Append(@" + + + net6.0 + $(NoWarn);NU1213 + + +"); + + foreach (var reference in references) + { + string itemName = "PackageReference"; + projectFileBuilder.AppendLine($"<{itemName} Include=\"{reference.Name}\" Version=\"{reference.Version}\" />"); + } + + projectFileBuilder.Append(@" + + +"); + File.WriteAllText(restoreProject, projectFileBuilder.ToString()); + + if (ExtraNuGetSources?.Length > 0) + { + StringBuilder nugetConfigBuilder = new(); + nugetConfigBuilder.AppendLine($"{Environment.NewLine}"); + + foreach (ITaskItem source in ExtraNuGetSources) + { + string key = source.ItemSpec; + string value = source.GetMetadata("Value"); + if (string.IsNullOrEmpty(value)) + { + Log.LogError($"ExtraNuGetSource {key} is missing Value metadata"); + return false; + } + + nugetConfigBuilder.AppendLine($@""); + } + + nugetConfigBuilder.AppendLine($"{Environment.NewLine}"); + + File.WriteAllText(Path.Combine(restoreProjectDirectory.FullName, "nuget.config"), nugetConfigBuilder.ToString()); + } + + string restoreDir = Path.Combine(_tempDir, "nuget-packages"); + if (Directory.Exists(restoreDir)) + { + Log.LogMessage(MessageImportance.Low, $"Deleting {restoreDir}"); + Directory.Delete(restoreDir, recursive: true); + } + + Log.LogMessage(MessageImportance.High, $"Restoring packages: {string.Join(", ", references.Select(r => $"{r.Name}/{r.Version}"))}"); + + string args = $"restore {restoreProject} /p:RestorePackagesPath={restoreDir}"; + (int exitCode, string output) = Utils.TryRunProcess("dotnet", args, silent: false, debugMessageImportance: MessageImportance.Normal); + if (exitCode != 0) + { + Log.LogError($"Restoring packages returned exit code: {exitCode}. Output:{Environment.NewLine}{output}"); + return false; + } + + restoredPackages = references.Select(reference => + { + var expectedPath = Path.Combine(restoreDir, reference.Name.ToLower(), reference.Version); + if (Directory.Exists(expectedPath)) + { + reference = reference with { RestoredPath = expectedPath }; + File.WriteAllText(Path.Combine(reference.RestoredPath, s_stampFileName), string.Empty); + } + return reference; + }).ToArray(); + + return true; + } + + private bool CopyDirectory(string srcDir, string destDir) + { + try + { + Log.LogMessage(MessageImportance.Low, $"Copying {srcDir} to {destDir}"); + if (Directory.Exists(destDir)) + { + Log.LogMessage(MessageImportance.Normal, $"Deleting {destDir}"); + Directory.Delete(destDir, recursive: true); + } + + Directory.CreateDirectory(destDir); + Utils.DirectoryCopy(srcDir, destDir); + + return true; + } + catch (Exception ex) + { + Log.LogError($"Failed while copying {srcDir} => {destDir}: {ex.Message}"); + if (ex is IOException) + return false; + + throw; + } + } + + private bool HasMetadata(ITaskItem item, string itemName, string metadataName) + { + if (!string.IsNullOrEmpty(item.GetMetadata(metadataName))) + return true; + + Log.LogError($"{itemName} item ({item.ItemSpec}) is missing Name metadata"); + return false; + } + + private static bool IsFileNewer(string sourceFile, string stampFile) + { + if (!File.Exists(sourceFile)) + return true; + + if (!File.Exists(stampFile)) + return true; + + return File.GetLastWriteTimeUtc(sourceFile) > File.GetLastWriteTimeUtc(stampFile); + } + + private record PackageReference(string Name, string Version, string? RestoredPath=null); + + private record ManifestInformation( + object Version, + string Description, + + [property: JsonPropertyName("depends-on")] + IDictionary DependsOn, + IDictionary Workloads, + IDictionary Packs, + object Data + ); + + private record WorkloadInformation( + bool Abstract, + string Kind, + string Description, + + List Packs, + List Extends, + List Platforms + ); + + private record PackVersionInformation( + string Kind, + string Version, + [property: JsonPropertyName("alias-to")] + Dictionary AliasTo + ); + } +} diff --git a/src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj b/src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj index 328672b45145b..537418ef31dc6 100644 --- a/src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj +++ b/src/tasks/WorkloadBuildTasks/WorkloadBuildTasks.csproj @@ -6,6 +6,8 @@ $(NoWarn),CA1050 + +