Skip to content

Commit

Permalink
Support project files for command targets (#56)
Browse files Browse the repository at this point in the history
* really basic build support

* more fixup

* More
  • Loading branch information
jaredpar authored Sep 1, 2023
1 parent 7004226 commit 6e7e0b6
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Basic.CompilerLog/bin/Debug/net7.0/Basic.CompilerLog.dll",
"args": [],
"args": ["rsp", "c:\\users\\jaredpar\\temp\\console\\console.csproj"],
"cwd": "${workspaceFolder}/src/Basic.CompilerLog",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
Expand Down
44 changes: 42 additions & 2 deletions src/Basic.CompilerLog.UnitTests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if NETCOREAPP
using Basic.CompilerLog.Util;
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -49,6 +50,45 @@ public void Create(string extra, string fileName)
Assert.True(File.Exists(complogPath));
}

[Fact]
public void CreateProjectFile()
{
RunDotNet("new console --name console -o .");
Assert.Equal(0, RunCompLog($"create console.csproj -o msbuild.complog"));
var complogPath = Path.Combine(RootDirectory, "msbuild.complog");
using var reader = CompilerLogReader.Create(complogPath, BasicAnalyzerHostOptions.None);
Assert.Single(reader.ReadAllCompilerCalls());
}

/// <summary>
/// Explicit build target overrides the implicit -t:Rebuild
/// </summary>
[Fact]
public void CreateNoopBuild()
{
RunDotNet("new console --name console -o .");
RunDotNet("build");
Assert.Equal(0, RunCompLog($"create console.csproj -o msbuild.complog -- -t:Build"));
var complogPath = Path.Combine(RootDirectory, "msbuild.complog");
using var reader = CompilerLogReader.Create(complogPath, BasicAnalyzerHostOptions.None);
Assert.Empty(reader.ReadAllCompilerCalls());
}

[Theory]
[InlineData("console.sln")]
[InlineData("console.csproj")]
[InlineData("")]
public void CreateSolution(string target)
{
RunDotNet("new console --name console -o .");
RunDotNet("new sln --name console");
RunDotNet("sln add console.csproj");
Assert.Equal(0, RunCompLog($"create {target} -o msbuild.complog"));
var complogPath = Path.Combine(RootDirectory, "msbuild.complog");
using var reader = CompilerLogReader.Create(complogPath, BasicAnalyzerHostOptions.None);
Assert.Single(reader.ReadAllCompilerCalls());
}

[Fact]
public void CreateFullPath()
{
Expand All @@ -62,7 +102,7 @@ public void CreateFullPath()
[Fact]
public void References()
{
Assert.Equal(0, RunCompLog($"ref -o {RootDirectory} {Path.Combine(Fixture.ComplogDirectory, "console.complog")}"));
Assert.Equal(0, RunCompLog($"ref -o {RootDirectory} {Fixture.ConsoleComplogPath.Value}"));
Assert.NotEmpty(Directory.EnumerateFiles(Path.Combine(RootDirectory, "console", "refs"), "*.dll"));
Assert.NotEmpty(Directory.EnumerateFiles(Path.Combine(RootDirectory, "console", "analyzers"), "*.dll", SearchOption.AllDirectories));
}
Expand Down Expand Up @@ -90,7 +130,7 @@ public void ExportHelloWorld(string template)
public void EmitConsole(string arg)
{
using var emitDir = new TempDir();
RunCompLog($"emit {arg} -o {emitDir.DirectoryPath} {Fixture.ConsoleComplogPath}");
RunCompLog($"emit {arg} -o {emitDir.DirectoryPath} {Fixture.ConsoleComplogPath.Value}");

AssertOutput(@"console\emit\console.dll");
AssertOutput(@"console\emit\console.pdb");
Expand Down
2 changes: 1 addition & 1 deletion src/Basic.CompilerLog/FilterOptionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class FilterOptionSet : OptionSet

internal FilterOptionSet(bool includeNoneHost = false)
{
Add("include", "include all compilation kinds", i => { if (i != null) IncludeAllKinds = true; });
Add("include", "include all compilation kinds", i => { if (i is not null) IncludeAllKinds = true; });
Add("targetframework=", "", TargetFrameworks.Add, hidden: true);
Add("framework=", "include only compilations for the target framework (allows multiple)", TargetFrameworks.Add);
Add("n|projectName=", "include only compilations with the project name", (string n) => ProjectName = n);
Expand Down
Loading

0 comments on commit 6e7e0b6

Please sign in to comment.