Author: zoltan
Date: 2005-07-08 12:24:33 -0400 (Fri, 08 Jul 2005)
New Revision: 47110

Modified:
   trunk/mcs/tools/al/Al.cs
   trunk/mcs/tools/al/ChangeLog
Log:
2005-07-08  Zoltan Varga  <[EMAIL PROTECTED]>

        * Al.cs: Applied patch from Sridhar Kulkarni ([EMAIL PROTECTED]).
        Implement /template option. Fixes #74814.


Modified: trunk/mcs/tools/al/Al.cs
===================================================================
--- trunk/mcs/tools/al/Al.cs    2005-07-08 16:13:59 UTC (rev 47109)
+++ trunk/mcs/tools/al/Al.cs    2005-07-08 16:24:33 UTC (rev 47110)
@@ -15,6 +15,7 @@
 using System.Reflection.Emit;
 using System.Security.Cryptography;
 using System.Text;
+using System.Configuration.Assemblies;
 
 using Mono.Security.Cryptography;
 
@@ -49,6 +50,8 @@
                string entryPoint;
                string win32IconFile;
                string win32ResFile;
+               string templateFile;
+               bool isTemplateFile = false;
                Target target;
                bool delaysign;
                string keyfile;
@@ -66,8 +69,22 @@
                        return 0;
                }
 
-               private void ParseArgs (string[] args) {
+               static bool IsStrongNamed (Assembly assembly)
+               {
+                       object[] attrs = assembly.GetCustomAttributes (true);
+                       foreach (object o in attrs) 
+                       {
+                               if (o is AssemblyKeyFileAttribute)
+                                       return true;
+                               else if (o is AssemblyKeyNameAttribute)
+                                       return true;
+                       }
+                       return false;
+               }
 
+               private void ParseArgs (string[] args) 
+               {
+
                        ArrayList flat_args = new ArrayList ();
 
                        // Process response files
@@ -344,9 +361,10 @@
                                        break;
 
                                case "template":
-                                       if (arg == null)
-                                               ReportMissingFileSpec (opt);
-                                       ReportNotImplemented (opt);
+                                       if (arg == null)
+                                               ReportMissingFileSpec (opt);
+                                       isTemplateFile = true;
+                                       templateFile = arg;
                                        break;
 
                                case "title":
@@ -400,7 +418,7 @@
                                Report (1035, "Libraries cannot have an entry 
point");
 
                        if (target == Target.Exe && (entryPoint == null))
-                               Report (1036, "Entry point required for 
executable applications");
+                               Report (1036, "Entry point required for 
executable applications");                                              
                }
 
                private string GetCommand (string str, out string command_arg) {
@@ -548,7 +566,7 @@
                                aname.KeyPair = new StrongNameKeyPair (keyname);
                        }
                }
-
+               
                private void DoIt () {
                        AssemblyName aname = new AssemblyName ();
                        aname.Name = Path.GetFileNameWithoutExtension (outFile);
@@ -557,7 +575,29 @@
                        string fileName = Path.GetFileName (outFile);
 
                        AssemblyBuilder ab;
+                       
+                       /*
+                        * Emit Manifest
+                        * */
 
+                       if(isTemplateFile) {
+                               
+                               byte[] pk;
+                               AssemblyName myAssm = new AssemblyName();
+                               myAssm.Name = Path.GetFileNameWithoutExtension 
(templateFile);
+                               Assembly assembly = Assembly.Load(myAssm);
+       
+                               if (!IsStrongNamed(assembly)){
+                                       Report (1055, String.Format ("Assembly 
specified does not have Strong Name '{0}'","template"));
+                      }
+                               pk = assembly.GetName().GetPublicKey();
+
+                               aname.SetPublicKey(pk);
+                               aname.HashAlgorithm = 
assembly.GetName().HashAlgorithm;
+                               aname.Version = assembly.GetName().Version;
+                               aname.HashAlgorithm = 
assembly.GetName().HashAlgorithm;
+                       }
+
                        if (fileName != outFile)
                                ab = 
AppDomain.CurrentDomain.DefineDynamicAssembly (aname, 
AssemblyBuilderAccess.Save, Path.GetDirectoryName (outFile));
                        else
@@ -679,51 +719,51 @@
                        }
                }
 
-               private void LoadArgs (string file, ArrayList args) {
-                       StreamReader f = null;
-                       string line;
-                       try {
-                               f = new StreamReader (file);
-
-                               StringBuilder sb = new StringBuilder ();
-                       
-                               while ((line = f.ReadLine ()) != null){
-                                       int t = line.Length;
-
-                                       for (int i = 0; i < t; i++){
-                                               char c = line [i];
-                                               
-                                               if (c == '"' || c == '\''){
-                                                       char end = c;
-                                                       
-                                                       for (i++; i < t; i++){
-                                                               c = line [i];
-
-                                                               if (c == end)
-                                                                       break;
-                                                               sb.Append (c);
-                                                       }
-                                               } else if (c == ' '){
-                                                       if (sb.Length > 0){
-                                                               args.Add 
(sb.ToString ());
-                                                               sb.Length = 0;
-                                                       }
-                                               } else
-                                                       sb.Append (c);
-                                       }
-                                       if (sb.Length > 0){
-                                               args.Add (sb.ToString ());
-                                               sb.Length = 0;
-                                       }
-                               }
-                       } catch (Exception ex) {
-                               Report (1007, "Error opening response file '" + 
file + "' -- '" + ex.Message + "'");
-                       } finally {
-                               if (f != null)
-                                       f.Close ();
-                       }
-               }
+               private void LoadArgs (string file, ArrayList args) {
+                       StreamReader f = null;
+                       string line;
+                       try {
+                               f = new StreamReader (file);
 
+                               StringBuilder sb = new StringBuilder ();
+                       
+                               while ((line = f.ReadLine ()) != null){
+                                       int t = line.Length;
+
+                                       for (int i = 0; i < t; i++){
+                                               char c = line [i];
+                                               
+                                               if (c == '"' || c == '\''){
+                                                       char end = c;
+                                                       
+                                                       for (i++; i < t; i++){
+                                                               c = line [i];
+
+                                                               if (c == end)
+                                                                       break;
+                                                               sb.Append (c);
+                                                       }
+                                               } else if (c == ' '){
+                                                       if (sb.Length > 0){
+                                                               args.Add 
(sb.ToString ());
+                                                               sb.Length = 0;
+                                                       }
+                                               } else
+                                                       sb.Append (c);
+                                       }
+                                       if (sb.Length > 0){
+                                               args.Add (sb.ToString ());
+                                               sb.Length = 0;
+                                       }
+                               }
+                       } catch (Exception ex) {
+                               Report (1007, "Error opening response file '" + 
file + "' -- '" + ex.Message + "'");
+                       } finally {
+                               if (f != null)
+                                       f.Close ();
+                       }
+               }
+
                string[] usage = {
                        "Usage: al [options] [sources]",
                        "Options: ('/out' must be specified)",

Modified: trunk/mcs/tools/al/ChangeLog
===================================================================
--- trunk/mcs/tools/al/ChangeLog        2005-07-08 16:13:59 UTC (rev 47109)
+++ trunk/mcs/tools/al/ChangeLog        2005-07-08 16:24:33 UTC (rev 47110)
@@ -1,3 +1,8 @@
+2005-07-08  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * Al.cs: Applied patch from Sridhar Kulkarni ([EMAIL PROTECTED]).
+       Implement /template option. Fixes #74814.
+
 2005-06-14  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * Al.cs: Added support for signing/delay-signing/ecma-delay-signing.

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to