Skip to content

Commit 511d580

Browse files
committed
Allow finding NDK location based on $PATH
Context: https://github.com/xamarin/androidtools/pull/119 Context: https://devdiv.visualstudio.com/DevDiv/DevDiv%20Team/_build?buildId=1908630 Context: https://github.com/xamarin/androidtools/pull/120 Context: https://devdiv.visualstudio.com/DevDiv/DevDiv%20Team/_build?buildId=1908776 How does `AndroidSdkInfo` determine the appropriate value to return from `AndroidSdkInfo.AndroidNdkPath`? Firstly, it checks `$HOME/.config/xbuild/monodroid-config.xml`. If that file doesn't exist, or it doesn't contain a `/monodroid/android-ndk/@path` attribute value, then `AndroidSdkInfo` checks `$PATH`, and attempts to find `ndk-stack`. If `ndk-stack` can be found in `$PATH`, the containing directory is used: $ mv $HOME/.config/xbuild/monodroid-config.xml{,.none} $ PATH=/path/to/my/ndk:$PATH csharp -r:Xamarin.Android.Tools.AndroidSdk.dll csharp> using System.Diagnostics; csharp> using Xamarin.Android.Tools; csharp> Action<TraceLevel, string> logger = (level, value) => Console.WriteLine ($"[{level}] {value}"); csharp> var info = new AndroidSdkInfo (logger); csharp> info.AndroidNdkPath; "/path/to/my/ndk" Unfortunately, commit 0cec16c broke this behavior; afterward, `info.AndroidNdkPath` would return `null`, bceause commit 0cec16c inadvertently broke `$PATH`-based probing for `ndk-stack`. Oops. :-( Specifically, it was the "cleanup" in 0cec16c, replacing `AndroidSdkBase.FindExecutableInPath()` with `ProcessUtils.FindExecutablesInPath()`. While these are similarly named, they had an important semantic difference: the former returned the *directory* containing an executable, while the latter returned the full path for the executable. Double oops. Review commit 0cec16c and review all `ProcessUtils.FindExecutablesInPath()` use to ensure that when a directory is desired, we actually get a directory, not the path to `ndk-stack` itself. This allows `$PATH`-based NDK lookup to work again.
1 parent b42c217 commit 511d580

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ protected override IEnumerable<string> GetAllAvailableAndroidSdks ()
9393
yield return preferedSdkPath;
9494

9595
// Look in PATH
96-
foreach (var path in ProcessUtils.FindExecutablesInPath (Adb)) {
96+
foreach (var adb in ProcessUtils.FindExecutablesInPath (Adb)) {
97+
var path = Path.GetDirectoryName (adb);
9798
// Strip off "platform-tools"
9899
var dir = Path.GetDirectoryName (path);
99100

@@ -119,9 +120,10 @@ protected override IEnumerable<string> GetAllAvailableAndroidNdks ()
119120
yield return preferedNdkPath;
120121

121122
// Look in PATH
122-
foreach (var path in ProcessUtils.FindExecutablesInPath (NdkStack)) {
123-
if (ValidateAndroidNdkLocation (path))
124-
yield return path;
123+
foreach (var ndkStack in ProcessUtils.FindExecutablesInPath (NdkStack)) {
124+
var ndkDir = Path.GetDirectoryName (ndkStack);
125+
if (ValidateAndroidNdkLocation (ndkDir))
126+
yield return ndkDir;
125127
}
126128
}
127129

0 commit comments

Comments
 (0)