Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Improve the error message when the SupportedOSPlatformVersion is lower than the minimum. Fixes #21368. #21369

Merged
merged 9 commits into from
Oct 10, 2024
1 change: 1 addition & 0 deletions dotnet/generate-target-platforms.csharp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ using (TextWriter writer = new StreamWriter (outputPath)) {
writer.WriteLine ("\t</ItemGroup>");
writer.WriteLine ("\t<PropertyGroup>");
writer.WriteLine ($"\t\t<{platform}MinSupportedOSPlatformVersion>{minSdkVersionString}</{platform}MinSupportedOSPlatformVersion>");
writer.WriteLine ($"\t\t<MinSupportedOSPlatformVersion>$({platform}MinSupportedOSPlatformVersion)</MinSupportedOSPlatformVersion>");
writer.WriteLine ("\t</PropertyGroup>");
writer.WriteLine ("</Project>");
}
Expand Down
13 changes: 13 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,19 @@
<comment>RuntimeIdentifier: don't translate (it's the name of a MSBuild property)</comment>
</data>

<data name="E7125" xml:space="preserve">
<value>Unable to parse the value '{0}' for the property '{1}.</value>
<comment>
{0}: user-provided value
{1}: name of an MSBuild property
</comment>
</data>

<data name="E7126" xml:space="preserve">
<value>The SupportedOSPlatformVersion value '{0}' in the project file is lower than the minimum value '{1}'.</value>
<comment>SupportedOSPlatformVersion: don't translate (it's the name of an MSBuild property)</comment>
</data>

<data name="XcodeBuild_CreateNativeRef" xml:space="preserve">
<value>Adding reference to Xcode project output: '{0}'. The '%(CreateNativeReference)' metadata can be set to 'false' to opt out of this behavior.</value>
<comment>
Expand Down
15 changes: 15 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class CompileAppManifest : XamarinTask, ITaskCallback, ICancelableTask {

public bool IsWatchExtension { get; set; }

[Required]
public string MinSupportedOSPlatformVersion { get; set; } = string.Empty;

public ITaskItem [] PartialAppManifests { get; set; } = Array.Empty<ITaskItem> ();

[Required]
Expand Down Expand Up @@ -302,6 +305,18 @@ bool SetMinimumOSVersion (PDictionary plist)
minimumOSVersion = minimumOSVersionInManifest!;
}

// Verify that the value is not lower than the minimum
if (!Version.TryParse (MinSupportedOSPlatformVersion, out var minSupportedVersion)) {
Log.LogError (MSBStrings.E7125 /* Unable to parse the value '{0}' for the property '{1}. */, MinSupportedOSPlatformVersion, "MinSupportedOSPlatformVersion");
return false;
} else if (!Version.TryParse (SupportedOSPlatformVersion, out var supportedVersion)) {
Log.LogError (MSBStrings.E7125 /* Unable to parse the value '{0}' for the property '{1}. */, SupportedOSPlatformVersion, "SupportedOSPlatformVersion");
return false;
} else if (minSupportedVersion > supportedVersion) {
Log.LogError (MSBStrings.E7126 /* The SupportedOSPlatformVersion value '{0}' in the project file is lower than the minimum value '{1}'." */, SupportedOSPlatformVersion, MinSupportedOSPlatformVersion);
return false;
}

// Write out our value
plist [minimumVersionKey] = minimumOSVersion;

Expand Down
1 change: 1 addition & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
IsWatchApp="$(IsWatchApp)"
IsWatchExtension="$(IsWatchExtension)"
IsXPCService="$(IsXPCService)"
MinSupportedOSPlatformVersion="$(MinSupportedOSPlatformVersion)"
PartialAppManifests="@(PartialAppManifest)"
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ test.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Version.De
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)\n" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)\n" >> $@
@printf "XCODE_VERSION=$(XCODE_VERSION)\n" >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),DOTNET_MIN_$(platform)_SDK_VERSION=$(DOTNET_MIN_$(platform)_SDK_VERSION)\\n)" | sed 's/^ //' >> $@

test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Version.Details.xml
@rm -f $@
Expand Down Expand Up @@ -122,6 +123,7 @@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Ver
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)\n" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)\n" >> $@
@printf "XCODE_VERSION=$(XCODE_VERSION)\n" >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),DOTNET_MIN_$(platform)_SDK_VERSION=$(DOTNET_MIN_$(platform)_SDK_VERSION)\\n)" | sed 's/^ //' >> $@

clean-local::
$(Q) $(SYSTEM_XBUILD) /t:Clean /p:Platform=iPhoneSimulator /p:Configuration=$(CONFIG) $(XBUILD_VERBOSITY) tests.sln
Expand Down
28 changes: 27 additions & 1 deletion tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ public void UnsupportedTargetPlatformVersion (ApplePlatform platform)
// Pick a target platform version that we don't really support,
// but don't show an error in .NET 8 because of backwards compat.
// The earliest target OS version should do.
var minSupportedOSVersion = GetSupportedTargetPlatformVersions (platform).First ();
var minSupportedOSVersion = GetMinSupportedOSPlatformVersion (platform);
var targetFrameworks = Configuration.DotNetTfm + "-" + platform.AsString ().ToLowerInvariant () + minSupportedOSVersion;
var supportedApiVersions = GetSupportedApiVersions (platform, isCompat: false);

Expand Down Expand Up @@ -1914,6 +1914,11 @@ string [] GetSupportedTargetPlatformVersions (ApplePlatform platform)
.ToArray ();
}

string GetMinSupportedOSPlatformVersion (ApplePlatform platform)
{
return Configuration.GetVariable ($"DOTNET_MIN_{platform.AsString ().ToUpperInvariant ()}_SDK_VERSION", "unknown MinSupportedOSPlatformVersion");
}

[Test]
[TestCase (ApplePlatform.MacCatalyst, "MtouchArch", "x86_64")]
[TestCase (ApplePlatform.iOS, "MtouchArch", "ARMv7s")]
Expand Down Expand Up @@ -2837,5 +2842,26 @@ static HashSet<string> GetLinkedWithFrameworks (string path)
}
return rv;
}

[Test]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64", "13.1")]
[TestCase (ApplePlatform.iOS, "ios-arm64", "10.0")]
[TestCase (ApplePlatform.TVOS, "tvossimulator-x64", "10.0")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64", "10.0")]
public void InvalidSupportedOSPlatformVersion (ApplePlatform platform, string runtimeIdentifiers, string version)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);

var minVersion = GetMinSupportedOSPlatformVersion (platform);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["SupportedOSPlatformVersion"] = version;
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
AssertErrorMessages (errors, $"The SupportedOSPlatformVersion value '{version}' in the project file is lower than the minimum value '{minVersion}'.");
}
}
}
Loading