Skip to content

Commit 3bfffd5

Browse files
committed
Fix 'conjure-xamarin-android-cecil'
1 parent 14cf2c6 commit 3bfffd5

File tree

4 files changed

+99
-10
lines changed

4 files changed

+99
-10
lines changed

Configuration.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
<AndroidSupportedTargetAotAbisSplit>$(AndroidSupportedTargetAotAbis.Split(':'))</AndroidSupportedTargetAotAbisSplit>
232232
</PropertyGroup>
233233
<PropertyGroup>
234-
<RemapAssemblyRefToolExecutable>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\remap-assembly-ref\remap-assembly-ref.exe</RemapAssemblyRefToolExecutable>
234+
<RemapAssemblyRefToolExecutable>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\remap-assembly-ref\remap-assembly-ref.dll</RemapAssemblyRefToolExecutable>
235235
<RemapAssemblyRefTool>$(ManagedRuntime) $(ManagedRuntimeArgs) &quot;$(RemapAssemblyRefToolExecutable)&quot;</RemapAssemblyRefTool>
236236
</PropertyGroup>
237237

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Net;
56
using System.Net.Http;
67
using System.Reflection;
@@ -796,6 +797,25 @@ public static bool RunCommand (string command, string? workingDirectory, bool ec
796797
return runner.Run ();
797798
}
798799

800+
public static bool RunManagedCommand (string command, string workingDirectory, bool ignoreEmptyArguments, params string [] arguments)
801+
{
802+
return RunManagedCommand (command, workingDirectory, echoStderr: true, ignoreEmptyArguments: ignoreEmptyArguments, arguments: arguments);
803+
}
804+
805+
// This is a managed assembly that needs to be run as 'dotnet foo.dll'
806+
public static bool RunManagedCommand (string command, string? workingDirectory, bool echoStderr, bool ignoreEmptyArguments, params string [] arguments)
807+
{
808+
if (string.IsNullOrEmpty (command))
809+
throw new ArgumentException ("must not be null or empty", nameof (command));
810+
811+
var runner = new ProcessRunner ("dotnet", ignoreEmptyArguments, new [] { command }.Concat (arguments).ToArray ()) {
812+
EchoStandardError = echoStderr,
813+
WorkingDirectory = workingDirectory,
814+
};
815+
816+
return runner.Run ();
817+
}
818+
799819
public static string GetStringFromStdout (string command, params string?[] arguments)
800820
{
801821
return GetStringFromStdout (command, throwOnErrors: false, trimTrailingWhitespace: true, arguments: arguments);

build-tools/xaprepare/xaprepare/Steps/Step_InstallMonoRuntimes.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,14 @@ async Task<bool> ConjureXamarinCecilAndRemapRef (Context context, bool haveManag
106106
}
107107

108108
StatusStep (context, "Conjuring Xamarin.Android.Cecil and Xamari.Android.Cecil.Mdb");
109-
string conjurer = Path.Combine (Configurables.Paths.BuildBinDir, "conjure-xamarin-android-cecil.exe");
110-
string conjurerSourceDir = Configurables.Paths.MonoProfileToolsDir;
111-
string conjurerDestDir = Configurables.Paths.BuildBinDir;
109+
string conjurer = Path.Combine (Configurables.Paths.BuildBinDir, "conjure-xamarin-android-cecil.dll");
112110

113-
result = Utilities.RunCommand (
114-
haveManagedRuntime ? managedRuntime : conjurer, // command
111+
result = Utilities.RunManagedCommand (
112+
conjurer, // command
115113
BuildPaths.XamarinAndroidSourceRoot, // workingDirectory
116114
true, // ignoreEmptyArguments
117115

118116
// arguments
119-
haveManagedRuntime ? conjurer : String.Empty,
120117
Configurables.Paths.MonoProfileToolsDir, // source dir
121118
Configurables.Paths.BuildBinDir // destination dir
122119
);
@@ -174,13 +171,12 @@ bool InstallUtilities (Context context, bool haveManagedRuntime, string managedR
174171

175172
string relDestFilePath = Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, destFilePath);
176173
StatusSubStep (context, $"Remapping Cecil references for {relDestFilePath}");
177-
bool result = Utilities.RunCommand (
178-
haveManagedRuntime ? managedRuntime : remapper, // command
174+
bool result = Utilities.RunManagedCommand (
175+
remapper, // command
179176
BuildPaths.XamarinAndroidSourceRoot, // workingDirectory
180177
true, // ignoreEmptyArguments
181178

182179
// arguments
183-
haveManagedRuntime ? remapper : String.Empty,
184180
Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, muf.SourcePath),
185181
relDestFilePath,
186182
"Mono.Cecil",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Xamarin.Android.Prepare
8+
{
9+
partial class ConjureXamarinAndroidCecilRunner : ToolRunner
10+
{
11+
protected override string DefaultToolExecutableName => "dotnet";
12+
protected override string ToolName => "dotnet";
13+
14+
public List<string> StandardArguments { get; }
15+
16+
public ConjureXamarinAndroidCecilRunner (Context context, Log? log = null, string? msbuildPath = null)
17+
: base (context, log, msbuildPath)
18+
{
19+
ProcessTimeout = TimeSpan.FromMinutes (1);
20+
21+
StandardArguments = new List<string> {
22+
Path.Combine (Configurables.Paths.BuildBinDir, "conjure-xamarin-android-cecil.dll"),
23+
};
24+
}
25+
26+
public async Task<bool> Run (string logTag, List<string>? arguments = null, string? workingDirectory = null)
27+
{
28+
if (string.IsNullOrEmpty (logTag))
29+
throw new ArgumentException ("must not be null or empty", nameof (logTag));
30+
31+
if (string.IsNullOrEmpty (workingDirectory))
32+
workingDirectory = BuildPaths.XamarinAndroidSourceRoot;
33+
34+
ProcessRunner runner = CreateProcessRunner ();
35+
36+
AddArguments (runner, StandardArguments);
37+
AddArguments (runner, arguments);
38+
39+
string message = GetLogMessage (runner);
40+
Log.Info (message, CommandMessageColor);
41+
Log.StatusLine ();
42+
43+
try {
44+
return await RunTool (
45+
() => {
46+
using (var outputSink = (OutputSink)SetupOutputSink (runner, $"conjurer.{logTag}")) {
47+
runner.WorkingDirectory = workingDirectory;
48+
StartTwiddler ();
49+
return runner.Run ();
50+
}
51+
}
52+
);
53+
} finally {
54+
StopTwiddler ();
55+
}
56+
}
57+
58+
protected override TextWriter CreateLogSink (string? logFilePath)
59+
{
60+
return new OutputSink (Log, logFilePath);
61+
}
62+
63+
class OutputSink : ToolRunner.ToolOutputSink
64+
{
65+
public override Encoding Encoding => Encoding.Default;
66+
67+
public OutputSink (Log log, string? logFilePath)
68+
: base (log, logFilePath)
69+
{
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)