Skip to content

Commit 0bb973a

Browse files
committed
[msbuild] Simplify code
1 parent 17caa83 commit 0bb973a

File tree

9 files changed

+8
-129
lines changed

9 files changed

+8
-129
lines changed

msbuild/Xamarin.MacDev.Tasks/Tasks/ACTool.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ public class ACTool : XcodeCompilerToolTask, ICancelableTask {
5858
HashSet<string> brandAssetsInAssets = new (); // tvOS
5959
HashSet<string> imageStacksInAssets = new (); // tvOS
6060

61-
protected override string DefaultBinDir {
62-
get { return DeveloperRootBinDir; }
63-
}
64-
6561
protected override string ToolName {
6662
get { return "actool"; }
6763
}

msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocation.cs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ public class DetectSdkLocations : XamarinTask, ICancelableTask {
1515
const string SdkVersionDefaultValue = "default";
1616
#region Inputs
1717

18-
public string TargetArchitectures {
19-
get; set;
20-
} = "";
21-
22-
public string IsDotNetSimulatorBuild {
18+
public string XcodeLocation {
2319
get; set;
2420
} = "";
2521

@@ -32,27 +28,17 @@ public string SdkRoot {
3228
get; set;
3329
} = "";
3430

35-
[Output]
36-
public string SdkBinPath {
37-
get; set;
38-
} = "";
39-
4031
[Output]
4132
public new string SdkDevPath {
4233
get; set;
4334
} = "";
4435

45-
[Output]
46-
public string SdkUsrPath {
47-
get; set;
48-
} = "";
4936

5037
[Output]
5138
public bool SdkIsSimulator {
5239
get; set;
5340
}
5441

55-
[Output]
5642
public string SdkPlatform {
5743
get; set;
5844
} = "";
@@ -130,14 +116,6 @@ protected void EnsureSdkPath ()
130116
SdkRoot = currentSdk.GetSdkPath (SdkVersion, SdkIsSimulator);
131117
if (string.IsNullOrEmpty (SdkRoot))
132118
Log.LogError (MSBStrings.E0084 /* Could not locate the {0} '{1}' SDK at path '{2}' */, PlatformName, SdkVersion, SdkRoot);
133-
134-
SdkUsrPath = DirExists ("SDK usr directory", Path.Combine (currentSdk.DeveloperRoot, "usr")) ?? "";
135-
if (string.IsNullOrEmpty (SdkUsrPath))
136-
Log.LogError (MSBStrings.E0085 /* Could not locate the {0} '{1}' SDK usr path at '{2}' */, PlatformName, SdkVersion, SdkRoot);
137-
138-
SdkBinPath = DirExists ("SDK bin directory", Path.Combine (SdkUsrPath, "bin")) ?? "";
139-
if (string.IsNullOrEmpty (SdkBinPath))
140-
Log.LogError (MSBStrings.E0032 /* Could not locate SDK bin directory */);
141119
}
142120

143121
void EnsureXamarinSdkRoot ()
@@ -172,8 +150,6 @@ bool ExecuteImpl ()
172150

173151
AppleSdkSettings.Init ();
174152

175-
SetIsSimulator ();
176-
177153
if (EnsureAppleSdkRoot ())
178154
EnsureSdkPath ();
179155
EnsureXamarinSdkRoot ();
@@ -183,25 +159,6 @@ bool ExecuteImpl ()
183159
return !Log.HasLoggedErrors;
184160
}
185161

186-
void SetIsSimulator ()
187-
{
188-
switch (Platform) {
189-
case ApplePlatform.MacCatalyst:
190-
case ApplePlatform.MacOSX:
191-
return;
192-
}
193-
194-
TargetArchitecture architectures;
195-
if (string.IsNullOrEmpty (TargetArchitectures) || !Enum.TryParse (TargetArchitectures, out architectures))
196-
architectures = TargetArchitecture.Default;
197-
198-
if (!string.IsNullOrEmpty (IsDotNetSimulatorBuild)) {
199-
SdkIsSimulator = string.Equals (IsDotNetSimulatorBuild, "true", StringComparison.OrdinalIgnoreCase);
200-
} else {
201-
SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;
202-
}
203-
}
204-
205162
protected bool EnsureAppleSdkRoot ()
206163
{
207164
var currentSdk = CurrentSdk;

msbuild/Xamarin.MacDev.Tasks/Tasks/IBTool.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public class IBTool : XcodeCompilerToolTask, ICancelableTask {
3030

3131
#endregion
3232

33-
protected override string DefaultBinDir {
34-
get { return DeveloperRootBinDir; }
35-
}
36-
3733
protected override string ToolName {
3834
get { return "ibtool"; }
3935
}

msbuild/Xamarin.MacDev.Tasks/Tasks/TextureAtlas.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ public class TextureAtlas : XcodeToolTaskBase, ICancelableTask {
2020

2121
#endregion
2222

23-
protected override string DefaultBinDir {
24-
get { return DeveloperRootBinDir; }
25-
}
26-
2723
protected override string ToolName {
2824
get { return "TextureAtlas"; }
2925
}

msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeCompilerToolTask.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ public abstract class XcodeCompilerToolTask : XamarinTask, IHasProjectDir, IHasR
3838
[Required]
3939
public string ResourcePrefix { get; set; } = string.Empty;
4040

41-
public string SdkBinPath { get; set; } = string.Empty;
42-
4341
[Required]
4442
public string SdkPlatform { get; set; } = string.Empty;
4543

46-
public string SdkUsrPath { get; set; } = string.Empty;
47-
4844
[Required]
4945
public string SdkVersion { get; set; } = string.Empty;
5046

@@ -91,14 +87,6 @@ public IPhoneDeviceType ParsedUIDeviceFamily {
9187
}
9288
}
9389

94-
protected abstract string DefaultBinDir {
95-
get;
96-
}
97-
98-
protected string DeveloperRootBinDir {
99-
get { return Path.Combine (SdkDevPath, "usr", "bin"); }
100-
}
101-
10290
protected abstract string ToolName { get; }
10391

10492
protected virtual bool UseCompilationDirectory {
@@ -174,12 +162,6 @@ protected int Compile (ITaskItem [] items, string output, ITaskItem manifest)
174162
var environment = new Dictionary<string, string?> ();
175163
var args = new List<string> ();
176164

177-
if (!string.IsNullOrEmpty (SdkBinPath))
178-
environment.Add ("PATH", SdkBinPath);
179-
180-
if (!string.IsNullOrEmpty (SdkUsrPath))
181-
environment.Add ("XCODE_DEVELOPER_USR_PATH", SdkUsrPath);
182-
183165
// workaround for ibtool[d] bug / asserts if Intel version is loaded
184166
string tool;
185167
if (IsTranslated ()) {

msbuild/Xamarin.MacDev.Tasks/Tasks/XcodeTool.cs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Xamarin.MacDev.Tasks {
1616
public abstract class XcodeToolTaskBase : XamarinTask, IHasProjectDir, IHasResourcePrefix {
17-
string? toolExe;
18-
1917
#region Inputs
2018

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

30-
[Required]
31-
public string SdkBinPath { get; set; } = string.Empty;
32-
33-
[Required]
34-
public string SdkUsrPath { get; set; } = string.Empty;
35-
36-
public string ToolExe {
37-
get { return toolExe ?? ToolName; }
38-
set { toolExe = value; }
39-
}
28+
public string ToolExe { get; set; } = string.Empty;
4029

4130
public string ToolPath { get; set; } = string.Empty;
4231

@@ -49,22 +38,6 @@ public string ToolExe {
4938

5039
#endregion
5140

52-
protected abstract string DefaultBinDir {
53-
get;
54-
}
55-
56-
protected string DeveloperRootBinDir {
57-
get { return Path.Combine (SdkDevPath, "usr", "bin"); }
58-
}
59-
60-
protected string DevicePlatformBinDir {
61-
get { return Path.Combine (SdkDevPath, "Platforms", "iPhoneOS.platform", "Developer", "usr", "bin"); }
62-
}
63-
64-
protected string SimulatorPlatformBinDir {
65-
get { return Path.Combine (SdkDevPath, "Platforms", "iPhoneSimulator.platform", "Developer", "usr", "bin"); }
66-
}
67-
6841
protected abstract string ToolName { get; }
6942

7043
protected abstract IEnumerable<ITaskItem> EnumerateInputs ();
@@ -94,22 +67,18 @@ string GetFullPathToTool ()
9467
if (!string.IsNullOrEmpty (ToolPath))
9568
return Path.Combine (ToolPath, ToolExe);
9669

97-
var path = Path.Combine (DefaultBinDir, ToolExe);
98-
99-
return File.Exists (path) ? path : ToolExe;
70+
return ToolExe ?? "";
10071
}
10172

10273
int ExecuteTool (ITaskItem input, ITaskItem output)
10374
{
10475
var environment = new Dictionary<string, string?> ();
10576
var args = new List<string> ();
10677

107-
environment.Add ("PATH", SdkBinPath);
108-
environment.Add ("XCODE_DEVELOPER_USR_PATH", SdkUsrPath);
109-
11078
AppendCommandLineArguments (environment, args, input, output);
11179

112-
var rv = ExecuteAsync (GetFullPathToTool (), args, environment: environment).Result;
80+
var executable = GetExecutable (args, ToolName, GetFullPathToTool ());
81+
var rv = ExecuteAsync (executable, args, environment: environment).Result;
11382
return rv.ExitCode;
11483
}
11584

msbuild/Xamarin.Shared/Xamarin.Shared.targets

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
922922
ProjectDir="$(MSBuildProjectDirectory)"
923923
ResourcePrefix="$(_ResourcePrefix)"
924924
SdkDevPath="$(_SdkDevPath)"
925-
SdkBinPath="$(_SdkBinPath)"
926-
SdkUsrPath="$(_SdkUsrPath)"
927925
SdkRoot="$(_SdkRoot)"
928926
SdkPlatform="$(_SdkPlatform)"
929927
SdkVersion="$(_SdkVersion)"
@@ -1058,8 +1056,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
10581056
ProjectDir="$(MSBuildProjectDirectory)"
10591057
ResourcePrefix="$(_ResourcePrefix)"
10601058
SdkDevPath="$(_SdkDevPath)"
1061-
SdkBinPath="$(_SdkBinPath)"
1062-
SdkUsrPath="$(_SdkUsrPath)"
10631059
SdkPlatform="$(_SdkPlatform)"
10641060
SdkVersion="$(_SdkVersion)"
10651061
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
@@ -1471,9 +1467,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
14711467
IntermediateOutputPath="$(DeviceSpecificIntermediateOutputPath)"
14721468
ProjectDir="$(MSBuildProjectDirectory)"
14731469
ResourcePrefix="$(_ResourcePrefix)"
1474-
SdkDevPath="$(_SdkDevPath)"
1475-
SdkBinPath="$(_SdkBinPath)"
1476-
SdkUsrPath="$(_SdkUsrPath)">
1470+
SdkDevPath="$(_SdkDevPath)">
14771471
<Output TaskParameter="BundleResources" ItemName="_BundleResourceWithLogicalName" />
14781472

14791473
<!-- Local items to be persisted to items files -->
@@ -2089,20 +2083,17 @@ Copyright (C) 2018 Microsoft. All rights reserved.
20892083
<DetectSdkLocations
20902084
SessionId="$(BuildSessionId)"
20912085
Condition="'$(IsMacEnabled)' == 'true'"
2092-
IsDotNetSimulatorBuild="$(_IsDotNetSimulatorBuild)"
2086+
SdkIsSimulator="$(SdkIsSimulator)"
20932087
SdkVersion="$(_SdkVersion)"
20942088
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
2095-
TargetArchitectures="$(TargetArchitectures)"
20962089
XamarinSdkRoot="$(_XamarinSdkRootOnMac)"
2090+
XcodeLocation="$(XcodeLocation)"
20972091
>
20982092

20992093
<Output TaskParameter="SdkVersion" PropertyName="_SdkVersion" />
21002094
<Output TaskParameter="SdkRoot" PropertyName="_SdkRoot" />
2101-
<Output TaskParameter="SdkBinPath" PropertyName="_SdkBinPath" />
21022095
<Output TaskParameter="SdkDevPath" PropertyName="_SdkDevPath" />
2103-
<Output TaskParameter="SdkUsrPath" PropertyName="_SdkUsrPath" />
21042096
<Output TaskParameter="SdkPlatform" PropertyName="_SdkPlatform" />
2105-
<Output TaskParameter="SdkIsSimulator" PropertyName="_SdkIsSimulator" />
21062097
<Output TaskParameter="XamarinSdkRoot" PropertyName="_XamarinSdkRoot" />
21072098
<Output TaskParameter="XcodeVersion" PropertyName="_XcodeVersion" />
21082099
</DetectSdkLocations>

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ACToolTaskTest.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
2525
var sdk = Sdks.GetAppleSdk (platform);
2626
var version = AppleSdkVersion.UseDefault.ToString ();
2727
var root = sdk.GetSdkPath (version, false);
28-
var usr = Path.Combine (sdk.DeveloperRoot, "usr");
29-
var bin = Path.Combine (usr, "bin");
3028
string sdkPlatform;
3129
var uiDeviceFamily = "";
3230

@@ -66,8 +64,6 @@ ACTool CreateACToolTask (ApplePlatform platform, string projectDir, out string i
6664
task.SdkDevPath = Configuration.xcode_root;
6765
task.SdkPlatform = sdkPlatform;
6866
task.SdkVersion = version.ToString ();
69-
task.SdkUsrPath = usr;
70-
task.SdkBinPath = bin;
7167
task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform).ToString ();
7268
task.UIDeviceFamily = uiDeviceFamily;
7369
return task;

tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/IBToolTaskTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string inte
2222
var sdk = Sdks.GetSdk (framework);
2323
var version = AppleSdkVersion.GetDefault (sdk, false);
2424
var root = sdk.GetSdkPath (version, false);
25-
var usr = Path.Combine (sdk.DeveloperRoot, "usr");
26-
var bin = Path.Combine (usr, "bin");
2725
string platform;
2826

2927
switch (framework) {
@@ -50,8 +48,6 @@ IBTool CreateIBToolTask (ApplePlatform framework, string projectDir, string inte
5048
task.SdkDevPath = Configuration.xcode_root;
5149
task.SdkPlatform = platform;
5250
task.SdkVersion = version.ToString ();
53-
task.SdkUsrPath = usr;
54-
task.SdkBinPath = bin;
5551
task.SdkRoot = root;
5652
task.TargetFrameworkMoniker = TargetFramework.DotNet_iOS_String;
5753
return task;

0 commit comments

Comments
 (0)