Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runtime/launcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@

// 3) Ensure the following environment variables are set: [...]
NSString *res_dir = [data->app_dir stringByAppendingPathComponent: @"Contents/Resources"];
NSString *monobundle_dir = [data->app_dir stringByAppendingPathComponent: @"Contents/MonoBundle"];

#ifdef DYNAMIC_MONO_RUNTIME
NSString *bin_dir = [data->app_dir stringByAppendingPathComponent: @"Contents/MacOS"];
Expand Down Expand Up @@ -357,6 +358,8 @@
// So route through MONO_DEBUG
setenv ("MONO_DEBUG", "no-gdb-backtrace", 0);
}

setenv ("MONO_CFG_DIR", [monobundle_dir UTF8String], 0);
}

static void
Expand Down
4 changes: 4 additions & 0 deletions src/AppKit/NSApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static void Init ()
// that don't call Main.
NSApplication.mainThread = Thread.CurrentThread;

// Launcher sets this to work around https://bugzilla.xamarin.com/show_bug.cgi?id=45279
// But can affect child xbuild processes, so unset
Environment.SetEnvironmentVariable ("MONO_CFG_DIR", "");

// TODO:
// Install hook to register dynamically loaded assemblies
}
Expand Down
11 changes: 6 additions & 5 deletions tests/common/mac/MacTestMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ static void Main(string[] args)
static void RunTests()
{
TestRunner.MainLoop = new NSRunLoopIntegration();
TestRunner.Main(new[] {
typeof(MainClass).Assembly.Location,
"-labels",
"-noheader"
});
string testName = System.Environment.GetEnvironmentVariable ("XM_TEST_NAME");
string [] args = testName != null ?
new [] { typeof(MainClass).Assembly.Location, "-labels", "-noheader", string.Format ("-test={0}", testName) } :
new [] { typeof(MainClass).Assembly.Location, "-labels", "-noheader" };

TestRunner.Main (args);
}

class NSRunLoopIntegration : NSObject, IMainLoopIntegration
Expand Down
14 changes: 10 additions & 4 deletions tests/common/mac/ProjectTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public static string RunAndAssert (string exe, StringBuilder args, string stepNa
int compileResult = Xamarin.Bundler.Driver.RunCommand (exe, args != null ? args.ToString() : string.Empty, MonoDevelopLike, output, suppressPrintOnErrors: shouldFail);
Func<string> getInfo = () => getAdditionalFailInfo != null ? getAdditionalFailInfo() : "";
if (!shouldFail)
Assert.AreEqual (0, compileResult, stepName + " failed: '" + output + "' " + exe + " " + args + getInfo ());
Assert.AreEqual (0, compileResult, stepName + " failed:\n\n'" + output + "' " + exe + " " + args + getInfo ());
else
Assert.AreNotEqual (0, compileResult, stepName + " did not fail as expected: '" + output + "' " + exe + " " + args + getInfo ());
Assert.AreNotEqual (0, compileResult, stepName + " did not fail as expected:\n\n'" + output + "' " + exe + " " + args + getInfo ());

return output.ToString ();
}
Expand All @@ -111,11 +111,17 @@ public static string BuildProject (string csprojTarget, bool isUnified, bool sho

buildArgs.Append (csprojTarget);

Func <string> getBuildProjectErrorInfo = () => {
string csprojText = "\n\n\n\tCSProj: \n" + File.ReadAllText (csprojTarget);
string csprojLocation = Path.GetDirectoryName (csprojTarget);
string fileList = "\n\n\tFiles: " + String.Join (" ", Directory.GetFiles (csprojLocation).Select (x => x.Replace (csprojLocation + "/", "")));
return csprojText + fileList;
};

if (isUnified)
return RunAndAssert ("/Library/Frameworks/Mono.framework/Commands/xbuild", buildArgs, "Compile", shouldFail, () => File.ReadAllText (csprojTarget));
return RunAndAssert ("/Library/Frameworks/Mono.framework/Commands/xbuild", buildArgs, "Compile", shouldFail, getBuildProjectErrorInfo);
else
return RunAndAssert ("/Applications/Xamarin Studio.app/Contents/MacOS/mdtool", buildArgs, "Compile", shouldFail, () => File.ReadAllText (csprojTarget));
return RunAndAssert ("/Applications/Xamarin Studio.app/Contents/MacOS/mdtool", buildArgs, "Compile", shouldFail, getBuildProjectErrorInfo);
}

static string ProjectTextReplacement (UnifiedTestConfig config, string text)
Expand Down
87 changes: 86 additions & 1 deletion tests/mmptest/src/MMPTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ void RunMMPTest (Action <string> test)
{
string tmpDir = Path.Combine (Path.GetTempPath (), "mmp-test-dir");
try {
// Clean out any existing build there first to prevent strange behavior
if (Directory.Exists (tmpDir))
Directory.Delete (tmpDir, true);

Directory.CreateDirectory (tmpDir);
test (tmpDir);
}
Expand Down Expand Up @@ -380,5 +384,86 @@ static void MonoPosixTestCore (string tmpDir, TI.UnifiedTestConfig test)
Assert.IsTrue (File.Exists (Path.Combine (tmpDir, "bin/Debug/XM45Example.app/Contents/MonoBundle/Mono.Posix.dll")));
Assert.IsTrue (File.Exists (Path.Combine (tmpDir, "bin/Debug/XM45Example.app/Contents/MonoBundle/libMonoPosixHelper.dylib")));
}
}


const string machineConfigMobileLocation = "bin/Debug/UnifiedExample.app/Contents/MonoBundle/mono/4.5/machine.config";
const string machineConfigXM45Location = "bin/Debug/XM45Example.app/Contents/MonoBundle/mono/4.5/machine.config";

[Test]
public void Unified_ShouldNotGenerateMachineConfigInBundle_WithoutOption ()
{
RunMMPTest (tmpDir => {
TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir);
// Mobile
TI.TestUnifiedExecutable (test);

Assert.IsFalse (File.Exists (Path.Combine (tmpDir, machineConfigMobileLocation)));

// XM45
test.XM45 = true;
TI.TestUnifiedExecutable (test);

Assert.IsFalse (File.Exists (Path.Combine (tmpDir, machineConfigXM45Location)));
});
}

[Test]
public void Unified_InvalidMachineConfigInBundle_ThrowsError ()
{
RunMMPTest (tmpDir => {
string invalidConfigPath = Path.Combine (tmpDir, "nonexistant/machine.config");
TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) {
CSProjConfig = string.Format ("<MonoBundlingExtraArgs>--machine-config={0}</MonoBundlingExtraArgs>", invalidConfigPath)
};
string buildOutput = TI.TestUnifiedExecutable (test, shouldFail : true).BuildOutput;
Assert.IsTrue (buildOutput.Contains ("can not be found"), "Unified_InvalidMachineConfigInBundle_ThrowsError did not error as expected (1):\n\n", buildOutput);
Assert.IsTrue (buildOutput.Contains ("97"), "Unified_InvalidMachineConfigInBundle_ThrowsError did not error as expected (2):\n\n", buildOutput);
});
}

[Test]
public void Unified_ShouldGenerateMachineConfigInBundle_WithEmptyOption ()
{
RunMMPTest (tmpDir => {
TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) {
CSProjConfig = "<MonoBundlingExtraArgs>--machine-config=\"\"</MonoBundlingExtraArgs>"
};
TI.TestUnifiedExecutable (test);
Assert.IsTrue (File.Exists (Path.Combine (tmpDir, machineConfigMobileLocation)));

test.XM45 = true;
TI.TestUnifiedExecutable (test);
Assert.IsTrue (File.Exists (Path.Combine (tmpDir, machineConfigXM45Location)));
});
}

[Test]
public void Unified_ShouldGenerateMachineConfigInBundle_WhenPassedIn ()
{
RunMMPTest (tmpDir => {
const string configText = "THIS_IS_NOT_A_REAL_CONFIG_FILE";
string configPath = Path.Combine (tmpDir, "machine.config");
File.WriteAllLines (configPath, new string [] { configText });

TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) {
CSProjConfig = string.Format ("<MonoBundlingExtraArgs>--machine-config={0}</MonoBundlingExtraArgs>", configPath)
};

// Mobile
TI.TestUnifiedExecutable (test);

Assert.IsTrue (File.Exists (Path.Combine (tmpDir, machineConfigMobileLocation)));
string [] text = File.ReadAllLines (Path.Combine (tmpDir, machineConfigMobileLocation));
Assert.IsTrue (text.Length == 1 && text[0] == configText);

// XM45
test.XM45 = true;
TI.TestUnifiedExecutable (test);

Assert.IsTrue (File.Exists (Path.Combine (tmpDir, machineConfigXM45Location)));
text = File.ReadAllLines (Path.Combine (tmpDir, machineConfigXM45Location));
Assert.IsTrue (text.Length == 1 && text[0] == configText);
});
}
}
}
19 changes: 18 additions & 1 deletion tools/mmp/driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static partial class Driver {
static string link_flags = null;
static LinkerOptions linker_options;
static bool disable_lldb_attach = false;
static string machine_config_path = null;

static bool arch_set = false;
static string arch = "i386";
Expand Down Expand Up @@ -287,7 +288,8 @@ static void Main2 (string [] args)
{ "http-message-handler=", "Specify the default HTTP Message Handler", v => { http_message_provider = v; }},
{ "extension", "Specifies an app extension", v => is_extension = true },
{ "allow-unsafe-gac-resolution", "Allow MSBuild to resolve from the System GAC", v => {} , true }, // Used in Xamarin.Mac.XM45.targets and must be ignored here. Hidden since it is a total hack. If you can use it, you don't need support
{ "disable-lldb-attach=", "Disable automatic lldb attach on crash", v => disable_lldb_attach = ParseBool (v, "disable_lldb_attach")},
{ "disable-lldb-attach=", "Disable automatic lldb attach on crash", v => disable_lldb_attach = ParseBool (v, "disable-lldb-attach")},
{ "machine-config=", "Custom machine.config file to copy into MonoBundle/mono/4.5/machine.config. Pass \"\" to copy in a valid \"empty\" config file.", v => machine_config_path = v },
};

AddSharedOptions (os);
Expand Down Expand Up @@ -1498,6 +1500,21 @@ static void CopyConfiguration () {

CopyResourceFile ("config", "config");
}

if (machine_config_path != null) {
string machineConfigDestDir = Path.Combine (mmp_dir, "mono/4.5/");
string machineConfigDestFile = Path.Combine (machineConfigDestDir, "machine.config");

CreateDirectoryIfNeeded (machineConfigDestDir);
if (machine_config_path == String.Empty) {
File.WriteAllLines (machineConfigDestFile, new string [] { "<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<configuration>", "</configuration>" });
}
else {
if (!File.Exists (machine_config_path))
throw new MonoMacException (97, true, "machine.config file '{0}' can not be found.", machine_config_path);
File.Copy (machine_config_path, machineConfigDestFile);
}
}
}

static void CopyResourceFile (string streamName, string outputFileName) {
Expand Down
1 change: 1 addition & 0 deletions tools/mmp/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Xamarin.Bundler {
// Warning MT0080 Disabling NewRefCount, --new-refcount:false, is deprecated.
// MM0088 ** Reserved mtouch **
// MM0089 ** Reserved mtouch **
// MM0097 machine.config file '{0}' can not be found.
// MM1xxx file copy / symlinks (project related)
// MM14xx Product assemblies
// MM1401 The required '{0}' assembly is missing from the references
Expand Down
1 change: 1 addition & 0 deletions tools/mtouch/error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Xamarin.Bundler {
// Warning MT0094 <unused> Both profiling (--profiling) and incremental builds (--fastdev) are currently not supported when building for {0}, and incremental builds have been disabled (this will be fixed in a future release).
// MT0095 Aot files could not be copied to the destination directory.
// MT0096 No reference to Xamarin.iOS.dll was found.
// MT0097 <used by mmp>
// MT1xxx file copy / symlinks (project related)
// MT10xx installer.cs / mtouch.cs
// MT1001 Could not find an application at the specified directory: {0}
Expand Down