Пример #1
0
        public void HandleSealDirectory(SealDirectory sealDirectory, SpecWriter writer, ConfigWriter configWriter)
        {
            List <string> remappedContents = new List <string>();
            Dir           dir = m_buildGraph.Directories[sealDirectory.Directory];

            foreach (int content in dir.Contents)
            {
                int producingProcess;
                if (m_buildGraph.OutputArtifactToProducingPip.TryGetValue(content, out producingProcess))
                {
                    var p = m_buildGraph.Pips[producingProcess];
                    remappedContents.Add(writer.GetProcessInputName(GetProcessOutputName(producingProcess), p.Spec,
                                                                    content));
                }
                else
                {
                    remappedContents.Add(configWriter.ToRelativePathExpression(m_buildGraph.Files[content].Location));
                    QueueWritingInputFileIfNecessary(content);
                }
            }

            writer.AddSealDirectory(GetSealOutputName(sealDirectory.Directory), configWriter.ToRelativePathExpression(dir.Location), remappedContents);
        }
Пример #2
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);
        }