Пример #1
0
        private void CompileToResponse(TemporaryDirectory td, TempFileCollection tfc, List <string> files, Stack <IIntermediateProject> partialCompletions, Dictionary <IIntermediateModule, List <string> > moduleFiles, out IIntermediateCompilerCommandLineModule module, out List <string> commandSequences, out string response)
        {
            module           = (IIntermediateCompilerCommandLineModule)this.Module;
            commandSequences = new List <string>();
            if (this.Project.OutputType == ProjectOutputType.ConsoleApplication || this.Project.OutputType == ProjectOutputType.WindowsApplication)
            {
                IMethodMember entryPoint = Project.EntryPoint;
                if (entryPoint != null && ((IDeclaredType)entryPoint.ParentTarget).Module != Project.RootModule)
                {
                    IClassType entryPointCover = Project.Partials.AddNew().DefaultNameSpace.Classes.AddNew(Project.Classes.GetUniqueName("_cover"));

                    entryPointCover.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    entryPointCover.IsStatic    = true;
                    entryPointCover.AccessLevel = DeclarationAccessLevel.Internal;
                    entryPointCover.Module      = Project.RootModule;
                    IMethodMember coverPoint = entryPointCover.Methods.AddNew(new TypedName(entryPoint.Name, entryPoint.ReturnType));
                    coverPoint.Attributes.AddNew(typeof(CompilerGeneratedAttribute));
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        coverPoint.Parameters.AddNew(new TypedName(impm.Name, impm.ParameterType));
                    }

                    coverPoint.Summary = "Entrypoint cover method, invokes the true entrypoint in a different module.";
                    IMethodInvokeExpression imie = entryPoint.GetReference().Invoke();
                    foreach (IMethodParameterMember impm in entryPoint.Parameters.Values)
                    {
                        imie.ArgumentExpressions.Add(impm.GetReference());
                    }
                    if (!(coverPoint.ReturnType.Equals(typeof(void).GetTypeReference())))
                    {
                        coverPoint.Return(imie);
                    }
                    else
                    {
                        coverPoint.CallMethod(imie);
                    }
                    string entryFile = ProjectTranslator.WriteFile(this.Project, this.Translator, td, tfc, partialCompletions, entryPointCover, ".cs", "    ");
                    moduleFiles[Project.RootModule].Add(entryFile);
                    files.Add(entryFile);
                    commandSequences.Add(module.GetEntryPointCommand(coverPoint, this.Options));
                    this.Project.Partials.Remove((IIntermediateProject)entryPointCover.ParentTarget.ParentTarget);
                }
                else
                {
                    commandSequences.Add(module.GetEntryPointCommand(entryPoint, this.Options));
                }
            }
            List <string> moduleCommandLines = new List <string>();

            foreach (IIntermediateModule iim in this.Project.Modules.Values)
            {
                string[] moduleFileNames = new string[moduleFiles[iim].Count + (iim == this.Project.RootModule ? this.Options.ExtraFiles.Count() : 0)];
                for (int i = 0; i < moduleFiles[iim].Count; i++)
                {
                    moduleFileNames[i] = moduleFiles[iim][i];
                }
                if (iim == this.Project.RootModule)
                {
                    int exC   = this.Options.ExtraFiles.Count();
                    int exO   = moduleFiles[iim].Count;
                    int index = exO;
                    foreach (var extraFile in this.Options.ExtraFiles)
                    {
                        var tempFile = td.Directories.GetTemporaryDirectory(iim.Name).Files.GetTemporaryFile(Path.GetFileName(extraFile));
                        tempFile.CloseStream();
                        File.Copy(extraFile, tempFile.FileName, true);
                        moduleFileNames[index++] = tempFile.FileName;
                    }
                }
                moduleCommandLines.AddRange(module.GetModuleCommand(iim, moduleFileNames, null, this.Options));
            }
            bool allowPartials = this.Translator.Options.AllowPartials;

            this.Translator.Options.AllowPartials = false;
            ProjectDependencyReport pdr = new ProjectDependencyReport(this.Project, this.Translator.Options);

            pdr.Begin();
            this.Translator.Options.AllowPartials = allowPartials;
            if (module.Supports(CompilerModuleSupportFlags.Optimization))
            {
                commandSequences.Add(module.GetOptimizationCommand(this.Options.Optimize, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.DebuggerSupport))
            {
                commandSequences.Add(module.GetDebugCommand(this.Options.DebugSupport, this.Options));
            }
            if (module.Supports(CompilerModuleSupportFlags.XMLDocumentation))
            {
                commandSequences.Add(module.GetXMLDocumentationCommand(this.Options.GenerateXMLDocs, this.Options));
            }
            commandSequences.AddRange(module.GetReferencesCommand(Tweaks.TranslateArray(pdr.CompiledAssemblyReferences.ToArray(), a =>
            {
                return(a.Location);
            }), this.Options));
            if (module.Supports(CompilerModuleSupportFlags.MultiFileAssemblies))
            {
                commandSequences.AddRange(moduleCommandLines.ToArray());
            }
            else
            {
                commandSequences.Add(module.GetOutputCommand(this.Options.Target, this.Options));
                commandSequences.AddRange(module.GetSourcesCommand(files.ToArray(), this.Options));
            }
            response = null;
            if (module.Supports(CompilerModuleSupportFlags.ResponseFile))
            {
                response = tfc.AddExtension("response");
                StreamWriter responseWriter = new StreamWriter(new FileStream(response, FileMode.Create));
                //string[] lines = fullCommand.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in commandSequences)
                {
                    responseWriter.WriteLine(s);
                }
                responseWriter.Flush();
                responseWriter.Close();
            }
        }