Skip to content

Commit

Permalink
Fix (#57)
Browse files Browse the repository at this point in the history
* Simple workspace

* Bug fixes
  • Loading branch information
jaredpar authored Sep 14, 2023
1 parent 6e7e0b6 commit 64e22fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Compiler Logs
Compiler Logs
===

This is the repository for creating and consuming compiler log files. These are files created from a [MSBuild binary log](https://github.com/KirillOsenkov/MSBuildStructuredLog) that contain information necessary to recreate all of the [Compilation](https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.compilation?view=roslyn-dotnet-4.2.0) instances from that build.

Expand Down
Empty file added doc/Capturing Compiler Logs.md
Empty file.
15 changes: 13 additions & 2 deletions src/Basic.CompilerLog.UnitTests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -92,13 +93,23 @@ public void CreateSolution(string target)
[Fact]
public void CreateFullPath()
{
using var exportDir = new TempDir();

RunDotNet($"new console --name example --output .");
RunDotNet("build -bl");
Assert.Equal(0, RunCompLog($"create {GetBinaryLogFullPath()}", RootDirectory));
}

/// <summary>
/// Don't search for complogs when an explicit log source isn't provided.
/// </summary>
[Fact]
public void CreateOtherComplogExists()
{
RunDotNet($"new console --name example --output .");
RunDotNet("build -bl");
Root.NewFile("other.complog", "");
Assert.Equal(0, RunCompLog($"create", RootDirectory));
}

[Fact]
public void References()
{
Expand Down
15 changes: 8 additions & 7 deletions src/Basic.CompilerLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ int RunCreate(IEnumerable<string> args)
return ExitFailure;
}

// todo use the standard get or build code
string binlogFilePath = GetLogFilePath(extra);
string binlogFilePath = GetLogFilePath(extra, includeCompilerLogs: false);
if (PathUtil.Comparer.Equals(".complog", Path.GetExtension(binlogFilePath)))
{
WriteLine($"Already a .complog file: {binlogFilePath}");
Expand Down Expand Up @@ -565,15 +564,15 @@ Stream GetOrCreateCompilerLogStream(List<string> extra)
/// <summary>
/// Returns a path to a .complog or .binlog to be used for processing
/// </summary>
string GetLogFilePath(List<string> extra)
string GetLogFilePath(List<string> extra, bool includeCompilerLogs = true)
{
string? logFilePath;
IEnumerable<string> args = Array.Empty<string>();
string baseDirectory = CurrentDirectory;
var printFile = false;
if (extra.Count == 0)
{
logFilePath = FindLogFilePath(baseDirectory);
logFilePath = FindLogFilePath(baseDirectory, includeCompilerLogs);
printFile = true;
}
else
Expand All @@ -583,7 +582,7 @@ string GetLogFilePath(List<string> extra)
if (string.IsNullOrEmpty(Path.GetExtension(logFilePath)))
{
baseDirectory = logFilePath;
logFilePath = FindLogFilePath(baseDirectory);
logFilePath = FindLogFilePath(baseDirectory, includeCompilerLogs);
printFile = true;
}
}
Expand Down Expand Up @@ -617,8 +616,10 @@ string GetLogFilePath(List<string> extra)
throw new OptionException($"Not a valid log file {logFilePath}", "log");
}

static string? FindLogFilePath(string baseDirectory) =>
FindFirstFileWithPattern(baseDirectory, "*.complog", "*.binlog", "*.sln", "*.csproj", ".vbproj");
static string? FindLogFilePath(string baseDirectory, bool includeCompilerLogs = true ) =>
includeCompilerLogs
? FindFirstFileWithPattern(baseDirectory, "*.complog", "*.binlog", "*.sln", "*.csproj", ".vbproj")
: FindFirstFileWithPattern(baseDirectory, "*.binlog", "*.sln", "*.csproj", ".vbproj");

static string GetLogFilePathAfterBuild(string baseDirectory, string? buildFileName, IEnumerable<string> buildArgs)
{
Expand Down

0 comments on commit 64e22fc

Please sign in to comment.