Skip to content

Commit

Permalink
Embed the project imports archive directly in the structured .buildlo…
Browse files Browse the repository at this point in the history
…g file.
  • Loading branch information
KirillOsenkov committed Jun 17, 2017
1 parent 19d71d3 commit 4157ac9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/StructuredLogger/Serialization/Binary/BinaryLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class BinaryLogReader : IDisposable
private readonly Queue<string> attributes = new Queue<string>(10);

private readonly bool formatSupportsSourceFiles;
private readonly bool formatSupportsEmbeddedProjectImportsArchive;

public static Build Read(string filePath)
{
Expand All @@ -25,7 +26,7 @@ public static Build Read(string filePath)
}

var projectImportsZip = Path.ChangeExtension(filePath, ".ProjectImports.zip");
if (File.Exists(projectImportsZip))
if (build.SourceFilesArchive == null && File.Exists(projectImportsZip))
{
build.SourceFilesArchive = File.ReadAllBytes(projectImportsZip);
}
Expand All @@ -39,6 +40,7 @@ private BinaryLogReader(string filePath)
this.filePath = filePath;
this.reader = new TreeBinaryReader(filePath);
this.formatSupportsSourceFiles = reader.Version > new Version(1, 0, 130);
this.formatSupportsEmbeddedProjectImportsArchive = reader.Version > new Version(1, 1, 87);
}

private object ReadNode()
Expand All @@ -64,6 +66,11 @@ private object ReadNode()
}
}

if (node is Build build && formatSupportsEmbeddedProjectImportsArchive)
{
build.SourceFilesArchive = reader.ReadByteArray();
}

return node;
}

Expand Down
5 changes: 5 additions & 0 deletions src/StructuredLogger/Serialization/Binary/BinaryLogWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ private void WriteNode(object node)
WriteAttributes(node);
writer.WriteEndAttributes();
WriteChildren(node);

if (node is Build build)
{
writer.WriteByteArray(build.SourceFilesArchive);
}
}

private void WriteChildren(object node)
Expand Down
11 changes: 11 additions & 0 deletions src/StructuredLogger/Serialization/Binary/TreeBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public TreeBinaryReader(string filePath)

public string[] StringTable => stringTable;

public byte[] ReadByteArray()
{
int length = binaryReader.ReadInt32();
if (length > 0)
{
return binaryReader.ReadBytes(length);
}

return null;
}

public void ReadStringArray(Queue<string> array)
{
array.Clear();
Expand Down
10 changes: 10 additions & 0 deletions src/StructuredLogger/Serialization/Binary/TreeBinaryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ private void WriteStringTable()
}
}

public void WriteByteArray(byte[] bytes)
{
bytes = bytes ?? Array.Empty<byte>();
treeNodesStreamBinaryWriter.Write(bytes.Length);
if (bytes.Length > 0)
{
treeNodesStreamBinaryWriter.Write(bytes);
}
}

private Stream DestinationStream => gzipStream;

public void Dispose()
Expand Down

0 comments on commit 4157ac9

Please sign in to comment.