Skip to content

Commit e554928

Browse files
committed
[WIP] Modify code to comply with test expectations
1 parent 5e1086e commit e554928

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ int GetNdkApiLevel (NdkTools ndk, string androidApiLevel, AndroidTargetArch arch
221221

222222
public async override System.Threading.Tasks.Task RunTaskAsync ()
223223
{
224-
NdkTools ndk = NdkTools.Create (AndroidNdkDirectory, Log);
224+
NdkTools? ndk = NdkTools.Create (AndroidNdkDirectory, Log);
225+
if (ndk == null) {
226+
return; // NdkTools.Create will log appropriate error
227+
}
228+
225229
bool hasValidAotMode = GetAndroidAotMode (AndroidAotMode, out AotMode);
226230
if (!hasValidAotMode) {
227231
LogCodedError ("XA3002", Properties.Resources.XA3002, AndroidAotMode);

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,11 @@ private void AddNativeLibraries (ArchiveFileList files, string [] supportedAbis)
635635
return;
636636
}
637637

638-
NdkTools ndk = NdkTools.Create (AndroidNdkDirectory, Log);
638+
NdkTools? ndk = NdkTools.Create (AndroidNdkDirectory, Log);
639+
if (ndk == null) {
640+
return; // NdkTools.Create will log appropriate error
641+
}
642+
639643
string clangDir = ndk.GetClangDeviceLibraryPath ();
640644
if (String.IsNullOrEmpty (clangDir)) {
641645
LogSanitizerError ($"Unable to find the clang compiler directory. Is NDK installed?");

src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public MakeBundleNativeCodeExternal ()
5757

5858
public override bool RunTask ()
5959
{
60-
NdkTools ndk = NdkTools.Create (AndroidNdkDirectory, Log);
60+
NdkTools? ndk = NdkTools.Create (AndroidNdkDirectory, Log);
61+
if (ndk == null) {
62+
return false; // NdkTools.Create will log appropriate error
63+
}
6164

6265
try {
6366
return DoExecute (ndk);

src/Xamarin.Android.Build.Tasks/Utilities/NdkTools/NdkTools.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ public static bool IsValidNdkRoot (string androidNdkPath)
7272
return true;
7373
}
7474

75-
public static NdkTools Create (string androidNdkPath, TaskLoggingHelper? log = null)
75+
public static NdkTools? Create (string androidNdkPath, TaskLoggingHelper? log = null)
7676
{
7777
if (String.IsNullOrEmpty (androidNdkPath)) {
78-
throw new ArgumentException ("must be a non-empty string", nameof (androidNdkPath));
78+
log?.LogCodedError ("XA5104", Properties.Resources.XA5104);
79+
return null;
7980
}
8081

81-
NdkVersion version = ReadVersion (androidNdkPath);
82+
NdkVersion? version = ReadVersion (androidNdkPath);
83+
if (version == null) {
84+
return null;
85+
}
8286

8387
if (version.Main.Major < 14) {
8488
throw new InvalidOperationException ($"Unsupported NDK version {version}");
@@ -356,10 +360,11 @@ bool HasPrebuiltDir (string name)
356360
}
357361
}
358362

359-
static NdkVersion ReadVersion (string androidNdkPath)
363+
static NdkVersion? ReadVersion (string androidNdkPath, TaskLoggingHelper? log = null)
360364
{
361365
if (!Directory.Exists (androidNdkPath)) {
362-
throw new InvalidOperationException ($"NDK directory '{androidNdkPath}' does not exist.");
366+
log?.LogCodedError ("XA5104", Properties.Resources.XA5104);
367+
return null;
363368
}
364369

365370
string sourcePropertiesPath = Path.Combine (androidNdkPath, "source.properties");

0 commit comments

Comments
 (0)