예제 #1
0
        private static CompilerOptions CreateCompilerOptions(CommandLine commandLine)
        {
            List <string>        references       = new List <string>();
            List <IStreamSource> sources          = new List <IStreamSource>();
            List <IStreamSource> resources        = new List <IStreamSource>();
            List <string>        defines          = new List <string>();
            List <string>        scripts          = new List <string>();
            bool                  debug           = false;
            bool                  includeTests    = false;
            bool                  minimize        = true;
            IStreamSource         scriptFile      = null;
            IStreamSourceResolver includeResolver = null;

            foreach (string fileName in commandLine.Arguments)
            {
                // TODO: This is a hack... something in the .net 4 build system causes
                //       generation of an AssemblyAttributes.cs file with fully-qualified
                //       type names, that we can't handle (this comes from multitargeting),
                //       and there doesn't seem like a way to turn it off.
                if (fileName.EndsWith(".AssemblyAttributes.cs", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                sources.Add(new FileInputStreamSource(fileName));
            }

            object referencesObject = commandLine.Options["ref"];

            if (referencesObject is string)
            {
                references.Add((string)referencesObject);
            }
            else if (referencesObject is ArrayList)
            {
                ArrayList referenceList = (ArrayList)referencesObject;

                foreach (string reference in referenceList)
                {
                    // TODO: This is a hack... something in the .net 4 build system causes
                    //       System.Core.dll to get included [sometimes].
                    //       That shouldn't happen... so filter it out here.
                    if (reference.EndsWith("System.Core.dll", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    references.Add(reference);
                }
            }

            object resourcesObject = commandLine.Options["res"];

            if (resourcesObject is string)
            {
                resources.Add(new FileInputStreamSource((string)resourcesObject));
            }
            else if (resourcesObject is ArrayList)
            {
                ArrayList resourceList = (ArrayList)resourcesObject;

                foreach (string resource in resourceList)
                {
                    resources.Add(new FileInputStreamSource(resource));
                }
            }

            object definesObject = commandLine.Options["D"];

            if (definesObject is string)
            {
                defines.Add((string)definesObject);
            }
            else if (definesObject is ArrayList)
            {
                ArrayList definesList = (ArrayList)definesObject;

                foreach (string definedVariable in definesList)
                {
                    defines.Add(definedVariable);
                }
            }

            string scriptFilePath = null;

            if (commandLine.Options.Contains("out"))
            {
                scriptFilePath = (string)commandLine.Options["out"];
                if (scriptFilePath.IndexOfAny(Path.GetInvalidPathChars()) < 0)
                {
                    scriptFile = new FileOutputStreamSource(scriptFilePath);
                }
            }

            debug = commandLine.Options.Contains("debug");
            if (debug && !defines.Contains("DEBUG"))
            {
                defines.Add("DEBUG");
            }

            includeTests = commandLine.Options.Contains("tests");
            minimize     = commandLine.Options.Contains("minimize");

            if (commandLine.Options.Contains("inc"))
            {
                string basePath = (string)commandLine.Options["inc"];
                includeResolver = new IncludeResolver(basePath);
            }

            CompilerOptions compilerOptions = new CompilerOptions();

            compilerOptions.IncludeTests    = includeTests;
            compilerOptions.Defines         = defines;
            compilerOptions.Minimize        = minimize;
            compilerOptions.References      = references;
            compilerOptions.Sources         = sources;
            compilerOptions.Resources       = resources;
            compilerOptions.ScriptFile      = scriptFile;
            compilerOptions.IncludeResolver = includeResolver;

            compilerOptions.InternalTestMode = commandLine.Options.Contains("test");
            if (compilerOptions.InternalTestMode)
            {
                compilerOptions.InternalTestType = (string)commandLine.Options["test"];
            }

            return(compilerOptions);
        }
예제 #2
0
        private static CompilerOptions CreateCompilerOptions(CommandLine commandLine)
        {
            List<string> references = new List<string>();
            List<IStreamSource> sources = new List<IStreamSource>();
            List<IStreamSource> resources = new List<IStreamSource>();
            List<string> defines = new List<string>();
            List<string> scripts = new List<string>();
            bool debug = false;
            bool includeTests = false;
            bool minimize = true;
            bool copyRefs = false;
            IStreamSource scriptFile = null;
            IStreamSource templateFile = null;
            IStreamSource docCommentFile = null;

            foreach (string fileName in commandLine.Arguments) {
                // TODO: This is a hack... something in the .net 4 build system causes
                //       generation of an AssemblyAttributes.cs file with fully-qualified
                //       type names, that we can't handle (this comes from multitargeting),
                //       and there doesn't seem like a way to turn it off.
                if (fileName.EndsWith(".AssemblyAttributes.cs", StringComparison.OrdinalIgnoreCase)) {
                    continue;
                }
                sources.Add(new FileInputStreamSource(fileName));
            }

            object referencesObject = commandLine.Options["ref"];
            if (referencesObject is string) {
                references.Add((string)referencesObject);
            }
            else if (referencesObject is ArrayList) {
                ArrayList referenceList = (ArrayList)referencesObject;

                foreach (string reference in referenceList) {
                    // TODO: This is a hack... something in the .net 4 build system causes
                    //       System.Core.dll to get included [sometimes].
                    //       That shouldn't happen... so filter it out here.
                    if (reference.EndsWith("System.Core.dll", StringComparison.OrdinalIgnoreCase)) {
                        continue;
                    }
                    references.Add(reference);
                }
            }

            object resourcesObject = commandLine.Options["res"];
            if (resourcesObject is string) {
                resources.Add(new FileInputStreamSource((string)resourcesObject));
            }
            else if (resourcesObject is ArrayList) {
                ArrayList resourceList = (ArrayList)resourcesObject;

                foreach (string resource in resourceList) {
                    resources.Add(new FileInputStreamSource(resource));
                }
            }

            object definesObject = commandLine.Options["D"];
            if (definesObject is string) {
                defines.Add((string)definesObject);
            }
            else if (definesObject is ArrayList) {
                ArrayList definesList = (ArrayList)definesObject;

                foreach (string definedVariable in definesList) {
                    defines.Add(definedVariable);
                }
            }

            string scriptFilePath = null;
            if (commandLine.Options.Contains("out")) {
                scriptFilePath = (string)commandLine.Options["out"];
                if (scriptFilePath.IndexOfAny(Path.GetInvalidPathChars()) < 0) {
                    scriptFile = new FileOutputStreamSource(scriptFilePath);
                }
            }

            if (commandLine.Options.Contains("template")) {
                templateFile = new FileInputStreamSource((string)commandLine.Options["template"], "Template");
            }

            if (commandLine.Options.Contains("doc")) {
                docCommentFile = new FileInputStreamSource((string)commandLine.Options["doc"], "DocComment");
            }

            debug = commandLine.Options.Contains("debug");
            if (debug && !defines.Contains("DEBUG")) {
                defines.Add("DEBUG");
            }

            includeTests = commandLine.Options.Contains("tests");
            minimize = commandLine.Options.Contains("minimize");
            copyRefs = commandLine.Options.Contains("copyRefs");

            CompilerOptions compilerOptions = new CompilerOptions();
            compilerOptions.DebugFlavor = debug;
            compilerOptions.IncludeTests = includeTests;
            compilerOptions.Defines = defines;
            compilerOptions.Minimize = minimize;
            compilerOptions.References = references;
            compilerOptions.Sources = sources;
            compilerOptions.Resources = resources;
            compilerOptions.ScriptFile = scriptFile;
            compilerOptions.TemplateFile = templateFile;
            compilerOptions.DocCommentFile = docCommentFile;
            compilerOptions.CopyReferences = copyRefs;

            compilerOptions.InternalTestMode = commandLine.Options.Contains("test");
            if (compilerOptions.InternalTestMode) {
                compilerOptions.InternalTestType = (string)commandLine.Options["test"];
            }

            return compilerOptions;
        }