-
Notifications
You must be signed in to change notification settings - Fork 31
Allow an optional locator to be provided to JdkInfo #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context: dotnet/android#2004 (comment) There are a two (related) "usability" issues with `JdkInfo.GetKnownSystemJdkInfos()`: 1. It returns duplicate paths, and 2. There's no way of knowing where a path "came from" For example: $ csharp -r:bin/Debug/Xamarin.Android.Tools.AndroidSdk.dll csharp> using Xamarin.Android.Tools; csharp> JdkInfo.GetKnownSystemJdkInfos(); { JdkInfo(Version=1.8.0.77, Vendor="Oracle Corporation", HomePath="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home"), Not a valid JDK directory: `/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home` System.ArgumentException: Could not find required file `jvm` within `/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home`; is this a valid JDK? Parameter name: homePath at Xamarin.Android.Tools.JdkInfo.ValidateFile (System.String name, System.String path) [0x00025] in <087d9a26808b4d2d9c5d2844064ae952>:0 at Xamarin.Android.Tools.JdkInfo..ctor (System.String homePath, System.String locator) [0x00120] in <087d9a26808b4d2d9c5d2844064ae952>:0 at Xamarin.Android.Tools.JdkInfo.TryGetJdkInfo (System.String path, System.Action`2[T1,T2] logger, System.String locator) [0x00004] in <087d9a26808b4d2d9c5d2844064ae952>:0 JdkInfo(Version=1.8.0.77, Vendor="Oracle Corporation", HomePath="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home"), } Notice that on my machine `jdk1.8.0_77.jdk` is listed *twice*. Why is it listed twice? It's listed twice because it comes from two different "locators": `JdkInfo.GetPathEnvironmentJdks()`, which reads `$PATH`, and `JdkInfo.GetLibexecJdks()`, which parses the output of `/usr/libexec/java_home -X`. If `$JAVA_HOME` were set to the same location, it would be listed three times. As-is, there's no way of knowing where a path is "coming from"; the "locator" -- what found the path -- isn't known. We could `.Distinct()` the output so that we don't have duplicates, but I *like* the idea of duplicates, as it shows that we're using multiple locators. Then we hit [xamarin-android PR #2004][0], in which the `xamarin-android-tools` bump within `xamarin-android` would fail, *depending on which machine ran the unit tests*: Xamarin.Android.Common.targets(691,2): warning : Not a valid JDK directory: `/var/folders/19/hjm21bn17913_0ck7nh3thdr0000gn/T/tmp731daee6.tmp/microsoft_dist_openjdk_1.8.999` Where did that path come from?! Update `JdkInfo.TryGetJdkInfo()` so that it takes an additional "locator" parameter, which is publicly visible as the new `JdkInfo.Locator` property, so that when we encounter an invalid JDK directory, we know where that path came from: Xamarin.Android.Common.targets(691,2): warning : Not a valid JDK directory: `/var/folders/19/hjm21bn17913_0ck7nh3thdr0000gn/T/tmp731daee6.tmp/microsoft_dist_openjdk_1.8.999`; via locator: monodroid-config.xml *Now* we can see that the invalid (bizarro!) JDK path is coming from `monodroid-config.xml`, allowing us to deduce that `monodroid-config.xml` is "bad" (because the unit tests in a4aad18 incorrectly restored the original `monodroid-config.xml` file, meaning the state of the machine after running that unit test is forever suspect!). The additional inclusion of Locator information makes it much easier to reason about things, and the inclusion of duplicates makes sense: $ csharp -r:bin/Debug/Xamarin.Android.Tools.AndroidSdk.dll csharp> using Xamarin.Android.Tools; csharp> JdkInfo.GetKnownSystemJdkInfos(); { JdkInfo(Version=1.8.0.77, Vendor="Oracle Corporation", HomePath="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home", Locator="$PATH"), Not a valid JDK directory: `/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home` System.ArgumentException: Could not find required file `jvm` within `/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home`; is this a valid JDK? Parameter name: homePath at Xamarin.Android.Tools.JdkInfo.ValidateFile (System.String name, System.String path) [0x00025] in <087d9a26808b4d2d9c5d2844064ae952>:0 at Xamarin.Android.Tools.JdkInfo..ctor (System.String homePath, System.String locator) [0x00120] in <087d9a26808b4d2d9c5d2844064ae952>:0 at Xamarin.Android.Tools.JdkInfo.TryGetJdkInfo (System.String path, System.Action`2[T1,T2] logger, System.String locator) [0x00004] in <087d9a26808b4d2d9c5d2844064ae952>:0 JdkInfo(Version=1.8.0.77, Vendor="Oracle Corporation", HomePath="/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home", Locator="`/usr/libexec/java_home -X`") } [0]: dotnet/android#2004
jonathanpeppers
approved these changes
Aug 3, 2018
bratsche
approved these changes
Aug 3, 2018
jonathanpeppers
added a commit
to jonathanpeppers/xamarin-android
that referenced
this pull request
Aug 16, 2018
Context; dotnet/android-tools@917d3b3...9e78d6e Fixes for OpenJDK: dotnet/android-tools#43 dotnet/android-tools#45 Better logging: dotnet/android-tools#46 Fix for missing JDKs on MacOS: dotnet/android-tools#48 Tests now pass on Windows: dotnet/android-tools#47
grendello
pushed a commit
to dotnet/android
that referenced
this pull request
Aug 17, 2018
Context; dotnet/android-tools@917d3b3...9e78d6e Fixes for OpenJDK: dotnet/android-tools#43 dotnet/android-tools#45 Better logging: dotnet/android-tools#46 Fix for missing JDKs on MacOS: dotnet/android-tools#48 Tests now pass on Windows: dotnet/android-tools#47
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: dotnet/android#2004 (comment)
There are a two (related) "usability" issues with
JdkInfo.GetKnownSystemJdkInfos():For example:
Notice that on my machine
jdk1.8.0_77.jdkis listed twice.Why is it listed twice? It's listed twice because it comes from two
different "locators":
JdkInfo.GetPathEnvironmentJdks(), which reads$PATH, andJdkInfo.GetLibexecJdks(), which parses the output of/usr/libexec/java_home -X. If$JAVA_HOMEwere set to the samelocation, it would be listed three times.
As-is, there's no way of knowing where a path is "coming from"; the
"locator" -- what found the path -- isn't known.
We could
.Distinct()the output so that we don't have duplicates,but I like the idea of duplicates, as it shows that we're using
multiple locators.
Then we hit xamarin-android PR #2004, in which the
xamarin-android-toolsbump withinxamarin-androidwould fail,depending on which machine ran the unit tests:
Where did that path come from?!
Update
JdkInfo.TryGetJdkInfo()so that it takes an additional"locator" parameter, which is publicly visible as the new
JdkInfo.Locatorproperty, so that when we encounter an invalid JDKdirectory, we know where that path came from:
Now we can see that the invalid (bizarro!) JDK path is coming from
monodroid-config.xml, allowing us to deduce thatmonodroid-config.xmlis "bad" (because the unit tests in a4aad18incorrectly restored the original
monodroid-config.xmlfile, meaningthe state of the machine after running that unit test is forever
suspect!).
The additional inclusion of Locator information makes it much easier
to reason about things, and the inclusion of duplicates makes sense: