Skip to content

Commit

Permalink
[mkbundle] New mkbundle options for better handling integration with …
Browse files Browse the repository at this point in the history
…native libs.

New --skip-scan flag allow us to handle resource assemblies as opaque data.
New --static-ctor flag allows us to better interop with weird C libraries requirements.
  • Loading branch information
kumpera committed Oct 21, 2013
1 parent 2a4a459 commit 0a4a52c
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions mcs/tools/mkbundle/mkbundle.cs
Expand Up @@ -38,6 +38,8 @@ class MakeBundle {
static bool compress;
static bool nomain;
static bool? use_dos2unix = null;
static bool skip_scan;
static string ctor_func;

static int Main (string [] args)
{
Expand Down Expand Up @@ -145,6 +147,16 @@ static int Main (string [] args)
return 1;
}

break;
case "--skip-scan":
skip_scan = true;
break;
case "--static-ctor":
if (i+1 == top) {
Help ();
return 1;
}
ctor_func = args [++i];
break;
default:
sources.Add (args [i]);
Expand All @@ -163,10 +175,10 @@ static int Main (string [] args)
Environment.Exit (1);
}

List<Assembly> assemblies = LoadAssemblies (sources);
List<string> assemblies = LoadAssemblies (sources);
List<string> files = new List<string> ();
foreach (Assembly a in assemblies)
QueueAssembly (files, a.CodeBase);
foreach (string file in assemblies)
QueueAssembly (files, file);

// Special casing mscorlib.dll: any specified mscorlib.dll cannot be loaded
// by Assembly.ReflectionFromLoadFrom(). Instead the fx assembly which runs
Expand Down Expand Up @@ -437,6 +449,12 @@ static void GenerateBundles (List<string> files)
tc.WriteLine ("\tNULL\n};\n");
tc.WriteLine ("static char *image_name = \"{0}\";", prog);

if (ctor_func != null) {
tc.WriteLine ("\nextern void {0} (void);", ctor_func);
tc.WriteLine ("\n__attribute__ ((constructor)) static void mono_mkbundle_ctor (void)");
tc.WriteLine ("{{\n\t{0} ();\n}}", ctor_func);
}

tc.WriteLine ("\nstatic void install_dll_config_files (void) {\n");
foreach (string[] ass in config_names){
tc.WriteLine ("\tmono_register_config_for_assembly (\"{0}\", assembly_config_{1});\n", ass [0], ass [1]);
Expand Down Expand Up @@ -518,20 +536,29 @@ static void GenerateBundles (List<string> files)
}
}

static List<Assembly> LoadAssemblies (List<string> sources)
static List<string> LoadAssemblies (List<string> sources)
{
List<Assembly> assemblies = new List<Assembly> ();
List<string> assemblies = new List<string> ();
bool error = false;

foreach (string name in sources){
Assembly a = LoadAssembly (name);
try {
Assembly a = LoadAssembly (name);

if (a == null){
error = true;
continue;
}
if (a == null){
error = true;
continue;
}

assemblies.Add (a);
assemblies.Add (a.CodeBase);
} catch (Exception e) {
if (skip_scan) {
Console.WriteLine ("File will not be scanned: {0}", name);
assemblies.Add (new Uri (new FileInfo (name).FullName).ToString ());
} else {
throw;
}
}
}

if (error)
Expand All @@ -544,18 +571,23 @@ static List<Assembly> LoadAssemblies (List<string> sources)

static void QueueAssembly (List<string> files, string codebase)
{
// Console.WriteLine ("CODE BASE IS {0}", codebase);
if (files.Contains (codebase))
return;

files.Add (codebase);
Assembly a = universe.LoadFile (new Uri(codebase).LocalPath);

if (!autodeps)
return;

foreach (AssemblyName an in a.GetReferencedAssemblies ()) {
a = universe.Load (an.Name);
QueueAssembly (files, a.CodeBase);
try {
Assembly a = universe.LoadFile (new Uri(codebase).LocalPath);

foreach (AssemblyName an in a.GetReferencedAssemblies ()) {
a = universe.Load (an.Name);
QueueAssembly (files, a.CodeBase);
}
} catch (Exception e) {
if (!skip_scan)
throw;
}
}

Expand Down Expand Up @@ -626,6 +658,8 @@ static void Help ()
" --static Statically link to mono libs\n" +
" --nomain Don't include a main() function, for libraries\n" +
" -z Compress the assemblies before embedding.\n" +
" --skip-scan Skip scanning assemblies that could not be loaded (but still embed them).\n" +
" --static-ctor ctor Add a constructor call to the supplied function.\n" +
" You need zlib development headers and libraries.\n");
}

Expand Down

0 comments on commit 0a4a52c

Please sign in to comment.