Skip to content

Commit

Permalink
Merge pull request #1506 from rolfbjarne/mtouch-single-invocation
Browse files Browse the repository at this point in the history
[mtouch] Build extensions and the container app in the same mtouch process.
  • Loading branch information
rolfbjarne committed Jan 16, 2017
2 parents a563a66 + 5aaea3e commit 3a480b5
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 70 deletions.
4 changes: 4 additions & 0 deletions docs/website/mtouch-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ A last-straw solution would be to use a different version of Xamarin.iOS, one th

<h3><a name="MT0096"/>MT0096: No reference to Xamarin.iOS.dll was found.</h3>

<h3><a name="MT0099"/>Internal error *. Please file a bug report with a test case (http://bugzilla.xamarin.com).</h3>

This indicates a bug in Xamarin.iOS; please file a bug report at [http://bugzilla.xamarin.com](https://bugzilla.xamarin.com/enter_bug.cgi?product=iOS) with a test case.

# MT1xxx: Project related error messages

### MT10xx: Installer / mtouch
Expand Down
33 changes: 33 additions & 0 deletions tests/mtouch/MTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ public void ExecutableName ()
}
}

[Test]
public void MT0008 ()
{
using (var mtouch = new MTouchTool ()) {
mtouch.CreateTemporaryAppDirectory ();
mtouch.CustomArguments = new string [] { "foo.exe", "bar.exe" };
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build");
mtouch.AssertError (8, "You should provide one root assembly only, found 2 assemblies: 'foo.exe', 'bar.exe'");
}
}

[Test]
public void MT0015 ()
{
Expand All @@ -216,6 +227,28 @@ public void MT0015 ()
"error MT0015: Invalid ABI: invalid-arm. Supported ABIs are: i386, x86_64, armv7, armv7+llvm, armv7+llvm+thumb2, armv7s, armv7s+llvm, armv7s+llvm+thumb2, armv7k, armv7k+llvm, arm64 and arm64+llvm.\n");
}

[Test]
public void MT0017 ()
{
using (var mtouch = new MTouchTool ()) {
mtouch.CreateTemporaryAppDirectory ();
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build");
mtouch.AssertError (17, "You should provide a root assembly.");
}
}

[Test]
public void MT0018 ()
{
using (var mtouch = new MTouchTool ()) {
mtouch.CustomArguments = new string [] { "--unknown", "-unknown" };
mtouch.CreateTemporaryAppDirectory ();
mtouch.AssertExecuteFailure (MTouchAction.BuildSim, "build");
mtouch.AssertError (18, "Unknown command line argument: '-unknown'");
mtouch.AssertError (18, "Unknown command line argument: '--unknown'");
}
}

[Test]
[TestCase (Profile.iOS, Profile.tvOS)]
[TestCase (Profile.iOS, Profile.watchOS)]
Expand Down
8 changes: 7 additions & 1 deletion tests/mtouch/MTouchTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MTouchTool : Tool, IDisposable
public Profile Profile = Profile.iOS;
public bool NoPlatformAssemblyReference;
static XmlDocument device_list_cache;

public string [] CustomArguments; // Sometimes you want to pass invalid arguments to mtouch, in this case this array is used. No processing will be done, if quotes are required, they must be added to the arguments in the array.

public class DeviceInfo
{
Expand Down Expand Up @@ -310,6 +310,12 @@ string BuildArguments (MTouchAction action)
if (!string.IsNullOrEmpty (Device))
sb.Append (" --device:").Append (MTouch.Quote (Device));

if (CustomArguments != null) {
foreach (var arg in CustomArguments) {
sb.Append (" ").Append (arg);
}
}

return sb.ToString ();
}

Expand Down
1 change: 1 addition & 0 deletions tools/mmp/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Xamarin.Bundler {
// MM0089 ** Reserved mtouch **
// MM0097 machine.config file '{0}' can not be found.
// MM0098 AOT compilation is only available on Unified
// MM0099 Internal error {0}. Please file a bug report with a test case (http://bugzilla.xamarin.com).
// MM1xxx file copy / symlinks (project related)
// MM14xx Product assemblies
// MM1401 The required '{0}' assembly is missing from the references
Expand Down
21 changes: 21 additions & 0 deletions tools/mtouch/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public bool EnableMSym {

public bool IsExtension;
public List<string> Extensions = new List<string> (); // A list of the extensions this app contains.
public List<Application> AppExtensions = new List<Application> ();

public bool FastDev;

Expand Down Expand Up @@ -590,6 +591,26 @@ public void SetDefaultFramework ()

void Initialize ()
{
if (EnableDebug && IsLLVM)
ErrorHelper.Warning (3003, "Debugging is not supported when building with LLVM. Debugging has been disabled.");

if (!IsLLVM && (EnableAsmOnlyBitCode || EnableLLVMOnlyBitCode))
throw ErrorHelper.CreateError (3008, "Bitcode support requires the use of LLVM (--abi=arm64+llvm etc.)");

if (EnableDebug) {
if (!DebugTrack.HasValue) {
DebugTrack = IsSimulatorBuild;
}
} else {
if (DebugTrack.HasValue) {
ErrorHelper.Warning (32, "The option '--debugtrack' is ignored unless '--debug' is also specified.");
}
DebugTrack = false;
}

if (EnableAsmOnlyBitCode)
LLVMAsmWriter = true;

if (!File.Exists (RootAssembly))
throw new MonoTouchException (7, true, "The root assembly '{0}' does not exist", RootAssembly);

Expand Down
1 change: 1 addition & 0 deletions tools/mtouch/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace Xamarin.Bundler {
// MT0096 No reference to Xamarin.iOS.dll was found.
// MT0097 <used by mmp>
// MT0098 <used by mmp>
// MT0099 Internal error {0}. Please file a bug report with a test case (http://bugzilla.xamarin.com).
// MT1xxx file copy / symlinks (project related)
// MT10xx installer.cs / mtouch.cs
// MT1001 Could not find an application at the specified directory: {0}
Expand Down
158 changes: 89 additions & 69 deletions tools/mtouch/mtouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ enum Action {
LaunchWatchApp,
}

static Action action;

static bool xcode_version_check = true;

//
Expand Down Expand Up @@ -332,7 +330,7 @@ static string FindSystemXcode ()
return output.ToString ().Trim ();
}

static void ValidateXcode ()
static void ValidateXcode (Action action)
{
// Allow a few actions, since these seem to always work no matter the Xcode version.
var accept_any_xcode_version = action == Action.ListDevices || action == Action.ListCrashReports || action == Action.ListApps || action == Action.LogDev;
Expand Down Expand Up @@ -960,31 +958,9 @@ public static int Main (string [] args)
return 0;
}

static void SetAction (Action value)
{
switch (action) {
case Action.None:
action = value;
break;
case Action.KillApp:
if (value == Action.LaunchDevice) {
action = Action.KillAndLaunch;
break;
}
goto default;
case Action.LaunchDevice:
if (value == Action.KillApp) {
action = Action.KillAndLaunch;
break;
}
goto default;
default:
throw new MonoTouchException (19, true, "Only one --[log|install|kill|launch]dev or --[launch|debug|list]sim option can be used.");
}
}

static int Main2 (string [] args)
static Application ParseArguments (string [] args, out Action a)
{
var action = Action.None;
var app = new Application ();
var assemblies = new List<string> ();

Expand All @@ -998,6 +974,29 @@ static int Main2 (string [] args)
string tls_provider = null;
string http_message_handler = null;

Action<Action> SetAction = (Action value) =>
{
switch (action) {
case Action.None:
action = value;
break;
case Action.KillApp:
if (value == Action.LaunchDevice) {
action = Action.KillAndLaunch;
break;
}
goto default;
case Action.LaunchDevice:
if (value == Action.KillApp) {
action = Action.KillAndLaunch;
break;
}
goto default;
default:
throw new MonoTouchException (19, true, "Only one --[log|install|kill|launch]dev or --[launch|debug|list]sim option can be used.");
}
};

var os = new OptionSet () {
{ "h|?|help", "Displays the help", v => SetAction (Action.Help) },
{ "version", "Output version information and exit.", v => SetAction (Action.Version) },
Expand Down Expand Up @@ -1272,48 +1271,61 @@ static int Main2 (string [] args)
throw new MonoTouchException (10, true, e, "Could not parse the command line arguments: {0}", e);
}

if (watch_level > 0) {
watch = new Stopwatch ();
watch.Start ();
}
a = action;

if (action == Action.Help) {
ShowHelp (os);
return 0;
return null;
} else if (action == Action.Version) {
Console.Write ("mtouch {0}.{1}", Constants.Version, Constants.Revision);
Console.WriteLine ();
return 0;
return null;
}

app.SetDefaultFramework ();
app.SetDefaultAbi ();

if (app.EnableDebug && app.IsLLVM)
ErrorHelper.Warning (3003, "Debugging is not supported when building with LLVM. Debugging has been disabled.");
app.RuntimeOptions = RuntimeOptions.Create (app, http_message_handler, tls_provider);

if (!app.IsLLVM && (app.EnableAsmOnlyBitCode || app.EnableLLVMOnlyBitCode))
ErrorHelper.Error (3008, "Bitcode support requires the use of LLVM (--abi=arm64+llvm etc.)");
if (action == Action.Build || action == Action.RunRegistrar) {
if (assemblies.Count != 1) {
var exceptions = new List<Exception> ();
for (int i = assemblies.Count - 1; i >= 0; i--) {
if (assemblies [i].StartsWith ("-", StringComparison.Ordinal)) {
exceptions.Add (new MonoTouchException (18, true, "Unknown command line argument: '{0}'", assemblies [i]));
assemblies.RemoveAt (i);
}
}
if (assemblies.Count > 1) {
exceptions.Add (new MonoTouchException (8, true, "You should provide one root assembly only, found {0} assemblies: '{1}'", assemblies.Count, string.Join ("', '", assemblies.ToArray ())));
} else if (assemblies.Count == 0) {
exceptions.Add (new MonoTouchException (17, true, "You should provide a root assembly."));
}

if (app.EnableDebug) {
if (!app.DebugTrack.HasValue) {
app.DebugTrack = app.IsSimulatorBuild;
}
} else {
if (app.DebugTrack.HasValue) {
ErrorHelper.Warning (32, "The option '--debugtrack' is ignored unless '--debug' is also specified.");
throw new AggregateException (exceptions);
}
app.DebugTrack = false;
app.RootAssembly = assemblies [0];
}

if (app.EnableAsmOnlyBitCode)
app.LLVMAsmWriter = true;
return app;
}

ErrorHelper.Verbosity = verbose;
static int Main2 (string[] args)
{
Action action;
var app = ParseArguments (args, out action);

app.RuntimeOptions = RuntimeOptions.Create (app, http_message_handler, tls_provider);
if (app == null)
return 0;

if (watch_level > 0) {
watch = new Stopwatch ();
watch.Start ();
}

ValidateXcode ();
ErrorHelper.Verbosity = verbose;

ValidateXcode (action);

switch (action) {
/* Device actions */
Expand Down Expand Up @@ -1374,23 +1386,6 @@ static int Main2 (string [] args)
if (!Directory.Exists (app.AppDirectory))
Directory.CreateDirectory (app.AppDirectory);

if (assemblies.Count != 1) {
var exceptions = new List<Exception> ();
for (int i = assemblies.Count - 1; i >= 0; i--) {
if (assemblies [i].StartsWith ("-", StringComparison.Ordinal)) {
exceptions.Add (new MonoTouchException (18, true, "Unknown command line argument: '{0}'", assemblies [i]));
assemblies.RemoveAt (i);
}
}
if (assemblies.Count > 1) {
exceptions.Add (new MonoTouchException (8, true, "You should provide one root assembly only, found {0} assemblies: '{1}'", assemblies.Count, string.Join ("', '", assemblies.ToArray ())));
} else if (assemblies.Count == 0) {
exceptions.Add (new MonoTouchException (17, true, "You should provide a root assembly."));
}

throw new AggregateException (exceptions);
}

if (app.EnableRepl && app.BuildTarget != BuildTarget.Simulator)
throw new MonoTouchException (29, true, "REPL (--enable-repl) is only supported in the simulator (--sim)");

Expand All @@ -1402,11 +1397,36 @@ static int Main2 (string [] args)

Watch ("Setup", 1);

app.RootAssembly = assemblies [0];
if (action == Action.RunRegistrar) {
app.RunRegistrar ();
} else if (action == Action.Build) {
if (app.IsExtension && !app.IsWatchExtension) {
var sb = new StringBuilder ();
foreach (var arg in args)
sb.AppendLine (arg);
File.WriteAllText (Path.Combine (Path.GetDirectoryName (app.AppDirectory), "build-arguments.txt"), sb.ToString ());
} else {
foreach (var appex in app.Extensions) {
var f_path = Path.Combine (appex, "..", "build-arguments.txt");
if (!File.Exists (f_path))
continue;
Action app_action;
app.AppExtensions.Add (ParseArguments (File.ReadAllLines (f_path), out app_action));
if (app_action != Action.Build)
throw ErrorHelper.CreateError (99, "Internal error: Extension build action is '{0}' when it should be 'Build'. Please file a bug report with a test case (http://bugzilla.xamarin.com).", app_action);
}

foreach (var appex in app.AppExtensions) {
Log ("Building {0}...", appex.BundleId);
appex.Build ();
}

if (app.AppExtensions.Count > 0)
Log ("Building {0}...", app.BundleId);
app.Build ();
}
} else {
app.Build ();
throw ErrorHelper.CreateError (99, "Internal error: Invalid action: {0}. Please file a bug report with a test case (http://bugzilla.xamarin.com).", action);
}

return 0;
Expand Down

0 comments on commit 3a480b5

Please sign in to comment.