예제 #1
0
        void Parse(IEnumerable <string> commandLine)
        {
            var noLogo = false;

            var args = ExpandResponseFiles(commandLine.Select(s => StripQuotes(s)));

            AddDefaultResponseFile(args);
            foreach (var arg in args)
            {
                if ("-" == arg)
                {
                    _options.Input.Add(new StringInput("<stdin>", Consume(Console.In)));
                    continue;
                }
                if (!IsFlag(arg))
                {
                    _options.Input.Add(new FileInput(StripQuotes(arg)));
                    continue;
                }
                if ("-utf8" == arg)
                {
                    continue;
                }

                switch (arg[1])
                {
                case 'h':
                {
                    if (arg == "-help" || arg == "-h")
                    {
                        Help();
                    }
                    break;
                }

                case 'w':
                {
                    if (arg == "-wsa")
                    {
                        _options.WhiteSpaceAgnostic = true;
                    }
                    else if (arg == "-warnaserror")
                    {
                        _options.WarnAsError = true;
                    }
                    else if (arg.StartsWith("-warnaserror:"))
                    {
                        string warnings = ValueOf(arg);
                        foreach (string warning in warnings.Split(','))
                        {
                            _options.EnableWarningAsError(warning);
                        }
                    }
                    else if (arg.StartsWith("-warn:"))
                    {
                        var warnings = ValueOf(arg);
                        foreach (string warning in warnings.Split(','))
                        {
                            _options.EnableWarning(warning);
                        }
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                case 'v':
                {
                    _options.TraceLevel = TraceLevel.Warning;
                    if (arg.Length > 2)
                    {
                        switch (arg.Substring(1))
                        {
                        case "vv":
                        {
                            _options.TraceLevel = TraceLevel.Info;
                            MonitorAppDomain();
                            break;
                        }

                        case "vvv":
                        {
                            _options.TraceLevel = TraceLevel.Verbose;
                            break;
                        }
                        }
                    }
                    else
                    {
                        _options.TraceLevel = TraceLevel.Warning;
                    }
                    break;
                }

                case 'r':
                {
                    if (arg.IndexOf(":") > 2 && arg.Substring(1, 9) != "reference")
                    {
                        switch (arg.Substring(1, 8))
                        {
                        case "resource":
                        {
                            AddResource(ValueOf(arg));
                            break;
                        }

                        default:
                        {
                            InvalidOption(arg);
                            break;
                        }
                        }
                    }
                    else
                    {
                        var assemblies = ValueOf(arg);
                        foreach (var assemblyName in assemblies.Split(','))
                        {
                            _references.Add(assemblyName);
                        }
                    }
                    break;
                }

                case 'l':
                {
                    switch (arg.Substring(1, 3))
                    {
                    case "lib":
                    {
                        ParseLib(arg);
                        break;
                    }

                    default:
                    {
                        InvalidOption(arg);
                        break;
                    }
                    }
                    break;
                }

                case 'n':
                {
                    if (arg == "-nologo")
                    {
                        noLogo = true;
                    }
                    else if (arg == "-noconfig")
                    {
                        _noConfig = true;
                    }
                    else if (arg == "-nostdlib")
                    {
                        _options.StdLib = false;
                    }
                    else if (arg == "-nowarn")
                    {
                        _options.NoWarn = true;
                    }
                    else if (arg.StartsWith("-nowarn:"))
                    {
                        string warnings = ValueOf(arg);
                        foreach (string warning in warnings.Split(','))
                        {
                            _options.DisableWarning(warning);
                        }
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                case 'o':
                {
                    _options.OutputAssembly = ValueOf(arg);
                    break;
                }

                case 't':
                {
                    string targetType = ValueOf(arg);
                    switch (targetType)
                    {
                    case "library":
                    {
                        _options.OutputType = CompilerOutputType.Library;
                        break;
                    }

                    case "exe":
                    {
                        _options.OutputType = CompilerOutputType.ConsoleApplication;
                        break;
                    }

                    case "winexe":
                    {
                        _options.OutputType = CompilerOutputType.WindowsApplication;
                        break;
                    }

                    default:
                    {
                        InvalidOption(arg);
                        break;
                    }
                    }
                    break;
                }

                case 'p':
                {
                    if (arg.StartsWith("-pkg:"))
                    {
                        string packages = ValueOf(arg);
                        _packages.Add(packages);
                    }
                    else if (arg.StartsWith("-platform:"))
                    {
                        string arch = ValueOf(arg).ToLowerInvariant();
                        switch (arch)
                        {
                        case "anycpu":
                            break;

                        case "x86":
                            _options.Platform = "x86";
                            break;

                        case "x64":
                            _options.Platform = "x64";
                            break;

                        case "itanium":
                            _options.Platform = "itanium";
                            break;

                        default:
                            InvalidOption(arg, "Valid platform types are: `anycpu', `x86', `x64' or `itanium'.");
                            break;
                        }
                    }
                    else if (arg.StartsWith("-p:"))
                    {
                        _pipelineName = StripQuotes(arg.Substring(3));
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                case 'c':
                {
                    switch (arg.Substring(1))
                    {
                    case "checked":
                    case "checked+":
                    {
                        _options.Checked = true;
                        break;
                    }

                    case "checked-":
                    {
                        _options.Checked = false;
                        break;
                    }

                    default:
                    {
                        string culture = arg.Substring(3);
                        Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(culture);
                        break;
                    }
                    }
                    break;
                }

                case 's':
                {
                    switch (arg.Substring(1, 6))
                    {
                    case "srcdir":
                    {
                        string path = StripQuotes(arg.Substring(8));
                        AddFilesForPath(path, _options);
                        break;
                    }

                    case "strict-":
                        break;

                    case "strict":
                    case "strict+":
                    {
                        _options.Strict = true;
                        break;
                    }

                    default:
                    {
                        InvalidOption(arg);
                        break;
                    }
                    }
                    break;
                }

                case 'k':
                {
                    if (arg.Substring(1, 7) == "keyfile")
                    {
                        _options.KeyFile = StripQuotes(arg.Substring(9));
                    }
                    else if (arg.Substring(1, 12) == "keycontainer")
                    {
                        _options.KeyContainer = StripQuotes(arg.Substring(14));
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                case 'd':
                {
                    switch (arg.Substring(1))
                    {
                    case "debug":
                    case "debug+":
                    {
                        _options.Debug = true;
                        break;
                    }

                    case "debug-":
                    {
                        _options.Debug = false;
                        break;
                    }

                    case "ducky":
                    {
                        _options.Ducky = true;
                        break;
                    }

                    case "debug-steps":
                    {
                        _debugSteps = true;
                        break;
                    }

                    case "delaysign":
                    {
                        _options.DelaySign = true;
                        break;
                    }

                    default:
                    {
                        if (arg.StartsWith("-d:") || arg.StartsWith("-define:"))
                        {
                            string[] symbols = ValueOf(arg).Split(",".ToCharArray());
                            foreach (string symbol in symbols)
                            {
                                string[] s_v = symbol.Split("=".ToCharArray(), 2);
                                if (s_v[0].Length < 1)
                                {
                                    continue;
                                }
                                if (_options.Defines.ContainsKey(s_v[0]))
                                {
                                    _options.Defines[s_v[0]] = (s_v.Length > 1) ? s_v[1] : null;
                                    TraceInfo("REPLACED DEFINE '" + s_v[0] + "' WITH VALUE '" + ((s_v.Length > 1) ? s_v[1] : string.Empty) + "'");
                                }
                                else
                                {
                                    _options.Defines.Add(s_v[0], (s_v.Length > 1) ? s_v[1] : null);
                                    TraceInfo("ADDED DEFINE '" + s_v[0] + "' WITH VALUE '" + ((s_v.Length > 1) ? s_v[1] : string.Empty) + "'");
                                }
                            }
                        }
                        else
                        {
                            InvalidOption(arg);
                        }
                        break;
                    }
                    }
                    break;
                }

                case 'e':
                {
                    switch (arg.Substring(1, 8))
                    {
                    case "embedres":
                    {
                        EmbedResource(ValueOf(arg));
                        break;
                    }

                    default:
                    {
                        InvalidOption(arg);
                        break;
                    }
                    }
                    break;
                }

                case 'u':
                {
                    if (arg == "-unsafe")
                    {
                        _options.Unsafe = true;
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                case 'x':
                {
                    if (arg.Substring(1).StartsWith("x-type-inference-rule-attribute"))
                    {
                        var attribute = ValueOf(arg);
                        _options.Environment = new DeferredEnvironment {
                            { typeof(TypeInferenceRuleProvider), () => new CustomTypeInferenceRuleProvider(attribute) }
                        };
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }

                default:
                {
                    if (arg == "--help")
                    {
                        Help();
                    }
                    else
                    {
                        InvalidOption(arg);
                    }
                    break;
                }
                }
            }

            if (!noLogo)
            {
                DoLogo();
            }
        }