Пример #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
 public void AddIncludeResolver()
 {
     _includeResolver = this;
 }
Пример #3
0
 public void AddIncludeResolver()
 {
     _includeResolver = this;
 }
Пример #4
0
        public static ICompilationUnitBuilder AddStreamResolver(this ICompilationUnitBuilder compilationUnitBuilder, IStreamSourceResolver streamSourceResolver)
        {
            compilationUnitBuilder.Options.IncludeResolver = streamSourceResolver;

            return(compilationUnitBuilder);
        }