diff --git a/Make.config b/Make.config index 34026f4745dc..f16135e554ea 100644 --- a/Make.config +++ b/Make.config @@ -223,7 +223,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)/../..) # We don't need to be told there are workload updates export DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE=true diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index c6f3be76c3a2..8ccb7e7358ea 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -944,7 +944,7 @@ @@ -967,6 +967,7 @@ Source="%(_DirectoriesToPublish.SourceDirectory)" Destination="%(_DirectoriesToPublish.TargetDirectory)" TouchDestinationFiles="true" + SdkDevPath="$(_SdkDevPath)" StampFile="%(_DirectoriesToPublish.StampLocation)" CreateOutputFiles="false" /> @@ -1274,7 +1275,7 @@ - + <_XamarinAOTCompilerCachePath>$(DeviceSpecificIntermediateOutputPath)aot-compiler-path-$(NETCoreSdkVersion).txt @@ -1293,6 +1294,7 @@ KeepTemporaryOutput="$(FindAotCompilerKeepKeepTemporaryOutput)" MonoAotCrossCompiler="@(MonoAotCrossCompiler)" RuntimeIdentifier="$(RuntimeIdentifier)" + SdkDevPath="$(_SdkDevPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" > @@ -1972,6 +1974,7 @@ _DetectSigningIdentity; _PrepareResourceRules; _AddDebugSymbolsToBundle; + _DetectSdkLocations; @@ -2203,6 +2206,7 @@ FrameworksDirectory="$(_AppFrameworksRelativePath)" IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)" NativeReferences="@(_NativeReferencesToResolve)" + SdkDevPath="$(_SdkDevPath)" SdkIsSimulator="$(_SdkIsSimulator)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" > @@ -2264,6 +2268,7 @@ Condition="'$(IsMacEnabled)' == 'true'" ZipFilePath="%(_CompressedPlugIns.Identity)" ExtractionPath="%(_CompressedPlugIns.ExtractionPath)" + SdkDevPath="$(_SdkDevPath)" > @@ -2307,6 +2312,7 @@ CopyToWindows="true" ZipFilePath="%(_CompressedXpcServices.Identity)" ExtractionPath="%(_CompressedXpcServices.ExtractionPath)" + SdkDevPath="$(_SdkDevPath)" > diff --git a/external/Xamarin.MacDev b/external/Xamarin.MacDev index 757b4f5b7e8e..8d6495b42028 160000 --- a/external/Xamarin.MacDev +++ b/external/Xamarin.MacDev @@ -1 +1 @@ -Subproject commit 757b4f5b7e8e2f60ecbea6de3967158cc4f77069 +Subproject commit 8d6495b4202877a8f849311fba290d7c4e345489 diff --git a/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx b/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx index cae2cb561191..b09a504c40e9 100644 --- a/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx +++ b/msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx @@ -1619,4 +1619,28 @@ Unable to copy the inputs to this task to the remote build server for unknown reasons. The build log may have more information. + + + The task '{0}' is trying to call an external process, but a path to Xcode has not been provided. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. + + + + 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. + + + + 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. + + + + 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. + + + + 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. + + + + The task '{0}' requires the property '{1}' to be set. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. + diff --git a/msbuild/Xamarin.MacDev.Tasks/Sdks.cs b/msbuild/Xamarin.MacDev.Tasks/Sdks.cs index ca04c9c665f1..17b7c0c04143 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Sdks.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Sdks.cs @@ -9,53 +9,24 @@ namespace Xamarin.MacDev { public static class Sdks { - public static AppleIPhoneSdk IOS { get; private set; } - public static MacOSXSdk MacOS { get; private set; } - public static AppleTVOSSdk TVOS { get; private set; } - - static Sdks () - { - IOS = new AppleIPhoneSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist); - TVOS = new AppleTVOSSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist); - MacOS = new MacOSXSdk (AppleSdkSettings.DeveloperRoot, AppleSdkSettings.DeveloperRootVersionPlist); - } - - public static AppleSdk GetSdk (ApplePlatform framework) + public static IAppleSdk GetAppleSdk (ApplePlatform framework, XcodeLocator appleSdk) { switch (framework) { case ApplePlatform.iOS: - return IOS; + return new AppleIPhoneSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist); case ApplePlatform.TVOS: - return TVOS; - default: - throw new InvalidOperationException (string.Format (MSBStrings.InvalidFramework, framework)); - } - } - - public static AppleSdk GetSdk (string targetFrameworkMoniker) - { - return GetSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker)); - } - - public static IAppleSdk GetAppleSdk (ApplePlatform framework) - { - switch (framework) { - case ApplePlatform.iOS: - return IOS; - case ApplePlatform.TVOS: - return TVOS; + return new AppleTVOSSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist); case ApplePlatform.MacCatalyst: case ApplePlatform.MacOSX: - return MacOS; + return new MacOSXSdk (appleSdk.DeveloperRoot, appleSdk.DeveloperRootVersionPlist); default: throw new InvalidOperationException (string.Format (MSBStrings.InvalidFramework, framework)); } } - public static IAppleSdk GetAppleSdk (string targetFrameworkMoniker) + public static IAppleSdk GetAppleSdk (string targetFrameworkMoniker, XcodeLocator appleSdk) { - return GetAppleSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker)); + return GetAppleSdk (PlatformFrameworkHelper.GetFramework (targetFrameworkMoniker), appleSdk); } - } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs index f7dfbcd5a93d..116dd0963344 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs @@ -58,10 +58,6 @@ public class ACTool : XcodeCompilerToolTask, ICancelableTask { HashSet brandAssetsInAssets = new (); // tvOS HashSet imageStacksInAssets = new (); // tvOS - protected override string DefaultBinDir { - get { return DeveloperRootBinDir; } - } - protected override string ToolName { get { return "actool"; } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompile.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompile.cs index 3adaa8afd0d9..f43551989ee6 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompile.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompile.cs @@ -36,9 +36,6 @@ public class AOTCompile : XamarinParallelTask, ITaskCallback, ICancelableTask { [Required] public string OutputDirectory { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - #region Output [Output] public ITaskItem []? AssemblyFiles { get; set; } @@ -341,7 +338,7 @@ public override bool Execute () environment [item.ItemSpec] = item.GetMetadata ("Value"); ForEach (listOfArguments, (arg) => { - ExecuteAsync (AOTCompilerPath, arg.Arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) + ExecuteAsync (AOTCompilerPath, arg.Arguments, environment: environment, showErrorIfFailure: false /* we show our own error below */) .ContinueWith ((v) => { if (v.Result.ExitCode != 0) Log.LogError (MSBStrings.E7118 /* Failed to AOT compile {0}, the AOT compiler exited with code {1} */, Path.GetFileName (arg.Input), v.Result.ExitCode); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/AlTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/AlTool.cs index 63e0de67c8bb..96e96c88fa54 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/AlTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/AlTool.cs @@ -27,9 +27,6 @@ public abstract class ALToolTaskBase : XamarinTask, ICancelableTask { [Required] public string FilePath { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - protected abstract string ALToolAction { get; } public override bool Execute () @@ -44,7 +41,7 @@ public override bool Execute () return false; cancellationTokenSource = new CancellationTokenSource (); - var rv = ExecuteAsync (Log, executable, args, sdkDevPath: SdkDevPath, cancellationToken: cancellationTokenSource.Token).Result; + var rv = ExecuteAsync (executable, args, cancellationToken: cancellationTokenSource.Token).Result; LogErrorsFromOutput (rv.StandardOutput?.ToString ()); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs index 803842390a4f..99a78200563c 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/BGen.cs @@ -286,7 +286,7 @@ public override bool Execute () return false; cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/Codesign.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/Codesign.cs index f1c25499eb98..d7d7579ff711 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/Codesign.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/Codesign.cs @@ -362,7 +362,7 @@ void Sign (SignInfo info) var environment = new Dictionary () { { "CODESIGN_ALLOCATE", GetCodesignAllocate (item) }, }; - var rv = ExecuteAsync (fileName, arguments, null, environment, mergeOutput: false).Result; + var rv = ExecuteAsync (fileName, arguments, environment, mergeOutput: false).Result; var exitCode = rv.ExitCode; var messages = rv.StandardOutput?.ToString () ?? string.Empty; diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs index c17f2793a349..a7a7ba527f1f 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileAppManifest.cs @@ -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 (GetSdk ().GetSdkPath (SdkVersion), SupportedOSPlatformVersion, out var convertedVersion, out var knowniOSVersions)) { Log.LogError (MSBStrings.E0188, SupportedOSPlatformVersion, string.Join (", ", knowniOSVersions.OrderBy (v => v))); return false; } @@ -250,7 +250,7 @@ bool SetMinimumOSVersion (PDictionary plist) var minimumiOSVersionInManifest = plist.Get (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 (GetSdk ().GetSdkPath (SdkVersion), minimumiOSVersionInManifest!, out var convertedVersion, out var knowniOSVersions)) { Log.LogError (MSBStrings.E0188, minimumiOSVersionInManifest, string.Join (", ", knowniOSVersions.OrderBy (v => v))); return false; } @@ -309,7 +309,7 @@ bool Compile (PDictionary plist) return false; } - var currentSDK = Sdks.GetAppleSdk (Platform); + var currentSDK = GetSdk (); sdkVersion = AppleSdkVersion.Parse (DefaultSdkVersion); if (!currentSDK.SdkIsInstalled (sdkVersion, SdkIsSimulator)) { @@ -408,6 +408,11 @@ protected void MergePartialPlistTemplates (PDictionary plist) MergePartialPLists (this, plist, PartialAppManifests); } + IAppleSdk GetSdk () + { + return Sdks.GetAppleSdk (Platform, GetXcodeLocator ()); + } + void Validation (PDictionary plist) { if (!Validate) @@ -424,7 +429,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 (GetSdk ().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); } @@ -510,7 +515,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); } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs index 4287190635c9..a55cd3ef31c2 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs @@ -117,7 +117,7 @@ string DefaultEntitlementsPath { return "Entitlements.plist"; } - return Path.Combine (Sdks.GetAppleSdk (TargetFrameworkMoniker).GetSdkPath (SdkVersion, false), "Entitlements.plist"); + return Path.Combine (Sdks.GetAppleSdk (TargetFrameworkMoniker, GetXcodeLocator ()).GetSdkPath (SdkVersion, false), "Entitlements.plist"); } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileNativeCode.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileNativeCode.cs index ea95c3530e4a..affd9e1f3fae 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileNativeCode.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileNativeCode.cs @@ -25,9 +25,6 @@ public class CompileNativeCode : XamarinTask, ICancelableTask, ITaskCallback { [Required] public string MinimumOSVersion { get; set; } = ""; - [Required] - public string SdkDevPath { get; set; } = ""; - [Required] public string SdkRoot { get; set; } = ""; @@ -142,7 +139,7 @@ public override bool Execute () arguments.Add ("-c"); arguments.Add (src); - processes [i] = ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath); + processes [i] = ExecuteAsync ("xcrun", arguments); } System.Threading.Tasks.Task.WaitAll (processes); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs index 3f50e6199dee..effd0434c231 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CompileSceneKitAssets.cs @@ -37,9 +37,6 @@ public class CompileSceneKitAssets : XamarinTask, ICancelableTask, IHasProjectDi [Required] public ITaskItem [] SceneKitAssets { get; set; } = Array.Empty (); - [Required] - public string SdkDevPath { get; set; } = ""; - [Required] public string SdkPlatform { get; set; } = ""; @@ -86,8 +83,7 @@ Task CopySceneKitAssets (string scnassets, string output, string intermediate) args.Add ($"--resources-folder-path={AppBundleName}"); var executable = GetExecutable (args, ToolName, CopySceneKitAssetsPath); - - return ExecuteAsync (executable, args, sdkDevPath: SdkDevPath, environment: environment, showErrorIfFailure: true); + return ExecuteAsync (executable, args, environment: environment, showErrorIfFailure: true); } static bool TryGetScnAssetsPath (string file, out string scnassets) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CoreMLCompiler.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CoreMLCompiler.cs index 29f19cff1f89..1ccbaff6f2ec 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CoreMLCompiler.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CoreMLCompiler.cs @@ -30,11 +30,6 @@ public class CoreMLCompiler : XamarinTask, ICancelableTask, IHasProjectDir, IHas [Required] public string ResourcePrefix { get; set; } = ""; - string sdkDevPath = ""; - public string SdkDevPath { - get { return string.IsNullOrEmpty (sdkDevPath) ? "/" : sdkDevPath; } - set { sdkDevPath = value; } - } #endregion #region Outputs @@ -60,7 +55,7 @@ int Compile (ITaskItem item, string outputDir, string log, string partialPlist) args.Add (partialPlist); var executable = GetExecutable (args, ToolName, CoreMlcPath); - var rv = ExecuteAsync (executable, args, sdkDevPath, mergeOutput: false).Result; + var rv = ExecuteAsync (executable, args, mergeOutput: false).Result; var exitCode = rv.ExitCode; var output = rv.StandardOutput!.ToString (); File.WriteAllText (log, output); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateAssetPack.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateAssetPack.cs index e91884c40685..264134ac29d2 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateAssetPack.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateAssetPack.cs @@ -80,7 +80,7 @@ public override bool Execute () var args = GenerateCommandLineCommands (); var executable = GetExecutable (args, "zip", ZipPath); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, workingDirectory: GetWorkingDirectory (), cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, workingDirectory: GetWorkingDirectory (), cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateInstallerPackage.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateInstallerPackage.cs index 6b3b1509fbf2..9abca409643b 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateInstallerPackage.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/CreateInstallerPackage.cs @@ -81,7 +81,7 @@ public override bool Execute () var args = GenerateCommandLineCommands (); var executable = GetExecutable (args, "productbuild", ProductBuildPath); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, workingDirectory: OutputDirectory, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, workingDirectory: OutputDirectory, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/DSymUtil.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/DSymUtil.cs index 58011d2fbc90..bb3abba9483c 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/DSymUtil.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/DSymUtil.cs @@ -21,9 +21,6 @@ public class DSymUtil : XamarinTask, ITaskCallback { [Required] public ITaskItem [] Executable { get; set; } = Array.Empty (); - [Required] - public string SdkDevPath { get; set; } = string.Empty; - #endregion #region Outputs @@ -65,7 +62,7 @@ void ExecuteDSymUtil (ITaskItem item, List contentFiles) args.Add (dSymDir); args.Add (Path.GetFullPath (item.ItemSpec)); - ExecuteAsync ("xcrun", args, sdkDevPath: SdkDevPath).Wait (); + ExecuteAsync ("xcrun", args).Wait (); var contentsDir = Path.Combine (dSymDir, "Contents"); if (Directory.Exists (contentsDir)) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs index 8b62df6c88e7..1839138f8e06 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs @@ -13,18 +13,6 @@ namespace Xamarin.MacDev.Tasks { public class DetectSdkLocations : XamarinTask, ICancelableTask { const string SdkVersionDefaultValue = "default"; - #region Inputs - - public string TargetArchitectures { - get; set; - } = ""; - - public string IsDotNetSimulatorBuild { - get; set; - } = ""; - - #endregion Inputs - #region Outputs [Output] @@ -32,10 +20,12 @@ public string SdkRoot { get; set; } = ""; + // this is input too (the variable 'XcodeLocation') [Output] - public string SdkDevPath { - get; set; - } = ""; + public new string SdkDevPath { + get => base.SdkDevPath; + set => base.SdkDevPath = value; + } [Output] public bool SdkIsSimulator { @@ -68,10 +58,12 @@ public string XcodeVersion { protected IAppleSdk CurrentSdk { get { - return Sdks.GetAppleSdk (Platform); + return Sdks.GetAppleSdk (Platform, GetXcodeLocator ()); } } + XcodeLocator? appleSdkSettings; + IAppleSdkVersion GetDefaultSdkVersion () { switch (Platform) { @@ -152,43 +144,44 @@ bool ExecuteImpl () return ExecuteRemotely (); } - AppleSdkSettings.Init (); + var isNet11OrNewer = TargetFramework.Version.Major >= 11; + appleSdkSettings = GetXcodeLocator (initialDiscovery: true, (locator) => { + locator.SupportEnvironmentVariableLookup = !isNet11OrNewer; + locator.SupportSettingsFileLookup = !isNet11OrNewer; + }); + SdkDevPath = appleSdkSettings.DeveloperRoot; + XcodeVersion = appleSdkSettings.XcodeVersion.ToString (); + + if (appleSdkSettings.SystemHasEnvironmentVariable) { + if (isNet11OrNewer) { + Log.LogWarning (MSBStrings.W7166 /* 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.W7165 /* 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.W7168 /* 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.W7167 /* 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); + } + } - SetIsSimulator (); + if (Log.HasLoggedErrors) + return false; if (EnsureAppleSdkRoot ()) EnsureSdkPath (); EnsureXamarinSdkRoot (); - XcodeVersion = AppleSdkSettings.XcodeVersion.ToString (); - return !Log.HasLoggedErrors; } - void SetIsSimulator () - { - switch (Platform) { - case ApplePlatform.MacCatalyst: - case ApplePlatform.MacOSX: - return; - } - - TargetArchitecture architectures; - if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures)) - architectures = TargetArchitecture.Default; - - if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) { - SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase); - } else { - SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0; - } - } - 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); + 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?.XcodeLocation); return false; } Log.LogMessage (MessageImportance.Low, "DeveloperRoot: {0}", currentSdk.DeveloperRoot); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs index f3797f0c3bca..a41f7b717115 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs @@ -31,7 +31,7 @@ public class DetectSigningIdentity : XamarinTask, ITaskCallback, ICancelableTask protected string DeveloperRoot { get { - return Sdks.GetAppleSdk (TargetFrameworkMoniker).DeveloperRoot; + return Sdks.GetAppleSdk (TargetFrameworkMoniker, GetXcodeLocator ()).DeveloperRoot; } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs index 89abe8e02b67..169af8dcddb2 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/Ditto.cs @@ -103,7 +103,7 @@ bool ExecuteImpl () } cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); // Create a list of all the files we've copied if (CreateOutputFiles) { diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs index 0c0f8efc00f6..f7356a66b15f 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetMlaunchArguments.cs @@ -27,9 +27,6 @@ public class GetMlaunchArguments : XamarinTask, ICancelableTask { public string AppManifestPath { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - public ITaskItem [] AdditionalArguments { get; set; } = Array.Empty (); public string DeviceName { get; set; } = string.Empty; public ITaskItem [] EnvironmentVariables { get; set; } = Array.Empty (); @@ -112,7 +109,7 @@ public IPhoneDeviceType DeviceType { var tmpfile = Path.GetTempFileName (); try { var output = new StringBuilder (); - var result = ExecuteAsync (MlaunchPath, new string [] { "--listsim", tmpfile }, SdkDevPath).Result; + var result = ExecuteAsync (MlaunchPath, new string [] { "--listsim", tmpfile }).Result; if (result.ExitCode != 0) return string.Empty; simulator_list = File.ReadAllText (tmpfile); @@ -130,7 +127,7 @@ public IPhoneDeviceType DeviceType { var tmpfile = Path.GetTempFileName (); try { var output = new StringBuilder (); - var result = ExecuteAsync (MlaunchPath, new string [] { $"--listdev:{tmpfile}", "--output-format:xml", "--use-amdevice:false" }, SdkDevPath).Result; + var result = ExecuteAsync (MlaunchPath, new string [] { $"--listdev:{tmpfile}", "--output-format:xml", "--use-amdevice:false" }).Result; if (result.ExitCode != 0) return string.Empty; device_list = File.ReadAllText (tmpfile); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs index 5ae4938b055e..748f1b7949c6 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs @@ -30,10 +30,6 @@ public class IBTool : XcodeCompilerToolTask, ICancelableTask { #endregion - protected override string DefaultBinDir { - get { return DeveloperRootBinDir; } - } - protected override string ToolName { get { return "ibtool"; } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/InstallNameTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/InstallNameTool.cs index 8430835aefee..16fb7e140fcb 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/InstallNameTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/InstallNameTool.cs @@ -15,9 +15,6 @@ public class InstallNameTool : XamarinTask, ITaskCallback { [Required] public ITaskItem [] DynamicLibrary { get; set; } = []; - [Required] - public string SdkDevPath { get; set; } = ""; - // This isn't consumed from the targets files, but it's needed for VSX to create corresponding // files on Windows. [Output] @@ -50,7 +47,7 @@ public override bool Execute () arguments.Add (input.GetMetadata ("DynamicLibraryId")); arguments.Add (temporaryTarget); - processes [i] = ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath).ContinueWith ((v) => { + processes [i] = ExecuteAsync ("xcrun", arguments).ContinueWith ((v) => { if (v.IsFaulted) throw v.Exception; if (v.Status == TaskStatus.RanToCompletion) { diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCode.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCode.cs index c7f3d06c0264..62c71cf36dcd 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCode.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/LinkNativeCode.cs @@ -21,9 +21,6 @@ public class LinkNativeCode : XamarinTask, ITaskCallback { // A path to entitlements to be embedded into the executable public string EntitlementsInExecutable { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - [Required] public bool SdkIsSimulator { get; set; } @@ -213,7 +210,7 @@ bool ExecuteUnsafe () arguments.Add (flag.ItemSpec); } - var rv = ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath, showErrorIfFailure: false).Result; + var rv = ExecuteAsync ("xcrun", arguments, showErrorIfFailure: false).Result; if (rv.ExitCode != 0) { var stderr = rv.StandardError?.ToString ()?.Trim (); #if NET @@ -284,7 +281,7 @@ string ConvertEntitlementsToDerEntitlements (string entitlements) "-o", derEntitlements, "--raw", }; - ExecuteAsync ("xcrun", arguments, sdkDevPath: SdkDevPath).Wait (); + ExecuteAsync ("xcrun", arguments).Wait (); return derEntitlements; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/MergeAppBundles.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/MergeAppBundles.cs index 5f8fcf89c516..8cde9a9aa2a6 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/MergeAppBundles.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/MergeAppBundles.cs @@ -46,9 +46,6 @@ public partial class MergeAppBundles : XamarinTask { [Required] public string OutputAppBundle { get; set; } = ""; - [Required] - public string SdkDevPath { get; set; } = ""; - #endregion enum FileType { @@ -441,7 +438,7 @@ void MergeMachOFiles (string output, IList input) arguments.Add ("-output"); arguments.Add (output); arguments.AddRange (sourceFiles); - ExecuteAsync ("lipo", arguments, sdkDevPath: SdkDevPath).Wait (); + ExecuteAsync ("lipo", arguments).Wait (); } FileType GetFileType (string path) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/Metal.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/Metal.cs index 8e5c4b298ebe..46b75264f693 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/Metal.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/Metal.cs @@ -32,9 +32,6 @@ public class Metal : XamarinTask, IHasProjectDir, IHasResourcePrefix { [Required] public string ResourcePrefix { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - [Required] public string SdkVersion { get; set; } = string.Empty; @@ -96,7 +93,7 @@ public override bool Execute () args.Add (SourceFile!.ItemSpec); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/MetalLib.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/MetalLib.cs index 804c846c14fe..91fbff871bdd 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/MetalLib.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/MetalLib.cs @@ -25,9 +25,6 @@ public class MetalLib : XamarinTask, ITaskCallback { [Required] public string OutputLibrary { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - [Required] public string SdkRoot { get; set; } = string.Empty; @@ -54,7 +51,7 @@ public override bool Execute () var executable = GetExecutable (args, "metallib", MetalLibPath); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, environment: env, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeImage.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeImage.cs index 1b2dab4b0d55..27258b512c13 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeImage.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizeImage.cs @@ -29,9 +29,6 @@ public class OptimizeImage : XamarinParallelTask, ICancelableTask { public string PngCrushPath { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - #endregion static List GenerateCommandLineCommands (string inputImage, string outputImage) @@ -92,7 +89,7 @@ public override bool Execute () ForEach (listOfArguments, (arg) => { var args = arg.Arguments; var executable = GetExecutable (args, "pngcrush", PngCrushPath); - ExecuteAsync (Log, executable, args, sdkDevPath: SdkDevPath, mergeOutput: true, showErrorIfFailure: false /* we show our own error below */, cancellationToken: cancellationTokenSource.Token) + ExecuteAsync (executable, args, mergeOutput: true, showErrorIfFailure: false /* we show our own error below */, cancellationToken: cancellationTokenSource.Token) .ContinueWith ((v) => { Execution execution = v.Result; if (execution.ExitCode != 0) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs index a98b1f365849..e58b26e7893b 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs @@ -50,7 +50,7 @@ public override bool Execute () var args = GenerateCommandLineCommands (); var executable = GetExecutable (args, "plutil", PlutilPath); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs index 4a18efd376ea..effa19dda461 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ReadAppManifest.cs @@ -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 (Sdks.GetAppleSdk (Platform, GetXcodeLocator ()).GetSdkPath (), MinimumOSVersion!, out var convertedVersion, out var knownMacOSVersions)) Log.LogError (MSBStrings.E0187, MinimumOSVersion, string.Join (", ", knownMacOSVersions.OrderBy (v => v))); MinimumOSVersion = convertedVersion; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ScnTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ScnTool.cs index 5f8e9617c1a8..e1cb9484c562 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ScnTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ScnTool.cs @@ -39,9 +39,6 @@ public class ScnTool : XamarinParallelTask, IHasProjectDir, IHasResourcePrefix { [Required] public string SdkVersion { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - #endregion #region Outputs @@ -91,7 +88,7 @@ public override bool Execute () } ForEach (listOfArguments, (arg) => { - ExecuteAsync ("xcrun", arg.Arguments, sdkDevPath: SdkDevPath).Wait (); + ExecuteAsync ("xcrun", arg.Arguments).Wait (); }); BundleResources = bundleResources.ToArray (); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/SpotlightIndexer.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/SpotlightIndexer.cs index eff7361b6429..7d35f420e79d 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/SpotlightIndexer.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/SpotlightIndexer.cs @@ -33,7 +33,7 @@ public override bool Execute () }; var executable = GetExecutable (args, "mdimport", MdimportPath); cancellationTokenSource = new CancellationTokenSource (); - ExecuteAsync (Log, executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); + ExecuteAsync (executable, args, cancellationToken: cancellationTokenSource.Token).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs index 5316bf815b4d..d7f098942538 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs @@ -20,10 +20,6 @@ public class TextureAtlas : XcodeToolTaskBase, ICancelableTask { #endregion - protected override string DefaultBinDir { - get { return DeveloperRootBinDir; } - } - protected override string ToolName { get { return "TextureAtlas"; } } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs index b00c7fe335ab..3e6e0087a0d6 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/XamarinTask.cs @@ -23,11 +23,30 @@ public abstract class XamarinTask : Task, IHasSessionId, ICustomLogger { public string TargetFrameworkMoniker { get; set; } = string.Empty; + public string SdkDevPath { get; set; } = string.Empty; + + XcodeLocator? xcodeLocator = null; + public XcodeLocator GetXcodeLocator (bool initialDiscovery = false, Action? 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; + } + void VerifyTargetFrameworkMoniker () { if (!string.IsNullOrEmpty (TargetFrameworkMoniker)) return; - Log.LogError ($"The task {GetType ().Name} requires TargetFrameworkMoniker to be set."); + 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, "TargetFrameworkMoniker"); } public string Product { @@ -97,19 +116,25 @@ protected string GetSdkPlatform (bool isSimulator) return PlatformFrameworkHelper.GetSdkPlatform (Platform, isSimulator); } - internal protected System.Threading.Tasks.Task ExecuteAsync (string fileName, IList arguments, string? sdkDevPath = null, Dictionary? environment = null, bool mergeOutput = true, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) + internal protected System.Threading.Tasks.Task ExecuteAsync (string fileName, IList arguments, Dictionary? environment = null, bool mergeOutput = true, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) { - return ExecuteAsync (Log, fileName, arguments, sdkDevPath, environment, mergeOutput, showErrorIfFailure, workingDirectory, cancellationToken); + return ExecuteAsync (this, fileName, arguments, SdkDevPath, environment, mergeOutput, showErrorIfFailure, workingDirectory, cancellationToken); } static int executionCounter; - internal protected static async System.Threading.Tasks.Task ExecuteAsync (TaskLoggingHelper log, string fileName, IList arguments, string? sdkDevPath = null, Dictionary? environment = null, bool mergeOutput = true, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) + static async System.Threading.Tasks.Task ExecuteAsync (Task task, string fileName, IList arguments, string? sdkDevPath = null, Dictionary? environment = null, bool mergeOutput = true, bool showErrorIfFailure = true, string? workingDirectory = null, CancellationToken? cancellationToken = null) { + var log = task.Log; // Create a new dictionary if we're given one, to make sure we don't change the caller's dictionary. var launchEnvironment = environment is null ? new Dictionary () : new Dictionary (environment); if (!string.IsNullOrEmpty (sdkDevPath)) launchEnvironment ["DEVELOPER_DIR"] = sdkDevPath; + if (Environment.OSVersion.Platform == PlatformID.MacOSX && string.IsNullOrEmpty (sdkDevPath)) { + log.LogError (MSBStrings.E7164 /* The task '{0}' is trying to call an external process, but a path to Xcode has not been provided. Please file an issue at https://github.com/dotnet/macios/issues/new/choose. */, task.GetType ().Name); + log.LogMessage (MessageImportance.Low, Environment.StackTrace); + } + var currentId = Interlocked.Increment (ref executionCounter); log.LogMessage (MessageImportance.Normal, MSBStrings.M0001, currentId, fileName, StringUtils.FormatArguments (arguments)); // Started external tool execution #{0}: {1} {2} if (!string.IsNullOrEmpty (workingDirectory)) { diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeBuildTask.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeBuildTask.cs index dff2c77c4f0f..e71840ed899f 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeBuildTask.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeBuildTask.cs @@ -5,8 +5,6 @@ namespace Xamarin.MacDev.Tasks { public abstract class XcodeBuildTask : XamarinTask { // Task input parameters - public string SdkDevPath { get; set; } = string.Empty; - public string WorkingDirectory { get; set; } = string.Empty; public string OutputPath { get; set; } = string.Empty; @@ -25,7 +23,7 @@ public override bool Execute () } args.AddRange (GenerateCommandLineCommands ()); - ExecuteAsync ("xcrun", args, sdkDevPath: SdkDevPath, mergeOutput: false, workingDirectory: WorkingDirectory).Wait (); + ExecuteAsync ("xcrun", args, mergeOutput: false, workingDirectory: WorkingDirectory).Wait (); return !Log.HasLoggedErrors; } diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs index 38ad0fc3bc96..204ffcaf8888 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs @@ -41,16 +41,6 @@ public abstract class XcodeCompilerToolTask : XamarinTask, IHasProjectDir, IHasR [Required] public string SdkPlatform { get; set; } = string.Empty; - string? sdkDevPath; - public string SdkDevPath { -#if NET - get { return string.IsNullOrEmpty (sdkDevPath) ? "/" : sdkDevPath; } -#else - get { return (sdkDevPath is null || string.IsNullOrEmpty (sdkDevPath)) ? "/" : sdkDevPath; } -#endif - set { sdkDevPath = value; } - } - [Required] public string SdkVersion { get; set; } = string.Empty; @@ -97,14 +87,6 @@ public IPhoneDeviceType ParsedUIDeviceFamily { } } - protected abstract string DefaultBinDir { - get; - } - - protected string DeveloperRootBinDir { - get { return Path.Combine (SdkDevPath, "usr", "bin"); } - } - protected abstract string ToolName { get; } protected virtual bool UseCompilationDirectory { @@ -180,9 +162,6 @@ protected int Compile (ITaskItem [] items, string output, ITaskItem manifest) var environment = new Dictionary (); var args = new List (); - if (!string.IsNullOrEmpty (SdkDevPath)) - environment.Add ("DEVELOPER_DIR", SdkDevPath); - // workaround for ibtool[d] bug / asserts if Intel version is loaded string tool; if (IsTranslated ()) { @@ -219,7 +198,7 @@ protected int Compile (ITaskItem [] items, string output, ITaskItem manifest) if (Log.HasLoggedErrors) return 1; - var rv = ExecuteAsync (tool, args, sdkDevPath, environment: environment, mergeOutput: false).Result; + var rv = ExecuteAsync (tool, args, environment: environment, mergeOutput: false).Result; var exitCode = rv.ExitCode; var messages = rv.StandardOutput!.ToString (); File.WriteAllText (manifest.ItemSpec, messages); diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs index ee357deeaa0a..ec4f021133ab 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs @@ -14,8 +14,6 @@ namespace Xamarin.MacDev.Tasks { public abstract class XcodeToolTaskBase : XamarinTask, IHasProjectDir, IHasResourcePrefix { - string? toolExe; - #region Inputs [Required] @@ -27,13 +25,7 @@ public abstract class XcodeToolTaskBase : XamarinTask, IHasProjectDir, IHasResou [Required] public string ResourcePrefix { get; set; } = string.Empty; - [Required] - public string SdkDevPath { get; set; } = string.Empty; - - public string ToolExe { - get { return toolExe ?? ToolName; } - set { toolExe = value; } - } + public string ToolExe { get; set; } = string.Empty; public string ToolPath { get; set; } = string.Empty; @@ -46,22 +38,6 @@ public string ToolExe { #endregion - protected abstract string DefaultBinDir { - get; - } - - protected string DeveloperRootBinDir { - get { return Path.Combine (SdkDevPath, "usr", "bin"); } - } - - protected string DevicePlatformBinDir { - get { return Path.Combine (SdkDevPath, "Platforms", "iPhoneOS.platform", "Developer", "usr", "bin"); } - } - - protected string SimulatorPlatformBinDir { - get { return Path.Combine (SdkDevPath, "Platforms", "iPhoneSimulator.platform", "Developer", "usr", "bin"); } - } - protected abstract string ToolName { get; } protected abstract IEnumerable EnumerateInputs (); @@ -91,9 +67,7 @@ string GetFullPathToTool () if (!string.IsNullOrEmpty (ToolPath)) return Path.Combine (ToolPath, ToolExe); - var path = Path.Combine (DefaultBinDir, ToolExe); - - return File.Exists (path) ? path : ToolExe; + return ToolExe ?? ""; } int ExecuteTool (ITaskItem input, ITaskItem output) @@ -103,7 +77,8 @@ int ExecuteTool (ITaskItem input, ITaskItem output) AppendCommandLineArguments (environment, args, input, output); - var rv = ExecuteAsync (GetFullPathToTool (), args, environment: environment).Result; + var executable = GetExecutable (args, ToolName, GetFullPathToTool ()); + var rv = ExecuteAsync (executable, args, environment: environment).Result; return rv.ExitCode; } diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 83d5757f6bde..d721ca248e81 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -164,6 +164,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)" NativeReferences="@(_NativeReferencesToExpand)" References="@(_ReferencesWithNativeReferencesToExpand)" + SdkDevPath="$(_SdkDevPath)" SdkIsSimulator="$(_SdkIsSimulator)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" > @@ -182,7 +183,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. @@ -201,6 +202,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. BindingResourcePath="$(BindingResourcePath)" Compress="$(CompressBindingResourcePackage)" IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)" + SdkDevPath="$(_SdkDevPath)" > @@ -365,8 +367,8 @@ Copyright (C) 2018 Microsoft. All rights reserved. - - + + @@ -465,6 +467,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. BundleResources="@(Content);@(BundleResource)" ProjectDir="$(MSBuildProjectDirectory)" ResourcePrefix="$(_ResourcePrefix)" + SdkDevPath="$(_SdkDevPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" UnpackedResources="@(_UnpackedBundleResourceWithLogicalName)" > @@ -682,6 +685,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. ProjectDir="$(MSBuildProjectDirectory)" ResourcePrefix="$(_ResourcePrefix)" ResourceRules="$(_PreparedResourceRules)" + SdkDevPath="$(_SdkDevPath)" SdkIsSimulator="$(_SdkIsSimulator)" SdkVersion="$(_SdkVersion)" SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)" @@ -708,6 +712,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Condition="'$(IsMacEnabled)' == 'true' And '$(_BundleOriginalResources)' != 'true'" SessionId="$(BuildSessionId)" AppManifest="$(_TemporaryAppManifest)" + SdkDevPath="$(_SdkDevPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" > @@ -795,6 +800,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Entitlements="$(CodesignEntitlements)" CompiledEntitlements="$(_CompiledEntitlementsPath)" ProvisioningProfile="$(_ProvisioningProfile)" + SdkDevPath="$(_SdkDevPath)" SdkIsSimulator="$(_SdkIsSimulator)" SdkPlatform="$(_SdkPlatform)" SdkVersion="$(_SdkVersion)" @@ -1131,7 +1137,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. + DependsOnTargets="_BeforeCoreCompileSceneKitAssets;_GenerateBundleName;_ComputeTargetFrameworkMoniker;_SetResourceMetadata;_DetectSdkLocations"> <_GenerateBindingsDependsOn> + _DetectSdkLocations; _ComputeTargetFrameworkMoniker; $(_GenerateBindingsDependsOn); @@ -1966,6 +1973,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Condition="'$(IsMacEnabled)' == 'true' And '$(BindingProjectBuildSessionId)' != ''" IntermediateOutputPath="$(IntermediateOutputPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" + SdkDevPath="$(_SdkDevPath)" UseFloatingTargetPlatformVersion="$(UseFloatingTargetPlatformVersion)" > @@ -1998,6 +2006,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. ProjectDir="$(MSBuildProjectDirectory)" References="@(ReferencePath);@(BGenReferencePath)" ResponseFilePath="$(DeviceSpecificIntermediateOutputPath)response-file.rsp" + SdkDevPath="$(_SdkDevPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" BGenToolPath="$(BGenToolPath)" BGenToolExe="$(BGenToolExe)" @@ -2046,6 +2055,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. SdkPlatform="$(_SdkPlatform)" ProvisioningProfile="$(CodesignProvision)" SigningKey="$(_SpecifiedCodesignKey)" + SdkDevPath="$(_SdkDevPath)" DetectedCodeSigningKey="$(_CodeSigningKey)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" > @@ -2067,10 +2077,10 @@ Copyright (C) 2018 Microsoft. All rights reserved. @@ -2078,7 +2088,6 @@ Copyright (C) 2018 Microsoft. All rights reserved. - @@ -2577,6 +2586,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. DisallowResourcesSubdirectoryInAppBundle="$(CodesignDisallowResourcesSubdirectoryInAppBundle)" MaxDegreeOfParallelism="$(CodesignMaxDegreeOfParallelism)" Resources="@(_ComputedCodesignItems)" + SdkDevPath="$(_SdkDevPath)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" ToolExe="$(CodesignExe)" ToolPath="$(CodesignPath)" @@ -2730,7 +2740,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. @@ -2747,6 +2757,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Source="@(_ResolvedAppExtensionReferences)" Destination="$(_AppExtensionRoot)%(_ResolvedAppExtensionReferences.ContainerName)\%(_ResolvedAppExtensionReferences.FileName)%(_ResolvedAppExtensionReferences.Extension)" TouchDestinationFiles="true" + SdkDevPath="$(_SdkDevPath)" /> @@ -3094,6 +3105,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Executable="$(_AppContainerDir)%(_NativeStripItems.Identity)" Kind="%(_NativeStripItems.Kind)" MaxDegreeOfParallelism="$(SymbolStripMaxDegreeOfParallelism)" + SdkDevPath="$(_SdkDevPath)" StripPath="$(StripPath)" SymbolFile="%(_NativeStripItems.SymbolFile)" /> @@ -3131,6 +3143,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Condition="'$(IsMacEnabled)' == 'true'" Input="$(_AppContainerDir)" MdimportPath="$(MdimportPath)" + SdkDevPath="$(_SdkDevPath)" /> @@ -3165,6 +3178,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. ProjectGuid="$(ProjectGuid)" ProjectName="$(MSBuildProjectName)" ProjectTypeGuids="$(ProjectTypeGuids)" + SdkDevPath="$(_SdkDevPath)" SigningKey="$(_CodeSigningKey)" SolutionPath="$(SolutionPath)" RuntimeIdentifiers="$(RuntimeIdentifiers);$(RuntimeIdentifier)" @@ -3248,7 +3262,8 @@ Copyright (C) 2018 Microsoft. All rights reserved. _GetAppBundleEntitlements; Codesign; _CompileProductDefinition; - _WriteAppManifest + _WriteAppManifest; + _DetectSdkLocations; @@ -3271,6 +3286,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. ProductBuildPath="$(ProductBuildPath)" ProductDefinition="$(_CompiledProductDefinition)" ProjectPath="$(MSBuildProjectFullPath)" + SdkDevPath="$(_SdkDevPath)" > diff --git a/msbuild/Xamarin.Shared/Xamarin.iOS.Common.targets b/msbuild/Xamarin.Shared/Xamarin.iOS.Common.targets index e41b93ce7ac5..4a8fde95d01d 100644 --- a/msbuild/Xamarin.Shared/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.Shared/Xamarin.iOS.Common.targets @@ -259,17 +259,18 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. - + - + @@ -283,6 +284,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" DittoPath="$(DittoPath)" + SdkDevPath="$(_SdkDevPath)" Source="$(AppBundleDir)" Destination="$(_IpaAppBundleDir)" /> @@ -346,7 +348,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. - + <_PayloadDir>$(DeviceSpecificIntermediateOutputPath)ipa\Payload\ <_IpaAppBundleDir>$(_PayloadDir)$(_AppBundleName).app\ @@ -372,6 +374,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true' And Exists('$(DeviceSpecificOutputPath)OnDemandResources\')" DittoPath="$(DittoPath)" + SdkDevPath="$(_SdkDevPath)" Source="$(DeviceSpecificOutputPath)OnDemandResources\" Destination="$(_IntermediateODRDir)" /> @@ -416,6 +419,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. Keychain="$(CodesignKeychain)" Entitlements="$(_CompiledCodesignEntitlements)" Resources="@(_AssetPack)" + SdkDevPath="$(_SdkDevPath)" SigningKey="$(_CodeSigningKey)" ExtraArgs="$(CodesignExtraArgs)" > @@ -449,6 +453,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. Entitlements="$(_CompiledCodesignEntitlements)" ResourceRules="$(_PreparedResourceRules)" Resources="@(_IpaAppBundleToSign)" + SdkDevPath="$(_SdkDevPath)" SigningKey="$(_CodeSigningKey)" TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" ExtraArgs="$(CodesignExtraArgs)" @@ -463,6 +468,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. Source="%(_AssetPack.Identity)" OutputFile="$(IpaPackageDir)OnDemandResources\%(_AssetPack.DirectoryName)" ZipPath="$(ZipPath)" + SdkDevPath="$(_SdkDevPath)" /> diff --git a/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets b/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets index 18f47cefeb98..c46751d4d2bf 100644 --- a/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets +++ b/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets @@ -177,11 +177,11 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved. - + - + diff --git a/tests/common/BinLog.cs b/tests/common/BinLog.cs index f02f5123bfec..e8afbc729d96 100644 --- a/tests/common/BinLog.cs +++ b/tests/common/BinLog.cs @@ -210,6 +210,9 @@ public static IEnumerable 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)) ; } diff --git a/tests/common/Configuration.cs b/tests/common/Configuration.cs index 5bf45dd44bcd..3a5123316f9c 100644 --- a/tests/common/Configuration.cs +++ b/tests/common/Configuration.cs @@ -693,7 +693,7 @@ public static void SetBuildVariables (ApplePlatform platform, ref Dictionary (); - environment ["MD_APPLE_SDK_ROOT"] = Path.GetDirectoryName (Path.GetDirectoryName (xcode_root)); + environment ["DEVELOPER_DIR"] = Path.GetDirectoryName (Path.GetDirectoryName (xcode_root)); // This is set by `dotnet test` and can cause building legacy projects to fail to build with: // Microsoft.NET.Build.Extensions.ConflictResolution.targets(30,5): diff --git a/tests/dotnet/UnitTests/XcodeVersionTest.cs b/tests/dotnet/UnitTests/XcodeVersionTest.cs index a365af92f75e..301eb5e57fe0 100644 --- a/tests/dotnet/UnitTests/XcodeVersionTest.cs +++ b/tests/dotnet/UnitTests/XcodeVersionTest.cs @@ -35,16 +35,11 @@ public void Test (ApplePlatform platform, string xcodePath, Version xcodeVersion Clean (project_path); var properties = GetDefaultProperties (runtimeIdentifiers); properties ["BundleOriginalResources"] = "true"; // this prevents a different and unrelated error message from failing to build library projects + properties ["XcodeLocation"] = xcodePath; - var existingDeveloperDir = Environment.GetEnvironmentVariable ("MD_APPLE_SDK_ROOT"); - try { - Environment.SetEnvironmentVariable ("MD_APPLE_SDK_ROOT", Path.GetDirectoryName (Path.GetDirectoryName (xcodePath))); - var rv = DotNet.AssertBuildFailure (project_path, properties); - var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray (); - AssertErrorMessages (errors, $"This version of .NET for {platform.AsString ()} ({Configuration.GetNuGetVersionNoMetadata (platform)}) requires Xcode {Configuration.XcodeVersion}. The current version of Xcode is {xcodeVersion}. Either install Xcode {Configuration.XcodeVersion}, or use a different version of .NET for {platform.AsString ()}. See https://aka.ms/xcode-requirement for more information."); - } finally { - Environment.SetEnvironmentVariable ("MD_APPLE_SDK_ROOT", existingDeveloperDir); - } + var rv = DotNet.AssertBuildFailure (project_path, properties); + var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray (); + AssertErrorMessages (errors, $"This version of .NET for {platform.AsString ()} ({Configuration.GetNuGetVersionNoMetadata (platform)}) requires Xcode {Configuration.XcodeVersion}. The current version of Xcode is {xcodeVersion}. Either install Xcode {Configuration.XcodeVersion}, or use a different version of .NET for {platform.AsString ()}. See https://aka.ms/xcode-requirement for more information."); } } } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/AssemblySetup.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/AssemblySetup.cs index 4c485e135bee..ebe462f05921 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/AssemblySetup.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/AssemblySetup.cs @@ -17,7 +17,7 @@ public void AssemblyInitialization () const string msbuild_exe_path = "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin/MSBuild.dll"; if (is_in_vsmac) { var env = new Dictionary { - { "MD_APPLE_SDK_ROOT", Path.GetDirectoryName (Path.GetDirectoryName (Configuration.xcode_root)) }, + { "DEVELOPER_DIR", Path.GetDirectoryName (Path.GetDirectoryName (Configuration.xcode_root)) }, { "MSBUILD_EXE_PATH", msbuild_exe_path }, }; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs index 75f52139b7af..3d29841fa700 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs @@ -22,7 +22,9 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i intermediateOutputPath = Cache.CreateTemporaryDirectory (); - var sdk = Sdks.GetAppleSdk (platform); + var task = CreateTask (); + + var sdk = Sdks.GetAppleSdk (platform, task.GetXcodeLocator (initialDiscovery: true)); var version = AppleSdkVersion.UseDefault.ToString (); var root = sdk.GetSdkPath (version, false); string sdkPlatform; @@ -47,7 +49,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i throw new NotImplementedException (platform.ToString ()); } - var task = CreateTask (); task.ImageAssets = imageAssets .Select (v => { var spl = v.Split ('|'); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs index 17f5f44f93ad..fbb8c7bb5c7c 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs @@ -20,7 +20,7 @@ CompileAppManifest CreateTask (string? tmpdir = null, ApplePlatform platform = A var task = CreateTask (); task.AppBundleName = "AppBundleName"; task.CompiledAppManifest = new TaskItem (Path.Combine (tmpdir, "TemporaryAppManifest.plist")); - task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString ()!; + task.DefaultSdkVersion = Sdks.GetAppleSdk (platform, task.GetXcodeLocator (initialDiscovery: true)).GetInstalledSdkVersions (false).First ().ToString ()!; task.MinSupportedOSPlatformVersion = "10.0"; task.SupportedOSPlatformVersion = "15.0"; task.SdkVersion = task.DefaultSdkVersion ?? string.Empty; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs index bcd3e301aa05..6de4730f6840 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CreateBindingResourceTaskTests.cs @@ -9,6 +9,7 @@ using NUnit.Framework; +using Xamarin.Tests; using Xamarin.Utils; namespace Xamarin.MacDev.Tasks { @@ -22,11 +23,12 @@ CreateBindingResourcePackage ExecuteTask (string compress, bool symlinks, out st task.BindingResourcePath = Path.Combine (tmpdir, "CreateBindingResourceTaskTest"); task.IntermediateOutputPath = Path.Combine (tmpdir, "IntermediateOutputPath"); task.NativeReferences = CreateNativeReferences (tmpdir, symlinks); + task.SdkDevPath = Configuration.xcode_root; var currentDir = Environment.CurrentDirectory; try { Environment.CurrentDirectory = tmpdir; - Assert.IsTrue (task.Execute (), "Execute"); + ExecuteTask (task); } finally { Environment.CurrentDirectory = currentDir; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS.cs index 9d094f066a94..ef2fc666b041 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_iOS.cs @@ -15,7 +15,7 @@ protected override void ConfigureTask () Configuration.IgnoreIfIgnoredPlatform (ApplePlatform.iOS); base.ConfigureTask (); - Task.DefaultSdkVersion = Sdks.IOS.GetClosestInstalledSdk (AppleSdkVersion.V6_1, true).ToString (); + Task.DefaultSdkVersion = Sdks.GetAppleSdk (Platform, Task.GetXcodeLocator (initialDiscovery: true)).GetClosestInstalledSdk (AppleSdkVersion.V6_1, true).ToString (); Task.TargetFrameworkMoniker = TargetFramework.DotNet_iOS_String; Task.TargetArchitectures = "ARM64"; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_tvOS.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_tvOS.cs index b77904722891..63a1564ffd33 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_tvOS.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GeneratePlistTaskTests/GeneratePlistTaskTests_tvOS.cs @@ -14,7 +14,7 @@ protected override void ConfigureTask () Configuration.IgnoreIfIgnoredPlatform (ApplePlatform.TVOS); base.ConfigureTask (); - Task.DefaultSdkVersion = Sdks.TVOS.GetClosestInstalledSdk (AppleSdkVersion.V9_0, true).ToString (); + Task.DefaultSdkVersion = Sdks.GetAppleSdk (Platform, Task.GetXcodeLocator (initialDiscovery: true)).GetClosestInstalledSdk (AppleSdkVersion.V9_0, true).ToString (); Task.TargetFrameworkMoniker = TargetFramework.DotNet_tvOS_String; } } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs index 8c301b35e3c8..304a4931674d 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs @@ -18,9 +18,11 @@ namespace Xamarin.MacDev.Tasks { public class IBToolTaskTests : TestBase { IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string intermediateOutputPath) { + var task = CreateTask (); + var interfaceDefinitions = new List (); - var sdk = Sdks.GetSdk (framework); - var version = AppleSdkVersion.GetDefault (sdk, false); + var sdk = Sdks.GetAppleSdk (framework, task.GetXcodeLocator (initialDiscovery: true)); + var version = AppleSdkVersion.UseDefault.ToString (); var root = sdk.GetSdkPath (version, false); string platform; @@ -39,7 +41,6 @@ IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string inte foreach (var item in Directory.EnumerateFiles (projectDir, "*.xib", SearchOption.AllDirectories)) interfaceDefinitions.Add (new TaskItem (item)); - var task = CreateTask (); task.InterfaceDefinitions = interfaceDefinitions.ToArray (); task.IntermediateOutputPath = intermediateOutputPath; task.MinimumOSVersion = PDictionary.FromFile (Path.Combine (projectDir, "Info.plist")).GetMinimumOSVersion (); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeAppBundleTaskTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeAppBundleTaskTest.cs index 16a79e70fb84..b5d2723c775d 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeAppBundleTaskTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/MergeAppBundleTaskTest.cs @@ -60,6 +60,7 @@ MergeAppBundles CreateTask (string outputBundle, params string [] inputBundles) var task = CreateTask (); task.InputAppBundles = inputItems.ToArray (); task.OutputAppBundle = outputBundle; + task.SdkDevPath = Configuration.xcode_root; return task; } @@ -98,7 +99,7 @@ public void TestLipoExecutable () var outputBundle = Path.Combine (Cache.CreateTemporaryDirectory (), "Merged.app"); var task = CreateTask (outputBundle, bundles); - Assert.IsTrue (task.Execute (), "Task execution"); + ExecuteTask (task); // The bundle should only contain a single file. Assert.AreEqual (1, Directory.GetFileSystemEntries (outputBundle).Length, "Files in bundle"); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs index 8f38b34b0225..3856dc0dc097 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TestHelpers/TestBase.cs @@ -53,6 +53,8 @@ public virtual void Setup () { var t = new T (); t.BuildEngine = Engine; + if (t is XamarinTask xt) + xt.SdkDevPath = Configuration.xcode_root; return t; } diff --git a/tests/package-mac-tests.sh b/tests/package-mac-tests.sh index 423c822f4264..476ed2bdca60 100755 --- a/tests/package-mac-tests.sh +++ b/tests/package-mac-tests.sh @@ -19,7 +19,7 @@ cat test.config INCLUDE_MAC=$(grep ^INCLUDE_MAC= test.config | sed 's/.*=//') INCLUDE_MACCATALYST=$(grep ^INCLUDE_MACCATALYST= test.config | sed 's/.*=//') XCODE_DEVELOPER_ROOT=$(grep ^XCODE_DEVELOPER_ROOT= test.config | sed 's/.*=//') -export MD_APPLE_SDK_ROOT="$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")" +export DEVELOPER_DIR="$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")" export RootTestsDirectory="$(pwd)" make diff --git a/tests/xharness/Jenkins/TestTasks/AppleTestTask.cs b/tests/xharness/Jenkins/TestTasks/AppleTestTask.cs index b8e47819e90f..386eab0fbc09 100644 --- a/tests/xharness/Jenkins/TestTasks/AppleTestTask.cs +++ b/tests/xharness/Jenkins/TestTasks/AppleTestTask.cs @@ -35,7 +35,7 @@ public override void SetEnvironmentVariables (Process process) var xcodeRoot = Jenkins.Harness.XcodeRoot; process.StartInfo.EnvironmentVariables ["RootTestsDirectory"] = HarnessConfiguration.RootDirectory; - process.StartInfo.EnvironmentVariables ["MD_APPLE_SDK_ROOT"] = xcodeRoot; + process.StartInfo.EnvironmentVariables ["DEVELOPER_DIR"] = xcodeRoot; foreach (var kvp in Environment) { if (kvp.Value is null) {