Exemple #1
0
        /// <summary>
        /// Writes out build files
        /// </summary>
        public bool WriteBuildFiles()
        {
            bool success = true;

            Console.WriteLine("Writing build files and inputs");

            Directory.CreateDirectory(m_outputDirectory);

            using (var textWriter = new StreamWriter(Path.Combine(m_outputDirectory, "stats.txt")))
            {
                m_buildGraph.OutputFileStats.Write(textWriter);
                m_buildGraph.SourceFileStats.Write(textWriter);
                m_buildGraph.PipDurationStats.Write(textWriter);
                m_buildGraph.BuildInterval.Write(textWriter);
                m_buildGraph.ProcessPipStats.Write(textWriter);
            }

            // Write out the cache config file
            System.IO.File.WriteAllText(
                Path.Combine(m_outputDirectory, "cacheConfig.json"),
                GetEmbeddedResourceFile("Tool.MimicGenerator.Content.CacheConfig.json"));
            WriteBuildScript();

            var provider = new LanguageProvider(m_language);

            using (var configWriter = provider.CreateConfigWriter(Path.Combine(m_outputDirectory, "mimic")))
            {
                using (var moduleWriter = provider.CreateModuleWriter(m_outputDirectory, "MimicModule", new string[] { "{EngineLayout.DefaultMounts.DeploymentRootPath.Path.Combine('BuildXL.Transformers.Runners.dll')}" }))
                {
                    configWriter.AddModule(moduleWriter);

                    // Write each pip into its spec file
                    using (Timer updateTimer = new Timer(ReportProgress, null, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)))
                    {
                        Parallel.ForEach(m_specFileToPipsLookup, specPips =>
                        {
                            using (var writer = provider.CreateSpecWriter(RemapPath(specPips.Key)))
                            {
                                List <Process> allProcesses = new List <Process>();
                                foreach (var p in specPips)
                                {
                                    Interlocked.Increment(ref m_processesEncountered);

                                    lock (moduleWriter)
                                    {
                                        int lengthToStrip = m_outputDirectory.Length;
                                        if (!(m_outputDirectory.EndsWith(@"/", StringComparison.Ordinal) || m_outputDirectory.EndsWith(@"\", StringComparison.Ordinal)))
                                        {
                                            lengthToStrip++;
                                        }

                                        string specPath = writer.AbsolutePath.Remove(0, lengthToStrip);
                                        moduleWriter.AddSpec(specPath, writer);
                                    }

                                    Process process = p as Process;
                                    if (process != null)
                                    {
                                        allProcesses.Add(process);
                                    }

                                    CopyFile copyFile = p as CopyFile;
                                    if (copyFile != null)
                                    {
                                        bool isDirectory;
                                        bool isResponseFile;
                                        writer.AddCopyFile(
                                            GetProcessOutputName(p.PipId),
                                            GetInputExpression(copyFile.Source, writer, configWriter, out isDirectory, out isResponseFile),
                                            GetOutputExpression(copyFile.Destination, configWriter));
                                        if (isDirectory)
                                        {
                                            throw new MimicGeneratorException("CopyFile shouldn't produce a directory");
                                        }
                                    }

                                    WriteFile writeFile = p as WriteFile;
                                    if (writeFile != null)
                                    {
                                        bool ignore = false;
                                        if (m_ignoreResponseFiles)
                                        {
                                            File f;
                                            if (m_buildGraph.Files.TryGetValue(writeFile.Destination, out f))
                                            {
                                                if (f.Location.EndsWith(ResponseFileName, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    ignore = true;
                                                }
                                            }
                                        }

                                        if (!ignore)
                                        {
                                            writer.AddWriteFile(GetProcessOutputName(p.PipId), GetOutputExpression(writeFile.Destination, configWriter));
                                        }
                                    }

                                    SealDirectory sealDirectory = p as SealDirectory;
                                    if (sealDirectory != null)
                                    {
                                        HandleSealDirectory(sealDirectory, writer, configWriter);
                                    }
                                }

                                HandleProcesses(writer, configWriter, allProcesses);
                            }
                        });

                        success &= WriteQueuedInputFiles();
                    }
                }
            }

            Console.WriteLine("Write {0} input files", m_inputsWritten);
            Console.WriteLine("{0} Input files were using the default size", m_inputsWithDefaultSize);

            return(success);
        }