-
Notifications
You must be signed in to change notification settings - Fork 565
[Xamarin.Android.Build.Tasks] locate $(JdkJvmPath) only when needed #2420
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/Xamarin.Android.Build.Tasks/Tasks/ResolveJdkJvmPath.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Xamarin.Android.Tools; | ||
|
|
||
| namespace Xamarin.Android.Tasks | ||
| { | ||
| /// <summary> | ||
| /// This MSBuild task's job is to find $(JdkJvmPath) used by $(AndroidGenerateJniMarshalMethods) | ||
| /// </summary> | ||
| public class ResolveJdkJvmPath : Task | ||
| { | ||
| public string JavaSdkPath { get; set; } | ||
|
|
||
| [Output] | ||
| public string JdkJvmPath { get; set; } | ||
|
|
||
| public override bool Execute () | ||
| { | ||
| try { | ||
| JdkJvmPath = GetJvmPath (); | ||
| } catch (Exception e) { | ||
| Log.LogCodedError ("XA5300", $"Unable to find {nameof (JdkJvmPath)}{Environment.NewLine}{e}"); | ||
| return false; | ||
| } | ||
|
|
||
| if (string.IsNullOrEmpty (JdkJvmPath)) { | ||
| Log.LogCodedError ("XA5300", $"{nameof (JdkJvmPath)} is blank"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!File.Exists (JdkJvmPath)) { | ||
| Log.LogCodedError ("XA5300", $"JdkJvmPath not found at {JdkJvmPath}"); | ||
| return false; | ||
| } | ||
|
|
||
| return !Log.HasLoggedErrors; | ||
| } | ||
|
|
||
| string GetJvmPath () | ||
| { | ||
| var key = new Tuple<string, string> (nameof (ResolveJdkJvmPath), JavaSdkPath); | ||
| var cached = BuildEngine4.GetRegisteredTaskObject (key, RegisteredTaskObjectLifetime.AppDomain) as string; | ||
| if (cached != null) { | ||
| Log.LogDebugMessage ($"Using cached value for {nameof (JdkJvmPath)}: {cached}"); | ||
|
|
||
| return cached; | ||
| } | ||
|
|
||
| JdkInfo info = null; | ||
| try { | ||
| info = new JdkInfo (JavaSdkPath); | ||
| } catch { | ||
| info = JdkInfo.GetKnownSystemJdkInfos (this.CreateTaskLogger ()).FirstOrDefault (); | ||
| } | ||
|
|
||
| if (info == null) | ||
| return null; | ||
|
|
||
| var path = info.JdkJvmPath; | ||
| if (string.IsNullOrEmpty (path)) | ||
| return null; | ||
|
|
||
| BuildEngine4.RegisterTaskObject (key, path, RegisteredTaskObjectLifetime.AppDomain, allowEarlyCollection: false); | ||
|
|
||
| return path; | ||
| } | ||
| } | ||
| } | ||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let ask @jonpryor about that, as we already had the separate task once #2153 (review) and he suggested to do it in
ResolveSdksinstead.Now the circumstances changed (the DTB performance is important), but I guess we can still keep it in
ResolveSdksand addResolveJvmPathbool parameter to specify, whether the task should also resolve theJvmPath? That parameter value would be:'$(AndroidGenerateJniMarshalMethods)' == 'True'I am OK with both alternatives, just don't remember what was the reasoning for not having it in separate task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original concern was around consistency of the JVM path which was used:
I believe that in the original incarnation of the
<JdkInfo/>task added in PR #2153,<JdkInfo/>didn't accept an "input" Java SDK Path property, but simply re- computed the JVM path based onXamarin.Android.Tools.JdkInfo, which might not find the same path<ResolveSdks/>would have come up with (in part because<ResolveSdks/>reads$(JavaSdkDirectory), which could be overridden to point to ~anywhere).Keeping both the
JavaSdkPathandJdkJvmPathlogic within<ResolveSdks/>thus helped ensur a degree of consistency.The approach here does afford consistency between the
<ResolveJdkJvmPath/>and<ResolveSdks/>tasks, because of theResolveJdkJvmPath.JavaSdkPathproperty, and the only way they could differ is if the path that<ResolveSdks/>computes is an "invalid" path as far asXamarin.Android.Tools.JdkInfois concerned, but that was already a possibility when it was within<ResolveSdks/>, becauseResolveSdks.JavaSdkPathwasn't updated ifnew JdkInfo(JavaSdkPath)ever threw.