Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Make.config
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ endif

# Tell both Xcode and our build logic which Xcode we're using.
export DEVELOPER_DIR=$(XCODE_DEVELOPER_ROOT)
export MD_APPLE_SDK_ROOT=$(abspath $(XCODE_DEVELOPER_ROOT)/../..)
else
# On Linux, set placeholder Xcode values but honor XCODE_CHANNEL so we configure bots correctly
XCODE_PRODUCT_BUILD_VERSION=
Expand Down
15 changes: 15 additions & 0 deletions docs/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,21 @@ Consider using the unified [AppBundleResourcePrefix](#appbundleresourceprefix) p

See also [IPhoneResourcePrefix](#iphoneresourceprefix) and [MonoMacResourcePrefix](#monomacresourceprefix).

## XcodeLocation

Specifies the location of Xcode.

When the build searches for Xcode, it's done in this order:

1. If the `XcodeLocation` property is set, use that. Note that since all environment variables are automatically MSBuild properties as well, it's also possible to set the `XcodeLocation` environment variable for the same effect.
2. If the `MD_APPLE_SDK_ROOT` environment variable is set, use that.
3. If either of the files `~/Library/Preferences/maui/Settings.plist` or `~/Library/Preferences/Xamarin/Settings.plist` exist, and has the property list value `AppleSdkRoot`, use that.
4. Use the system version of Xcode (as determined by executing `xcode-select --print-path`).

> [!WARNING]
> Support for the `MD_APPLE_SDK_ROOT` environment variable, and the `~/Library/Preferences/maui/Settings.plist` and `~/Library/Preferences/Xamarin/Settings.plist` files, is deprecated and will be removed in the future.
> Going forward, choose which Xcode to use by either making it the system's version of Xcode (either using `xcode-select --switch ...` on the command line, or in Xcode's settings), or by setting the `XcodeLocation` MSBuild property / environment variable.

## ZipPath

The full path to the `zip` command-line tool.
Expand Down
16 changes: 16 additions & 0 deletions msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1627,4 +1627,20 @@
<data name="E7169" xml:space="preserve">
<value>The task '{0}' requires the property '{1}' to be set. Please file an issue at https://github.com/dotnet/macios/issues/new/choose.</value>
</data>

<data name="W7171" xml:space="preserve">
<value>The environment variable '{0}' is deprecated, and will be ignored in .NET 11+. Please use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use.</value>
</data>

<data name="W7172" xml:space="preserve">
<value>The environment variable '{0}' is deprecated, and will be ignored. Please use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use.</value>
</data>

<data name="W7173" xml:space="preserve">
<value>The settings file '{0}' is deprecated, and will be ignored in .NET 11+. Please use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use.</value>
</data>

<data name="W7174" xml:space="preserve">
<value>The settings file '{0}' is deprecated, and will be ignored. Please use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use.</value>
</data>
</root>
61 changes: 0 additions & 61 deletions msbuild/Xamarin.MacDev.Tasks/Sdks.cs

This file was deleted.

14 changes: 6 additions & 8 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool SetMinimumOSVersion (PDictionary plist)
if (Platform == ApplePlatform.MacCatalyst && !string.IsNullOrEmpty (SupportedOSPlatformVersion)) {
// SupportedOSPlatformVersion is the iOS version for Mac Catalyst.
// But we need to store the macOS version in the app manifest, so convert it to the macOS version here.
if (!MacCatalystSupport.TryGetMacOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), SupportedOSPlatformVersion, out var convertedVersion, out var knowniOSVersions)) {
if (!MacCatalystSupport.TryGetMacOSVersion (CurrentSdk.GetSdkPath (SdkVersion), SupportedOSPlatformVersion, out var convertedVersion, out var knowniOSVersions)) {
Log.LogError (MSBStrings.E0188, SupportedOSPlatformVersion, string.Join (", ", knowniOSVersions.OrderBy (v => v)));
return false;
}
Expand All @@ -250,7 +250,7 @@ bool SetMinimumOSVersion (PDictionary plist)
var minimumiOSVersionInManifest = plist.Get<PString> (ManifestKeys.MinimumOSVersion)?.Value;
if (!string.IsNullOrEmpty (minimumiOSVersionInManifest)) {
// Convert to the macOS version
if (!MacCatalystSupport.TryGetMacOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), minimumiOSVersionInManifest!, out var convertedVersion, out var knowniOSVersions)) {
if (!MacCatalystSupport.TryGetMacOSVersion (CurrentSdk.GetSdkPath (SdkVersion), minimumiOSVersionInManifest!, out var convertedVersion, out var knowniOSVersions)) {
Log.LogError (MSBStrings.E0188, minimumiOSVersionInManifest, string.Join (", ", knowniOSVersions.OrderBy (v => v)));
return false;
}
Expand Down Expand Up @@ -313,14 +313,12 @@ bool Compile (PDictionary plist)
return false;
}

var currentSDK = Sdks.GetAppleSdk (Platform);

sdkVersion = AppleSdkVersion.Parse (DefaultSdkVersion);
if (!currentSDK.SdkIsInstalled (sdkVersion, SdkIsSimulator)) {
if (!CurrentSdk.SdkIsInstalled (sdkVersion, SdkIsSimulator)) {
Log.LogError (null, null, null, null, 0, 0, 0, 0, MSBStrings.E0013, Platform, sdkVersion);
return false;
}
SetXcodeValues (plist, currentSDK);
SetXcodeValues (plist, CurrentSdk);
}

switch (Platform) {
Expand Down Expand Up @@ -428,7 +426,7 @@ void Validation (PDictionary plist)
GetMinimumOSVersion (plist, out var minimumOSVersion);
if (minimumOSVersion < new Version (11, 0)) {
string miniOSVersion = "?";
if (MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (SdkVersion), minimumOSVersion, out var iOSVersion, out var _))
if (MacCatalystSupport.TryGetiOSVersion (CurrentSdk.GetSdkPath (SdkVersion), minimumOSVersion, out var iOSVersion, out var _))
miniOSVersion = iOSVersion?.ToString () ?? "?";
LogAppManifestError (MSBStrings.E7099 /* The UIDeviceFamily value '6' requires macOS 11.0. Please set the 'SupportedOSPlatformVersion' in the project file to at least 14.0 (the Mac Catalyst version equivalent of macOS 11.0). The current value is {0} (equivalent to macOS {1}). */, miniOSVersion, minimumOSVersion);
}
Expand Down Expand Up @@ -514,7 +512,7 @@ void SetXcodeValues (PDictionary plist, IAppleSdk currentSDK)
SetValueIfNotNull (plist, "DTPlatformName", PlatformUtils.GetTargetPlatform (SdkPlatform, false));
SetValueIfNotNull (plist, "DTPlatformVersion", dtSettings.DTPlatformVersion);
SetValueIfNotNull (plist, "DTSDKName", sdkSettings.CanonicalName);
SetValueIfNotNull (plist, "DTXcode", AppleSdkSettings.DTXcode);
SetValueIfNotNull (plist, "DTXcode", GetXcodeLocator ().DTXcode);
SetValueIfNotNull (plist, "DTXcodeBuild", dtSettings.DTXcodeBuild);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ string DefaultEntitlementsPath {
return "Entitlements.plist";
}

return Path.Combine (Sdks.GetAppleSdk (TargetFrameworkMoniker).GetSdkPath (SdkVersion, false), "Entitlements.plist");
return Path.Combine (CurrentSdk.GetSdkPath (SdkVersion, false), "Entitlements.plist");
}
}

Expand Down
60 changes: 31 additions & 29 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public string SdkRoot {
get; set;
} = "";

// this is input too (the variable 'XcodeLocation')
[Output]
public new string SdkDevPath {
get => base.SdkDevPath;
Expand Down Expand Up @@ -59,12 +60,6 @@ public string XcodeVersion {

#endregion Outputs

protected IAppleSdk CurrentSdk {
get {
return Sdks.GetAppleSdk (Platform);
}
}

IAppleSdkVersion GetDefaultSdkVersion ()
{
switch (Platform) {
Expand Down Expand Up @@ -145,33 +140,40 @@ bool ExecuteImpl ()
return ExecuteRemotely ();
}

AppleSdkSettings.Init ();

if (EnsureAppleSdkRoot ())
EnsureSdkPath ();
EnsureXamarinSdkRoot ();
var isNet11OrNewer = TargetFramework.Version.Major >= 11;
var appleSdkSettings = GetXcodeLocator (initialDiscovery: true, (locator) => {
locator.SupportEnvironmentVariableLookup = !isNet11OrNewer;
locator.SupportSettingsFileLookup = !isNet11OrNewer;
});
SetXcodeLocator (appleSdkSettings);
SdkDevPath = appleSdkSettings.DeveloperRoot;
XcodeVersion = appleSdkSettings.XcodeVersion.ToString ();

if (appleSdkSettings.SystemHasEnvironmentVariable) {
if (isNet11OrNewer) {
Log.LogWarning (MSBStrings.W7172 /* The environment variable '{0}' is deprecated, and will be ignored. Please set use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use. */, XcodeLocator.EnvironmentVariableName);
} else {
Log.LogWarning (MSBStrings.W7171 /* The environment variable '{0}' is deprecated, and will be ignored in .NET 11+. Please set use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use. */, XcodeLocator.EnvironmentVariableName);
}
}
foreach (var file in appleSdkSettings.SystemExistingSettingsFiles) {
if (isNet11OrNewer) {
Log.LogWarning (MSBStrings.W7174 /* The settings file '{0}' is deprecated, and will be ignored. Please set use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use. */, file);
} else {
Log.LogWarning (MSBStrings.W7173 /* The settings file '{0}' is deprecated, and will be ignored in .NET 11+. Please set use the 'DEVELOPER_DIR' environment variable or the 'XcodeLocation' MSBuild property to choose which Xcode to use. */, file);
}
}

XcodeVersion = AppleSdkSettings.XcodeVersion.ToString ();
if (Log.HasLoggedErrors)
return false;

return !Log.HasLoggedErrors;
}
Log.LogMessage (MessageImportance.Low, "DeveloperRoot: {0}", CurrentSdk.DeveloperRoot);
Log.LogMessage (MessageImportance.Low, "GetPlatformPath: {0}", CurrentSdk.GetPlatformPath (SdkIsSimulator));

protected bool EnsureAppleSdkRoot ()
{
var currentSdk = CurrentSdk;
if (!currentSdk.IsInstalled) {
Log.LogError (MSBStrings.E0044v2 /* Could not find a valid Xcode app bundle at '{0}'. Please verify that 'xcode-select -p' points to your Xcode installation. For more information see https://aka.ms/macios-missing-xcode. */, AppleSdkSettings.InvalidDeveloperRoot);
return false;
}
Log.LogMessage (MessageImportance.Low, "DeveloperRoot: {0}", currentSdk.DeveloperRoot);
Log.LogMessage (MessageImportance.Low, "GetPlatformPath: {0}", currentSdk.GetPlatformPath (SdkIsSimulator));
EnsureSdkPath ();
EnsureXamarinSdkRoot ();

SdkDevPath = currentSdk.DeveloperRoot;
if (string.IsNullOrEmpty (SdkDevPath)) {
Log.LogError (MSBStrings.E0086 /* Could not find a valid Xcode developer path */);
return false;
}
return true;
return !Log.HasLoggedErrors;
}

protected string? DirExists (string checkingFor, params string [] paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public class DetectSigningIdentity : XamarinTask, ITaskCallback, ICancelableTask
static readonly string [] macDirectDistributionPrefixes = { "Developer ID Application" };
static readonly string [] macDevelopmentPrefixes = { "Mac Developer", "Apple Development" };

protected string DeveloperRoot {
get {
return Sdks.GetAppleSdk (TargetFrameworkMoniker).DeveloperRoot;
}
}

protected string [] DevelopmentPrefixes {
get {
switch (Platform) {
Expand Down Expand Up @@ -583,7 +577,7 @@ bool ExecuteImpl ()
else if (ProvisioningProfile == AutomaticAdHocProvision)
type = MobileProvisionDistributionType.AdHoc;

DetectedCodesignAllocate = Path.Combine (DeveloperRoot, "Toolchains", "XcodeDefault.xctoolchain", "usr", "bin", "codesign_allocate");
DetectedCodesignAllocate = Path.Combine (CurrentSdk.DeveloperRoot, "Toolchains", "XcodeDefault.xctoolchain", "usr", "bin", "codesign_allocate");
DetectedDistributionType = type.ToString ();

identity.BundleId = BundleIdentifier;
Expand Down
2 changes: 1 addition & 1 deletion msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override bool Execute ()
if (Platform == ApplePlatform.MacCatalyst) {
// The minimum version in the Info.plist is the macOS version. However, the rest of our tooling
// expects the iOS version, so expose that.
if (!MacCatalystSupport.TryGetiOSVersion (Sdks.GetAppleSdk (Platform).GetSdkPath (), MinimumOSVersion!, out var convertedVersion, out var knownMacOSVersions))
if (!MacCatalystSupport.TryGetiOSVersion (CurrentSdk.GetSdkPath (), MinimumOSVersion!, out var convertedVersion, out var knownMacOSVersions))
Log.LogError (MSBStrings.E0187, MinimumOSVersion, string.Join (", ", knownMacOSVersions.OrderBy (v => v)));
MinimumOSVersion = convertedVersion;
}
Expand Down
46 changes: 46 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,52 @@ public string GetSdkDevPath ()
return SdkDevPath;
}

XcodeLocator? xcodeLocator = null;
public XcodeLocator GetXcodeLocator (bool initialDiscovery = false, Action<XcodeLocator>? preprocess = null)
{
if (xcodeLocator is null) {
if (!initialDiscovery && string.IsNullOrEmpty (SdkDevPath)) {
Log.LogError (MSBStrings.E7169, /* The task '{0}' requires the property '{1}' to be set. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. */ GetType ().Name, "SdkDevPath");
}

var xcodeLocator = new XcodeLocator (this);
preprocess?.Invoke (xcodeLocator);
if (!xcodeLocator.TryLocatingXcode (SdkDevPath))
Log.LogError (MSBStrings.E0086 /* Could not find a valid Xcode developer path */);
this.xcodeLocator = xcodeLocator;
}
return xcodeLocator;
}

protected void SetXcodeLocator (XcodeLocator xcodeLocator)
{
this.xcodeLocator = xcodeLocator;
}

IAppleSdk? currentSdk;
public IAppleSdk CurrentSdk {
get {
if (currentSdk is null) {
var xcodeLocator = GetXcodeLocator ();
switch (Platform) {
case ApplePlatform.iOS:
currentSdk = new AppleIPhoneSdk (xcodeLocator.DeveloperRoot, xcodeLocator.DeveloperRootVersionPlist);
break;
case ApplePlatform.TVOS:
currentSdk = new AppleTVOSSdk (xcodeLocator.DeveloperRoot, xcodeLocator.DeveloperRootVersionPlist);
break;
case ApplePlatform.MacCatalyst:
case ApplePlatform.MacOSX:
currentSdk = new MacOSXSdk (xcodeLocator.DeveloperRoot, xcodeLocator.DeveloperRootVersionPlist);
break;
default:
throw new InvalidOperationException (string.Format (MSBStrings.InvalidPlatform, Platform));
}
}
return currentSdk;
}
}

void VerifyTargetFrameworkMoniker ()
{
if (!string.IsNullOrEmpty (TargetFrameworkMoniker))
Expand Down
5 changes: 5 additions & 0 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
ResourceRules="$(_PreparedResourceRules)"
SdkDevPath="$(_SdkDevPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkVersion="$(_SdkVersion)"
SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)"
Expand All @@ -710,6 +711,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Condition="'$(IsMacEnabled)' == 'true' And '$(_BundleOriginalResources)' != 'true'"
SessionId="$(BuildSessionId)"
AppManifest="$(_TemporaryAppManifest)"
SdkDevPath="$(_SdkDevPath)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
<Output TaskParameter="CFBundleExecutable" PropertyName="_ExecutableName" />
Expand Down Expand Up @@ -797,6 +799,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Entitlements="$(CodesignEntitlements)"
CompiledEntitlements="$(_CompiledEntitlementsPath)"
ProvisioningProfile="$(_ProvisioningProfile)"
SdkDevPath="$(_SdkDevPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkPlatform="$(_SdkPlatform)"
SdkVersion="$(_SdkVersion)"
Expand Down Expand Up @@ -2069,6 +2072,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
SdkIsSimulator="$(_SdkIsSimulator)"
SdkPlatform="$(_SdkPlatform)"
ProvisioningProfile="$(CodesignProvision)"
SdkDevPath="$(_SdkDevPath)"
SigningKey="$(_SpecifiedCodesignKey)"
DetectedCodeSigningKey="$(_CodeSigningKey)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Expand All @@ -2091,6 +2095,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<DetectSdkLocations
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
SdkDevPath="$(XcodeLocation)"
SdkVersion="$(_SdkVersion)"
SdkIsSimulator="$(SdkIsSimulator)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Expand Down
3 changes: 3 additions & 0 deletions tests/common/BinLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ public static IEnumerable<BuildLogEvent> GetBuildLogWarnings (string path)
.Where (v => v.Type == BuildLogEventType.Warning)
// We're often referencing earlier .NET projects (Touch.Unit/MonoTouch.Dialog), so ignore any out-of-support warnings.
.Where (v => v.Message?.Contains ("is out of support and will not receive security updates in the future") != true)
// Ignore any messages about the settings files, we get *a lot* of those
.Where (v => !(v.Message?.Contains ("The settings file '/Users/") == true && v.Message?.Contains ("/Library/Preferences/maui/Settings.plist' is deprecated, and will be ignored in .NET 11+. ") == true))
.Where (v => !(v.Message?.Contains ("The settings file '/Users/") == true && v.Message?.Contains ("/Library/Preferences/Xamarin/Settings.plist' is deprecated, and will be ignored in .NET 11+. ") == true))
;
}

Expand Down
Loading
Loading