Merge pull request #4716 from Unity-Technologies/eglib-msvc-targets
[mono.git] / mcs / ilasm / Driver.cs
index d4315f4c640ba726c21b1e7171ae10f6071d2966..af7120dce5878fc481227faf290c186e52eb5662 100644 (file)
@@ -33,7 +33,7 @@ namespace Mono.ILASM {
                         DriverMain driver = new DriverMain (args);
                         if (!driver.Run ())
                                 return 1;
-                        Console.WriteLine ("Operation completed successfully");
+                        Report.Message ("Operation completed successfully");
                         return 0;
                 }
 
@@ -44,14 +44,15 @@ namespace Mono.ILASM {
                         private Target target = Target.Exe;
                         private string target_string = "exe";
                         private bool show_tokens = false;
-                        private bool show_method_def = false;
-                        private bool show_method_ref = false;
+//                        private bool show_method_def = false;
+//                        private bool show_method_ref = false;
                         private bool show_parser = false;
                         private bool scan_only = false;
                        private bool debugging_info = false;
                         private CodeGen codegen;
                        private bool keycontainer = false;
                        private string keyname;
+                       private StrongName sn;
 
                         public DriverMain (string[] args)
                         {
@@ -66,9 +67,11 @@ namespace Mono.ILASM {
                                 if (output_file == null)
                                         output_file = CreateOutputFilename ();
                                 try {
-                                        codegen = new CodeGen (output_file, target == Target.Dll, true, debugging_info);
-                                        foreach (string file_path in il_file_list)
+                                        codegen = new CodeGen (output_file, target == Target.Dll, debugging_info);
+                                        foreach (string file_path in il_file_list) {
+                                                Report.FilePath = file_path;
                                                 ProcessFile (file_path);
+                                        }
                                         if (scan_only)
                                                 return true;
 
@@ -78,6 +81,13 @@ namespace Mono.ILASM {
                                         if (target != Target.Dll && !codegen.HasEntryPoint)
                                                 Report.Error ("No entry point found.");
 
+                                       // if we have a key and aren't assembling a netmodule
+                                       if ((keyname != null) && !codegen.IsThisAssembly (null)) {
+                                               LoadKey ();
+                                               // this overrides any attribute or .publickey directive in the source
+                                               codegen.ThisAssembly.SetPublicKey (sn.PublicKey);
+                                       }
+
                                         try {
                                                 codegen.Write ();
                                         } catch {
@@ -85,16 +95,16 @@ namespace Mono.ILASM {
                                                 throw;
                                         }
                                 } catch (ILAsmException e) {
-                                        Error (e.Message);
+                                        Error (e.ToString ());
                                         return false;
                                 } catch (PEAPI.PEFileException pe) {
-                                        Error (pe.Message);
+                                        Error ("Error : " + pe.Message);
                                         return false;
                                 } 
 
                                 try {
-                                       if (keyname != null) {
-                                               Console.WriteLine ("Signing assembly with the specified strongname keypair");
+                                       if (sn != null) {
+                                               Report.Message ("Signing assembly with the specified strongname keypair");
                                                return Sign (output_file);
                                        }
                                 } catch {
@@ -106,16 +116,12 @@ namespace Mono.ILASM {
 
                         private void Error (string message)
                         {
-                                Console.WriteLine ("Error : " + message + "\n");
+                                Console.WriteLine (message + "\n");
                                 Console.WriteLine ("***** FAILURE *****\n");
                         }
 
-                       private bool Sign (string filename)
+                       private void LoadKey ()
                        {
-                               // note: if the file cannot be signed (no public key in it) then
-                               // we do not show an error, or a warning, if the key file doesn't 
-                               // exists
-                               StrongName sn = null;
                                if (keycontainer) {
                                        CspParameters csp = new CspParameters ();
                                        csp.KeyContainerName = keyname;
@@ -130,6 +136,13 @@ namespace Mono.ILASM {
                                        }
                                        sn = new StrongName (data);
                                }
+                       }
+
+                       private bool Sign (string filename)
+                       {
+                               // note: if the file cannot be signed (no public key in it) then
+                               // we do not show an error, or a warning, if the key file doesn't 
+                               // exists
                                return sn.Sign (filename);
                        }
 
@@ -169,12 +182,15 @@ namespace Mono.ILASM {
                                         else
                                                 parser.yyparse (new ScannerAdapter (scanner),  null);
                                 } catch (ILTokenizingException ilte) {
-                                        Report.Error (file_path + "(" + ilte.Location.line + ") : error : " +
-                                                        "syntax error at token '" + ilte.Token + "'.");
-                                } catch (Mono.ILASM.yyParser.yyException) {
-                                        Report.Error ("Error at: " + scanner.Reader.Location);
-                                } catch {
-                                        Console.WriteLine ("Error at: " + scanner.Reader.Location);
+                                        Report.Error (ilte.Location, "syntax error at token '" + ilte.Token + "'");
+                                } catch (Mono.ILASM.yyParser.yyException ye) {
+                                        Report.Error (scanner.Reader.Location, ye.Message);
+                                } catch (ILAsmException ie) {
+                                        ie.FilePath = file_path;
+                                        ie.Location = scanner.Reader.Location;
+                                        throw;
+                                } catch (Exception){
+                                        Console.Write ("{0} ({1}, {2}): ",file_path, scanner.Reader.Location.line, scanner.Reader.Location.column);
                                         throw;
                                 } finally {
                                        codegen.EndSourceFile ();
@@ -233,8 +249,6 @@ namespace Mono.ILASM {
                                                 break;
                                         case "debug":
                                         case "deb":
-                                               if (str[0] != '-')
-                                                       break;
                                                debugging_info = true;
                                                break;
                                         // Stubs to stay commandline compatible with MS 
@@ -263,10 +277,10 @@ namespace Mono.ILASM {
                                                 show_tokens = true;
                                                 break;
                                         case "show_method_def":
-                                                show_method_def = true;
+//                                                show_method_def = true;
                                                 break;
                                         case "show_method_ref":
-                                                show_method_ref = true;
+//                                                show_method_ref = true;
                                                 break;
                                         case "show_parser":
                                                 show_parser = true;
@@ -346,7 +360,7 @@ namespace Mono.ILASM {
 
                         private void Version ()
                         {
-                                string version = Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
+                                string version = System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
                                 Console.WriteLine ("Mono ILasm compiler version {0}", version);
                                 Environment.Exit (0);
                         }