Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[msbuild] Simplify code
  • Loading branch information
rolfbjarne committed Nov 14, 2025
commit 491a8979a8dda2397edae2784b37d0c08703a9a4
4 changes: 0 additions & 4 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public class ACTool : XcodeCompilerToolTask, ICancelableTask {
HashSet<string> brandAssetsInAssets = new (); // tvOS
HashSet<string> imageStacksInAssets = new (); // tvOS

protected override string DefaultBinDir {
get { return DeveloperRootBinDir; }
}

protected override string ToolName {
get { return "actool"; }
}
Expand Down
45 changes: 1 addition & 44 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public class DetectSdkLocations : XamarinTask, ICancelableTask {
const string SdkVersionDefaultValue = "default";
#region Inputs

public string TargetArchitectures {
get; set;
} = "";

public string IsDotNetSimulatorBuild {
public string XcodeLocation {
get; set;
} = "";

Expand All @@ -32,27 +28,17 @@ public string SdkRoot {
get; set;
} = "";

[Output]
public string SdkBinPath {
get; set;
} = "";

[Output]
public new string SdkDevPath {
get; set;
} = "";

[Output]
public string SdkUsrPath {
get; set;
} = "";

[Output]
public bool SdkIsSimulator {
get; set;
}

[Output]
public string SdkPlatform {
get; set;
} = "";
Expand Down Expand Up @@ -130,14 +116,6 @@ protected void EnsureSdkPath ()
SdkRoot = currentSdk.GetSdkPath (SdkVersion, SdkIsSimulator);
if (string.IsNullOrEmpty (SdkRoot))
Log.LogError (MSBStrings.E0084 /* Could not locate the {0} '{1}' SDK at path '{2}' */, PlatformName, SdkVersion, SdkRoot);

SdkUsrPath = DirExists ("SDK usr directory", Path.Combine (currentSdk.DeveloperRoot, "usr")) ?? "";
if (string.IsNullOrEmpty (SdkUsrPath))
Log.LogError (MSBStrings.E0085 /* Could not locate the {0} '{1}' SDK usr path at '{2}' */, PlatformName, SdkVersion, SdkRoot);

SdkBinPath = DirExists ("SDK bin directory", Path.Combine (SdkUsrPath, "bin")) ?? "";
if (string.IsNullOrEmpty (SdkBinPath))
Log.LogError (MSBStrings.E0032 /* Could not locate SDK bin directory */);
}

void EnsureXamarinSdkRoot ()
Expand Down Expand Up @@ -172,8 +150,6 @@ bool ExecuteImpl ()

AppleSdkSettings.Init ();

SetIsSimulator ();

if (EnsureAppleSdkRoot ())
EnsureSdkPath ();
EnsureXamarinSdkRoot ();
Expand All @@ -183,25 +159,6 @@ bool ExecuteImpl ()
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;
Expand Down
4 changes: 0 additions & 4 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public class IBTool : XcodeCompilerToolTask, ICancelableTask {

#endregion

protected override string DefaultBinDir {
get { return DeveloperRootBinDir; }
}

protected override string ToolName {
get { return "ibtool"; }
}
Expand Down
4 changes: 0 additions & 4 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public class TextureAtlas : XcodeToolTaskBase, ICancelableTask {

#endregion

protected override string DefaultBinDir {
get { return DeveloperRootBinDir; }
}

protected override string ToolName {
get { return "TextureAtlas"; }
}
Expand Down
18 changes: 0 additions & 18 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ public abstract class XcodeCompilerToolTask : XamarinTask, IHasProjectDir, IHasR
[Required]
public string ResourcePrefix { get; set; } = string.Empty;

public string SdkBinPath { get; set; } = string.Empty;

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

public string SdkUsrPath { get; set; } = string.Empty;

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

Expand Down Expand Up @@ -91,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 {
Expand Down Expand Up @@ -174,12 +162,6 @@ protected int Compile (ITaskItem [] items, string output, ITaskItem manifest)
var environment = new Dictionary<string, string?> ();
var args = new List<string> ();

if (!string.IsNullOrEmpty (SdkBinPath))
environment.Add ("PATH", SdkBinPath);

if (!string.IsNullOrEmpty (SdkUsrPath))
environment.Add ("XCODE_DEVELOPER_USR_PATH", SdkUsrPath);

// workaround for ibtool[d] bug / asserts if Intel version is loaded
string tool;
if (IsTranslated ()) {
Expand Down
39 changes: 4 additions & 35 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace Xamarin.MacDev.Tasks {
public abstract class XcodeToolTaskBase : XamarinTask, IHasProjectDir, IHasResourcePrefix {
string? toolExe;

#region Inputs

[Required]
Expand All @@ -27,16 +25,7 @@ public abstract class XcodeToolTaskBase : XamarinTask, IHasProjectDir, IHasResou
[Required]
public string ResourcePrefix { get; set; } = string.Empty;

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

[Required]
public string SdkUsrPath { 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;

Expand All @@ -49,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<ITaskItem> EnumerateInputs ();
Expand Down Expand Up @@ -94,22 +67,18 @@ 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)
{
var environment = new Dictionary<string, string?> ();
var args = new List<string> ();

environment.Add ("PATH", SdkBinPath);
environment.Add ("XCODE_DEVELOPER_USR_PATH", SdkUsrPath);

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;
}

Expand Down
15 changes: 3 additions & 12 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
SdkDevPath="$(_SdkDevPath)"
SdkBinPath="$(_SdkBinPath)"
SdkUsrPath="$(_SdkUsrPath)"
SdkRoot="$(_SdkRoot)"
SdkPlatform="$(_SdkPlatform)"
SdkVersion="$(_SdkVersion)"
Expand Down Expand Up @@ -1058,8 +1056,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
SdkDevPath="$(_SdkDevPath)"
SdkBinPath="$(_SdkBinPath)"
SdkUsrPath="$(_SdkUsrPath)"
SdkPlatform="$(_SdkPlatform)"
SdkVersion="$(_SdkVersion)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
Expand Down Expand Up @@ -1471,9 +1467,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
SdkDevPath="$(_SdkDevPath)"
SdkBinPath="$(_SdkBinPath)"
SdkUsrPath="$(_SdkUsrPath)">
SdkDevPath="$(_SdkDevPath)">
<Output TaskParameter="BundleResources" ItemName="_BundleResourceWithLogicalName" />

<!-- Local items to be persisted to items files -->
Expand Down Expand Up @@ -2089,20 +2083,17 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<DetectSdkLocations
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
IsDotNetSimulatorBuild="$(_IsDotNetSimulatorBuild)"
SdkIsSimulator="$(SdkIsSimulator)"
SdkVersion="$(_SdkVersion)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
TargetArchitectures="$(TargetArchitectures)"
XamarinSdkRoot="$(_XamarinSdkRootOnMac)"
XcodeLocation="$(XcodeLocation)"
>

<Output TaskParameter="SdkVersion" PropertyName="_SdkVersion" />
<Output TaskParameter="SdkRoot" PropertyName="_SdkRoot" />
<Output TaskParameter="SdkBinPath" PropertyName="_SdkBinPath" />
<Output TaskParameter="SdkDevPath" PropertyName="_SdkDevPath" />
<Output TaskParameter="SdkUsrPath" PropertyName="_SdkUsrPath" />
<Output TaskParameter="SdkPlatform" PropertyName="_SdkPlatform" />
<Output TaskParameter="SdkIsSimulator" PropertyName="_SdkIsSimulator" />
<Output TaskParameter="XamarinSdkRoot" PropertyName="_XamarinSdkRoot" />
<Output TaskParameter="XcodeVersion" PropertyName="_XcodeVersion" />
</DetectSdkLocations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
var sdk = Sdks.GetAppleSdk (platform);
var version = AppleSdkVersion.UseDefault.ToString ();
var root = sdk.GetSdkPath (version, false);
var usr = Path.Combine (sdk.DeveloperRoot, "usr");
var bin = Path.Combine (usr, "bin");
string sdkPlatform;
var uiDeviceFamily = "";

Expand Down Expand Up @@ -66,8 +64,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
task.SdkDevPath = Configuration.xcode_root;
task.SdkPlatform = sdkPlatform;
task.SdkVersion = version.ToString ();
task.SdkUsrPath = usr;
task.SdkBinPath = bin;
task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform).ToString ();
task.UIDeviceFamily = uiDeviceFamily;
return task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string inte
var sdk = Sdks.GetSdk (framework);
var version = AppleSdkVersion.GetDefault (sdk, false);
var root = sdk.GetSdkPath (version, false);
var usr = Path.Combine (sdk.DeveloperRoot, "usr");
var bin = Path.Combine (usr, "bin");
string platform;

switch (framework) {
Expand All @@ -50,8 +48,6 @@ IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string inte
task.SdkDevPath = Configuration.xcode_root;
task.SdkPlatform = platform;
task.SdkVersion = version.ToString ();
task.SdkUsrPath = usr;
task.SdkBinPath = bin;
task.SdkRoot = root;
task.TargetFrameworkMoniker = TargetFramework.DotNet_iOS_String;
return task;
Expand Down