[runtime] Add aot arguments to mkbundle
[mono.git] / mcs / tools / mkbundle / mkbundle.cs
index 4febb86c32014b1ea38858496f77a55cf301bbe2..78f990c568b9fccdc519f5920cfe604e304de56b 100755 (executable)
@@ -63,6 +63,8 @@ class MakeBundle {
        static bool custom_mode = true;
        static string embedded_options = null;
        static string runtime = null;
+       static bool aot_compile = false;
+       static string aot_args = "static";
        static string sdk_path = null;
        static string lib_path = null;
        static Dictionary<string,string> environment = new Dictionary<string,string>();
@@ -135,7 +137,7 @@ class MakeBundle {
                                        return 1;
                                }
                                if (sdk_path != null || runtime != null)
-                                       Error ("You can not specify one of --runtime, --sdk or --cross");
+                                       Error ("You can only specify one of --runtime, --sdk or --cross");
                                custom_mode = false;
                                autodeps = true;
                                cross_target = args [++i];
@@ -213,7 +215,7 @@ class MakeBundle {
                                autodeps = true;
                                sdk_path = args [++i];
                                if (cross_target != null || runtime != null)
-                                       Error ("You can not specify one of --runtime, --sdk or --cross");
+                                       Error ("You can only specify one of --runtime, --sdk or --cross");
                                break;
                        case "--runtime":
                                if (i+1 == top){
@@ -351,11 +353,20 @@ class MakeBundle {
                        case "--bundled-header":
                                bundled_header = true;
                                break;
+                       case "--aot-compile":
+                               aot_compile = true;
+                               break;
+                       case "--aot-args":
+                               if (i+1 == top) {
+                                       Console.WriteLine ("AOT arguments are passed as a comma-delimited list");
+                                       return 1;
+                               }
+                               aot_args = String.Format("static,{0}", args [++i]);
+                               break;
                        default:
                                sources.Add (args [i]);
                                break;
                        }
-
                }
                // Modern bundling starts here
                if (!custom_mode){
@@ -411,6 +422,8 @@ class MakeBundle {
                foreach (string file in assemblies)
                        if (!QueueAssembly (files, file))
                                return 1;
+               if (aot_compile)
+                       AotCompile (files);
                if (custom_mode)
                        GenerateBundles (files);
                else 
@@ -537,7 +550,6 @@ class MakeBundle {
                                        Console.WriteLine ("At {0:x} with input {1}", package.Position, fileStream.Length);
                                fileStream.CopyTo (package);
                                package.Position = package.Position + (align - (package.Position % align));
-
                                return (int) ret;
                        }
                }
@@ -821,6 +833,10 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                                }
                        }
 
+                       if (aot_compile) {
+                               // Read in static AOT file
+                       }
+
                        if (config_file != null){
                                FileStream conf;
                                try {
@@ -1169,9 +1185,18 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                        return true;
                try {
                        Assembly a = universe.LoadFile (path);
+                       if (a == null) {
+                               Error ("Unable to to load assembly `{0}'", path);
+                               return false;
+                       }
 
                        foreach (AssemblyName an in a.GetReferencedAssemblies ()) {
                                a = LoadAssembly (an.Name);
+                               if (a == null) {
+                                       Error ("Unable to load assembly `{0}' referenced by `{1}'", an.Name, path);
+                                       return false;
+                               }
+
                                if (!QueueAssembly (files, a.CodeBase))
                                        return false;
                        }
@@ -1322,6 +1347,14 @@ void          mono_register_config_for_assembly (const char* assembly_name, cons
                }
        }
 
+       static void AotCompile (List<string> files)
+       {
+               foreach (var fileName in files) {
+                       string path = LocateFile (new Uri (fileName).LocalPath);
+                       Execute (String.Format ("{0} --aot={1} {2}", runtime, aot_args, path));
+               }
+       }
+
        static void Execute (string cmdLine)
        {
                if (IsUnix) {