Ejemplo n.º 1
0
        public static Build ReadBuild(string filePath)
        {
            var eventSource = new BinaryLogReplayEventSource();

            byte[] sourceArchive = null;

            eventSource.OnBlobRead += (kind, bytes) =>
            {
                if (kind == BinaryLogRecordKind.ProjectImportArchive)
                {
                    sourceArchive = bytes;
                }
            };

            StructuredLogger.SaveLogToDisk = false;
            StructuredLogger.CurrentBuild  = null;
            var structuredLogger = new StructuredLogger();

            structuredLogger.Parameters = "build.buildlog";
            structuredLogger.Initialize(eventSource);

            var sw = Stopwatch.StartNew();

            eventSource.Replay(filePath);
            var elapsed = sw.Elapsed;

            structuredLogger.Shutdown();

            var build = StructuredLogger.CurrentBuild;

            StructuredLogger.CurrentBuild = null;

            if (build == null)
            {
                build = new Build()
                {
                    Succeeded = false
                };
                build.AddChild(new Error()
                {
                    Text = "Error when opening the file: " + filePath
                });
            }

            var projectImportsZip = Path.ChangeExtension(filePath, ".ProjectImports.zip");

            if (sourceArchive == null && File.Exists(projectImportsZip))
            {
                sourceArchive = File.ReadAllBytes(projectImportsZip);
            }

            build.SourceFilesArchive = sourceArchive;
            // build.AddChildAtBeginning(new Message { Text = "Elapsed: " + elapsed.ToString() });

            return(build);
        }
Ejemplo n.º 2
0
        private static (StLogger.Build, IEnumerable <StLogger.Error>) ProcessBuildLog(string tempPath)
        {
            var reader   = new StLogger.BinLogReader();
            var stlogger = new StLogger.StructuredLogger();

            // prevent output temporary file
            StLogger.StructuredLogger.SaveLogToDisk = false;

            // never output, but if not set, throw exception when initializing
            stlogger.Parameters = "tmp.buildlog";
            stlogger.Initialize(reader);
            reader.Replay(Path.Combine(tempPath, "build.binlog"));
            stlogger.Shutdown();
            StLogger.Build buildlog = stlogger.Construction.Build;
            if (buildlog.Succeeded)
            {
                return(buildlog, null);
            }
            else
            {
                IEnumerable <StLogger.Error> errors = FindAllErrors(buildlog);
                return(null, errors);
            }
        }
Ejemplo n.º 3
0
        public static Build ReadBuild(Stream stream, byte[] projectImportsArchive = null)
        {
            var eventSource = new BinaryLogReplayEventSource();

            Build build = null;

            eventSource.OnBlobRead += (kind, bytes) =>
            {
                if (kind == BinaryLogRecordKind.ProjectImportArchive)
                {
                    projectImportsArchive = bytes;
                }
            };
            eventSource.OnException += ex =>
            {
                if (build != null)
                {
                    build.AddChild(new Error()
                    {
                        Text = "Error when reading the file: " + ex.ToString()
                    });
                }
            };

            StructuredLogger.SaveLogToDisk = false;
            StructuredLogger.CurrentBuild  = null;
            var structuredLogger = new StructuredLogger();

            structuredLogger.Parameters = "build.buildlog";
            structuredLogger.Initialize(eventSource);

            build = structuredLogger.Construction.Build;

            var sw = Stopwatch.StartNew();

            eventSource.Replay(stream);
            var elapsed = sw.Elapsed;

            structuredLogger.Shutdown();

            build = StructuredLogger.CurrentBuild;
            StructuredLogger.CurrentBuild = null;

            if (build == null)
            {
                build = new Build()
                {
                    Succeeded = false
                };
                build.AddChild(new Error()
                {
                    Text = "Error when opening the log file."
                });
            }

            if (build.SourceFilesArchive == null && projectImportsArchive != null)
            {
                build.SourceFilesArchive = projectImportsArchive;
            }

            // build.AddChildAtBeginning(new Message { Text = "Elapsed: " + elapsed.ToString() });

            return(build);
        }
Ejemplo n.º 4
0
        public static Build ReadBuild(Stream stream, Progress progress, byte[] projectImportsArchive = null)
        {
            var eventSource = new BinLogReader();

            Build build = null;
            IEnumerable <string> strings = null;

            eventSource.OnBlobRead += (kind, bytes) =>
            {
                if (kind == BinaryLogRecordKind.ProjectImportArchive)
                {
                    projectImportsArchive = bytes;
                }
            };
            eventSource.OnException += ex =>
            {
                if (build != null)
                {
                    build.AddChild(new Error()
                    {
                        Text = "Error when reading the file: " + ex.ToString()
                    });
                }
            };
            eventSource.OnStringDictionaryComplete += s =>
            {
                strings = s;
            };

            StructuredLogger.SaveLogToDisk = false;
            StructuredLogger.CurrentBuild  = null;
            var structuredLogger = new StructuredLogger();

            structuredLogger.Parameters = "build.buildlog";
            structuredLogger.Initialize(eventSource);

            build = structuredLogger.Construction.Build;

            eventSource.OnFileFormatVersionRead += fileFormatVersion =>
            {
                build.FileFormatVersion = fileFormatVersion;

                // strings are deduplicated starting with version 10
                if (fileFormatVersion >= 10)
                {
                    build.StringTable.NormalizeLineEndings   = false;
                    build.StringTable.HasDeduplicatedStrings = true;
                    if (ReuseBinlogStrings)
                    {
                        build.StringTable.DisableDeduplication = true;
                    }
                }
            };

            var sw = Stopwatch.StartNew();

            eventSource.Replay(stream, progress);

            var elapsed = sw.Elapsed;

            if (strings != null)
            {
                if (ReuseBinlogStrings)
                {
                    // since strings are already deduplicated in the file, no need to do it again
                    build.StringTable.SetStrings(strings);
                }
                else
                {
                    // intern all strings in one fell swoop here instead of interning multiple times
                    // one by one when processing task parameters
                    build.StringTable.Intern(strings);
                }
            }

            structuredLogger.Shutdown();

            build = StructuredLogger.CurrentBuild;
            StructuredLogger.CurrentBuild = null;

            if (build == null)
            {
                build = new Build()
                {
                    Succeeded = false
                };
                build.AddChild(new Error()
                {
                    Text = "Error when opening the log file."
                });
            }

            if (build.SourceFilesArchive == null && projectImportsArchive != null)
            {
                build.SourceFilesArchive = projectImportsArchive;
            }

            // strings = build.StringTable.Instances.OrderBy(s => s).ToArray();

            // Serialization.WriteStringsToFile(@"C:\temp\1.txt", strings.ToArray());

            return(build);
        }
Ejemplo n.º 5
0
        public static Build ReadBuild(Stream stream, byte[] projectImportsArchive = null)
        {
            var eventSource = new BinLogReader();

            Build build = null;

            eventSource.OnBlobRead += (kind, bytes) =>
            {
                if (kind == BinaryLogRecordKind.ProjectImportArchive)
                {
                    projectImportsArchive = bytes;
                }
            };
            eventSource.OnException += ex =>
            {
                if (build != null)
                {
                    build.AddChild(new Error()
                    {
                        Text = "Error when reading the file: " + ex.ToString()
                    });
                }
            };

            StructuredLogger.SaveLogToDisk = false;
            StructuredLogger.CurrentBuild  = null;
            var structuredLogger = new StructuredLogger();

            structuredLogger.Parameters = "build.buildlog";
            structuredLogger.Initialize(eventSource);

            eventSource.OnFileFormatVersionRead += fileFormatVersion =>
            {
                if (fileFormatVersion >= 10)
                {
                    // since strings are already deduplicated in the file, no need to do it again
                    // TODO: but search will not work if the string table is empty
                    // structuredLogger.Construction.StringTable.DisableDeduplication = true;
                }
            };

            build = structuredLogger.Construction.Build;

            var sw = Stopwatch.StartNew();

            eventSource.Replay(stream);
            var elapsed = sw.Elapsed;

            structuredLogger.Shutdown();

            build = StructuredLogger.CurrentBuild;
            StructuredLogger.CurrentBuild = null;

            if (build == null)
            {
                build = new Build()
                {
                    Succeeded = false
                };
                build.AddChild(new Error()
                {
                    Text = "Error when opening the log file."
                });
            }

            if (build.SourceFilesArchive == null && projectImportsArchive != null)
            {
                build.SourceFilesArchive = projectImportsArchive;
            }

            // build.AddChildAtBeginning(new Message { Text = "Elapsed: " + elapsed.ToString() });

            return(build);
        }