Skip to content

Commit 014c1cb

Browse files
authored
[Xamarin.Android.Build.Tasks] class-parse.exe as separate process (#6551)
Context: dotnet/java-interop@73096d9 Context: dotnet/java-interop@f658ab2 There are potentially some conflicts with using `Xamarin.Android.Tools.Bytecode.dll` directly in the MSBuild process, as it now imports `protobuf-net` (dotnet/java-interop@73096d9f), which is a commonly used library. To ensure it isn't running in-process, switch our targets to shell out to `class-parse{.exe,.dll}`. Additionally, add `class-parse.dll`, etc. to the .NET 6 install pack. We are already shipping `class-parse.exe`, etc. in the Classic installer even though it wasn't used, so no additional installer changes are needed there. As expected, moving this out-of-process is slightly slower, but still acceptable. * Before: 292ms * After: 425ms Finally, adds `java-resolution-report.log` to `@(FileWrites)` which was added in dotnet/java-interop@f658ab26.
1 parent 60e983c commit 014c1cb

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ core workload SDK packs imported by WorkloadManifest.targets.
6969
<_PackageFiles Include="$(XAInstallPrefix)xbuild\Xamarin\Android\Microsoft.Android.Sdk.ILLink.pdb" PackagePath="tools" />
7070
<_PackageFiles Include="$(XAInstallPrefix)xbuild\Xamarin\Android\%(_LocalizationLanguages.Identity)\Microsoft.Android.Sdk.ILLink.resources.dll" PackagePath="tools\%(_LocalizationLanguages.Identity)" />
7171
<_PackageFiles Include="$(ToolsSourceDir)**" PackagePath="tools" />
72+
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)class-parse.dll" PackagePath="tools" />
73+
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)class-parse.pdb" PackagePath="tools" />
74+
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)class-parse.runtimeconfig.json" PackagePath="tools" />
7275
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)generator.dll" PackagePath="tools" />
7376
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)generator.pdb" PackagePath="tools" />
7477
<_PackageFiles Include="$(NetCoreAppToolsSourceDir)generator.runtimeconfig.json" PackagePath="tools" />

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Bindings.ClassParse.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This file is only used by binding projects.
3131
OutputFile="$(ApiOutputFile).class-parse"
3232
SourceJars="@(EmbeddedJar);@(InputJar)"
3333
DocumentationPaths="@(_AndroidDocumentationPath)"
34+
ToolPath="$(MonoAndroidToolsDirectory)"
3435
/>
3536
<BindingsGenerator
3637
OnlyRunXmlAdjuster="true"
@@ -45,6 +46,13 @@ This file is only used by binding projects.
4546
Nullable="$(Nullable)"
4647
UseJavaLegacyResolver="$(_AndroidUseJavaLegacyResolver)"
4748
/>
49+
50+
<ItemGroup>
51+
<!-- Created by <ClassParse /> -->
52+
<FileWrites Include="$(IntermediateOutputPath)class-parse.rsp" />
53+
<!-- Created by <BindingGenerator /> -->
54+
<FileWrites Condition="Exists ('$(IntermediateOutputPath)java-resolution-report.log')" Include="$(IntermediateOutputPath)java-resolution-report.log" />
55+
</ItemGroup>
4856
</Target>
4957

5058
<Target Name="_GetJavaSourceJarJavadocFiles"
Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// Copyright (C) 2012 Xamarin, Inc. All rights reserved.
22

3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
63
using System.IO;
7-
using System.Reflection;
8-
using Microsoft.Build.Framework;
9-
using Microsoft.Build.Utilities;
10-
using System.Text;
11-
using Bytecode = Xamarin.Android.Tools.Bytecode;
12-
using System.Diagnostics;
134
using Microsoft.Android.Build.Tasks;
5+
using Microsoft.Build.Framework;
146

157
namespace Xamarin.Android.Tasks
168
{
17-
public class ClassParse : AndroidTask
9+
public class ClassParse : AndroidDotnetToolTask
1810
{
1911
public override string TaskPrefix => "CLP";
2012

13+
protected override string BaseToolName => "class-parse";
14+
2115
[Required]
2216
public string OutputFile { get; set; }
2317

@@ -26,43 +20,33 @@ public class ClassParse : AndroidTask
2620

2721
public ITaskItem [] DocumentationPaths { get; set; }
2822

29-
public override bool RunTask ()
23+
protected override string GenerateCommandLineCommands ()
3024
{
31-
using (var output = new StreamWriter (OutputFile, append: false,
32-
encoding: Files.UTF8withoutBOM)) {
33-
Bytecode.Log.OnLog = LogEventHandler;
34-
var classPath = new Bytecode.ClassPath () {
35-
ApiSource = "class-parse",
36-
DocumentationPaths = (DocumentationPaths ?? Enumerable.Empty<ITaskItem> ()).Select(x => x.ItemSpec)
37-
};
38-
foreach (var jar in SourceJars) {
39-
if (Bytecode.ClassPath.IsJarFile (jar.ItemSpec)) {
40-
classPath.Load (jar.ItemSpec);
41-
}
42-
}
43-
classPath.SaveXmlDescription (output);
25+
var cmd = GetCommandLineBuilder ();
26+
27+
var responseFile = Path.Combine (Path.GetDirectoryName (OutputFile), "class-parse.rsp");
28+
Log.LogDebugMessage ("[class-parse] response file: {0}", responseFile);
29+
30+
using (var sw = new StreamWriter (responseFile, append: false, encoding: Files.UTF8withoutBOM)) {
31+
WriteLine (sw, $"--o=\"{OutputFile}\"");
32+
33+
if (DocumentationPaths != null)
34+
foreach (var doc in DocumentationPaths)
35+
WriteLine (sw, $"--docspath=\"{doc}\"");
36+
37+
foreach (var doc in SourceJars)
38+
WriteLine (sw, $"\"{doc}\"");
4439
}
45-
return true;
40+
41+
cmd.AppendSwitch ($"@{responseFile}");
42+
43+
return cmd.ToString ();
4644
}
4745

48-
void LogEventHandler (TraceLevel type, int verbosity, string message, params object[] args)
46+
void WriteLine (StreamWriter sw, string line)
4947
{
50-
switch (type) {
51-
case TraceLevel.Error:
52-
Log.LogError (message, args);
53-
break;
54-
case TraceLevel.Warning:
55-
Log.LogWarning (message, args);
56-
break;
57-
case TraceLevel.Info:
58-
Log.LogMessage ((MessageImportance)verbosity, message, args);
59-
break;
60-
default:
61-
Log.LogDebugMessage (message, args);
62-
break;
63-
64-
}
48+
sw.WriteLine (line);
49+
Log.LogDebugMessage (line);
6550
}
6651
}
6752
}
68-

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@
415415
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj" />
416416
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil.csproj" />
417417
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop.Tools.JavaCallableWrappers\Java.Interop.Tools.JavaCallableWrappers.csproj" />
418-
<ProjectReference Include="..\..\external\Java.Interop\src\Xamarin.Android.Tools.Bytecode\Xamarin.Android.Tools.Bytecode.csproj" />
419418
<!--
420419
Mono.Android.csproj needs to be built first because this project
421420
references files *generated* and contained within the Mono.Android project.

0 commit comments

Comments
 (0)