Add new mcs -sdk option
authorMarek Safar <marek.safar@gmail.com>
Mon, 17 Jan 2011 17:20:40 +0000 (17:20 +0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 17 Jan 2011 17:21:07 +0000 (17:21 +0000)
man/mcs.1
mcs/mcs/driver.cs
mcs/mcs/ikvm.cs
mcs/mcs/rootcontext.cs

index 4582b4117878d04b540a8913b8c2d5c70e4f062a..0fdec3b8200b6d23b9fcb7d0e7ebe152a18d77c2 100644 (file)
--- a/man/mcs.1
+++ b/man/mcs.1
@@ -351,6 +351,11 @@ shell will perform globbing, so you might want to use it like this:
                $ mcs -recurse:'*.cs' 
 .fi
 .TP
+.I \-sdk:VERSION
+Used to specify the version of Base Class Library assemblies. The possible
+values are: 2 (default), 4. The version number means which .NET version
+should the produced assembly be compatible with.
+.TP
 .I \-\-shell
 Starts up the compiler in interactive mode, providing a C# shell for
 statements and expressions.   A shortcut is to use the
index 8a63e7ff2078f457389475eabd57834c65f0d77e..47b075ee2e0ef47d0b0db0fca9f79013fb5e5115 100644 (file)
@@ -167,8 +167,8 @@ namespace Mono.CSharp
                                "   --about              About the Mono C# compiler\n" +
                                "   -addmodule:M1[,Mn]   Adds the module to the generated assembly\n" + 
                                "   -checked[+|-]        Sets default aritmetic overflow context\n" +
-                               "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
                                "   -clscheck[+|-]       Disables CLS Compliance verifications\n" +
+                               "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
                                "   -define:S1[;S2]      Defines one or more conditional symbols (short: -d)\n" +
                                "   -debug[+|-], -g      Generate debugging information\n" + 
                                "   -delaysign[+|-]      Only insert the public key into the assembly (no signing)\n" +
@@ -191,7 +191,9 @@ namespace Mono.CSharp
                                "                        ARCH can be one of: anycpu, x86, x64 or itanium\n" +
                                "   -recurse:SPEC        Recursively compiles files according to SPEC pattern\n" + 
                                "   -reference:A1[,An]   Imports metadata from the specified assembly (short: -r)\n" +
-                               "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +                         
+                               "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +
+                               "   -sdk:VERSION         Specifies SDK version of referenced assemlies\n" +
+                               "                        VERSION can be one of: 2 (default), 4\n" +
                                "   -target:KIND         Specifies the format of the output assembly (short: -t)\n" +
                                "                        KIND can be one of: exe, winexe, library, module\n" +
                                "   -unsafe[+|-]         Allows to compile code which uses unsafe keyword\n" +
@@ -1193,6 +1195,26 @@ namespace Mono.CSharp
 
                                return true;
 
+                       case "/sdk":
+                               if (value.Length == 0) {
+                                       Error_RequiresArgument (option);
+                                       break;
+                               }
+
+                               switch (value.ToLowerInvariant ()) {
+                                       case "2":
+                                               RootContext.SdkVersion = SdkVersion.v2;
+                                               break;
+                                       case "4":
+                                               RootContext.SdkVersion = SdkVersion.v4;
+                                               break;
+                                       default:
+                                               Report.Error (-26, "Invalid sdk version name");
+                                               break;
+                               }
+
+                               return true;
+
                                // We just ignore this.
                        case "/errorreport":
                        case "/filealign":
index e144ddd83cfa59b6ad97e6902d00b7ccf7872edf..d641234f80bcba9abee7648b206eac83567cbc82 100644 (file)
@@ -177,6 +177,14 @@ namespace Mono.CSharp
                readonly Universe domain;
                Assembly corlib;
                List<Tuple<AssemblyName, string>> loaded_names;
+               static readonly Dictionary<SdkVersion, string[]> sdk_directory;
+
+               static StaticLoader ()
+               {
+                       sdk_directory = new Dictionary<SdkVersion, string[]> ();
+                       sdk_directory.Add (SdkVersion.v2, new string[] { "2.0", "net_2_0", "v2.0.50727" });
+                       sdk_directory.Add (SdkVersion.v4, new string[] { "4.0", "net_4_0", "v4.0.30319" });
+               }
 
                public StaticLoader (StaticImporter importer, CompilerContext compiler)
                        : base (compiler)
@@ -186,8 +194,23 @@ namespace Mono.CSharp
                        domain.AssemblyResolve += AssemblyReferenceResolver;
                        loaded_names = new List<Tuple<AssemblyName, string>> ();
 
-                       // TODO: profile specific
-                       paths.Add (Path.GetDirectoryName (typeof (object).Assembly.Location));
+                       var corlib_path = Path.GetDirectoryName (typeof (object).Assembly.Location);
+                       string fx_path = corlib_path.Substring (0, corlib_path.LastIndexOf (Path.DirectorySeparatorChar));
+                       string sdk_path = null;
+
+                       foreach (var dir in sdk_directory[RootContext.SdkVersion]) {
+                               sdk_path = Path.Combine (fx_path, dir);
+                               if (Directory.Exists (sdk_path))
+                                       break;
+
+                               sdk_path = null;
+                       }
+
+                       if (sdk_path == null) {
+                               compiler.Report.Warning (-1, 1, "SDK path could not be resolved");
+                       } else {
+                               paths.Add (sdk_path);
+                       }
                }
 
                public Assembly Corlib {
@@ -348,6 +371,9 @@ namespace Mono.CSharp
                                                        }
                                                }
 
+                                               if (Report.DebugFlags > 0)
+                                                       Console.WriteLine ("Loading assembly `{0}'", fileName);
+
                                                loaded_names.Add (Tuple.Create (an, fileName));
                                                return domain.LoadAssembly (module);
                                        }
@@ -397,6 +423,9 @@ namespace Mono.CSharp
                                        continue;
 
                                try {
+                                       if (Report.DebugFlags > 0)
+                                               Console.WriteLine ("Loading default assembly `{0}'", file);
+
                                        var a = domain.LoadFile (file);
                                        if (a != null) {
                                                loaded_names.Add (Tuple.Create (a.GetName (), assembly));
index 3e681d4a226a1f6c5c587a776c1587f61c23fdcc..bd7823db90d39c2d665148a76f67897773dc6f23 100644 (file)
@@ -35,6 +35,12 @@ namespace Mono.CSharp {
                v4
        }
 
+       public enum SdkVersion
+       {
+               v2,
+               v4
+       }
+
        public enum Target
        {
                Library, Exe, Module, WinExe
@@ -58,6 +64,7 @@ namespace Mono.CSharp {
                public static LanguageVersion Version;
                public static bool EnhancedWarnings;
                public static bool LoadDefaultReferences;
+               public static SdkVersion SdkVersion;
 
                //
                // We keep strongname related info here because
@@ -205,6 +212,7 @@ namespace Mono.CSharp {
                        MainClass = null;
                        OutputFile = null;
                        Target = Target.Exe;
+                       SdkVersion = SdkVersion.v2;
                        TargetExt = ".exe";
                        Platform = Platform.AnyCPU;
                        Version = LanguageVersion.Default;