From 673524070d17a95d667a2a1774c6eb6275220d94 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 9 Dec 2024 19:07:29 +0100 Subject: [PATCH] [dotnet] Create and ship a WorkloadDependencies.json file. Fixes #21768. Fixes https://github.com/xamarin/xamarin-macios/issues/21768. --- dotnet/.gitignore | 1 + dotnet/Makefile | 8 ++++ dotnet/package/microsoft.workloads.csproj | 1 + .../README.md | 1 + .../fragment.mk | 2 + .../generate-workloaddependencies-json.cs | 39 +++++++++++++++++++ .../generate-workloaddependencies-json.csproj | 5 +++ 7 files changed, 57 insertions(+) create mode 100644 scripts/generate-workloaddependencies-json/README.md create mode 100644 scripts/generate-workloaddependencies-json/fragment.mk create mode 100644 scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.cs create mode 100644 scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.csproj diff --git a/dotnet/.gitignore b/dotnet/.gitignore index d0aedbaff198..a125da98bf78 100644 --- a/dotnet/.gitignore +++ b/dotnet/.gitignore @@ -2,6 +2,7 @@ tmpdir Workloads/Microsoft.NET.Sdk.*/LICENSE WorkloadManifest.json WorkloadManifest.targets +WorkloadDependencies.json nupkgs Microsoft.*.Sdk/targets/Microsoft.*.Sdk.ImplicitNamespaceImports.props Microsoft.*.Sdk/targets/Microsoft.*.Sdk.SupportedTargetPlatforms.props diff --git a/dotnet/Makefile b/dotnet/Makefile index 1e34e33d16d4..a0937bccbdfe 100644 --- a/dotnet/Makefile +++ b/dotnet/Makefile @@ -183,6 +183,7 @@ $(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call SupportedTargetPlatforms,$( include $(TOP)/scripts/generate-workloadmanifest-json/fragment.mk include $(TOP)/scripts/generate-workloadmanifest-targets/fragment.mk +include $(TOP)/scripts/generate-workloaddependencies-json/fragment.mk define WorkloadTargets Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json: Makefile $(TOP)/Make.config.inc $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index Makefile $(GENERATE_WORKLOADMANIFEST_JSON) | Workloads/Microsoft.NET.Sdk.$(1) $$(Q) rm -f $$@.tmp @@ -194,15 +195,22 @@ Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.targets: Makefile $(TOP)/Make. $$(Q_GEN) $(GENERATE_WORKLOADMANIFEST_TARGETS_EXEC) "$(1)" "$$@.tmp" "$$(DOTNET_WINDOWS_PLATFORMS)" "$(DOTNET_TFM)_$$($(4)_NUGET_OS_VERSION)" "$(SUPPORTED_API_VERSIONS_$(4))" $$(Q) mv $$@.tmp $$@ +Workloads/Microsoft.NET.Sdk.$(1)/WorkloadDependencies.json: Makefile $(TOP)/Make.config.inc $(GIT_DIRECTORY)/HEAD $(GIT_DIRECTORY)/index Makefile $(GENERATE_WORKLOADDEPENDENCIES_JSON) | Workloads/Microsoft.NET.Sdk.$(1) + $$(Q) rm -f $$@.tmp + $$(Q_GEN) $(GENERATE_WORKLOADDEPENDENCIES_JSON_EXEC) "$(1)" "$$($(4)_NUGET_VERSION_NO_METADATA)" "$(XCODE_VERSION)" "$$($(4)_NUGET_OS_VERSION)" "$$@.tmp" + $$(Q) mv $$@.tmp $$@ + Workloads/Microsoft.NET.Sdk.$(1)/LICENSE: $(TOP)/LICENSE | Workloads/Microsoft.NET.Sdk.$(1) $$(Q) $(CP) $$< $$@ WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.targets +WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadDependencies.json WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/LICENSE LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.targets +LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadDependencies.json LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/LICENSE endef $(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call WorkloadTargets,$(platform),$(shell echo $(platform) | tr A-Z a-z),$($(platform)_NUGET_VERSION_NO_METADATA),$(shell echo $(platform) | tr a-z A-Z),$(NET8_$(platform)_NUGET_VERSION_NO_METADATA)))) diff --git a/dotnet/package/microsoft.workloads.csproj b/dotnet/package/microsoft.workloads.csproj index 901fe5b1a8c7..0d288b8ec87f 100644 --- a/dotnet/package/microsoft.workloads.csproj +++ b/dotnet/package/microsoft.workloads.csproj @@ -9,5 +9,6 @@ + diff --git a/scripts/generate-workloaddependencies-json/README.md b/scripts/generate-workloaddependencies-json/README.md new file mode 100644 index 000000000000..7f65c098f983 --- /dev/null +++ b/scripts/generate-workloaddependencies-json/README.md @@ -0,0 +1 @@ +# generate-workload-dependencies diff --git a/scripts/generate-workloaddependencies-json/fragment.mk b/scripts/generate-workloaddependencies-json/fragment.mk new file mode 100644 index 000000000000..dc98042c5e22 --- /dev/null +++ b/scripts/generate-workloaddependencies-json/fragment.mk @@ -0,0 +1,2 @@ +include $(TOP)/scripts/template.mk +$(eval $(call TemplateScript,GENERATE_WORKLOADDEPENDENCIES_JSON,generate-workloaddependencies-json)) diff --git a/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.cs b/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.cs new file mode 100644 index 000000000000..0b18f22d0572 --- /dev/null +++ b/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.cs @@ -0,0 +1,39 @@ +// arguments are: + +using System.IO; +using System.Xml; + +var expectedArgumentCount = 5; +if (args.Length != expectedArgumentCount) { + Console.WriteLine ($"Need {expectedArgumentCount} arguments, got {args.Length}"); + return 1; +} + +var argumentIndex = 0; +var platform = args [argumentIndex++]; +var version = args [argumentIndex++]; +var xcodeVersion = args [argumentIndex++]; +var sdkVersion = args [argumentIndex++]; +var outputPath = args [argumentIndex++]; + +var platformLowerCase = platform.ToLowerInvariant (); + +using (var writer = new StreamWriter (outputPath)) { + writer.WriteLine ($"{{"); + writer.WriteLine ($" \"microsoft.net.sdk.{platformLowerCase}\": {{"); + writer.WriteLine ($" \"workload\": {{"); + writer.WriteLine ($" \"alias\": [ \"{platformLowerCase}\" ],"); + writer.WriteLine ($" \"version\": \"{version}\""); + writer.WriteLine ($" }},"); + writer.WriteLine ($" \"xcode\": {{"); + writer.WriteLine ($" \"version\": \"[{xcodeVersion},)\","); + writer.WriteLine ($" \"recommendedVersion\": \"{xcodeVersion}\""); + writer.WriteLine ($" }},"); + writer.WriteLine ($" \"sdk\": {{"); + writer.WriteLine ($" \"version\": \"{sdkVersion}\""); + writer.WriteLine ($" }}"); + writer.WriteLine ($" }}"); + writer.WriteLine ($"}}"); +} + +return 0; diff --git a/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.csproj b/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.csproj new file mode 100644 index 000000000000..036ee45034c7 --- /dev/null +++ b/scripts/generate-workloaddependencies-json/generate-workloaddependencies-json.csproj @@ -0,0 +1,5 @@ + + + net$(BundledNETCoreAppTargetFrameworkVersion) + +