Open Raikovm opened 1 year ago
This should be fairly easy to fix:
The fix would be to always emit Unit-style arguments.
I've tried changing the paths to Unix-style in the variables stored in cake file, yet the issue is not resolved. Can you explain what approach is "dotCover on Linux only supports Unix-style arguments", you are referring here.
Is DotCover supports Linux distribution. From the Jetbrains official site for DotCover download under system requirements I can only see Windows machine. Is this also same for CLI, if that so it wouldn't support in Linux distributions right ?
I've also searched for any alternatives to dotCover to run in linux env, but I couldn't find any. Is there any alternative present to run in Linux OS.
I'm not changing to change the paths, I'm saying that Cake should pass Unix-style arguments, so prefixed by --
instead of /
so the command line looks like:
/usr/bin/mono "/src/tools/JetBrains.dotCover.GlobalTool.2022.3.0/tools/netcoreapp3.1/any/dotCover.exe" Cover --TargetExecutable="/usr/bin/dotnet" --TargetArguments="test \"./Test.sln\" --configuration Release - -no-build" /Output="/src/Out/Coverage/result.dcvr"
instead of:
/usr/bin/mono "/src/tools/JetBrains.dotCover.GlobalTool.2022.3.0/tools/netcoreapp3.1/any/dotCover.exe" Cover /TargetExecutable="/usr/bin/dotnet" /TargetArguments="test \"./Test.sln\" --configuration Release - -no-build" /Output="/src/Out/Coverage/result.dcvr"
The --
prefix works on all platforms, the /
prefix only on Windows.
@Sebazzz Got it, I understand your approach. Before dive into deeper, let me update you I'm kinda new in cake build working, I'm constantly learning though.
What I guess or have knowledge so far:
Task("Tests")
.IsDependentOn("Build")
.Does(() =>
{
DotCoverCover(tool => {
tool.DotNetTest(pathToSolution, new DotNetTestSettings
{
Configuration = configuration,
NoBuild = true,
});
},
new FilePath(pathToCoverage),
new DotCoverCoverSettings());
});
This code part in cake script executes like this:
/usr/bin/mono "/src/tools/JetBrains.dotCover.GlobalTool.2022.3.0/tools/netcoreapp3.1/any/dotCover.exe" Cover /TargetExecutable="/usr/bin/dotnet" /TargetArguments="test \"./Test.sln\" --configuration Release - -no-build" /Output="/src/Out/Coverage/result.dcvr"
Cake build translates the code-part to this CLI argument based and then executes, right ?
(Kindly do update me if I'm wrong)
So in windows machine it worked fine, as the CLI arguments were supported. But same is not in the case of Linux.
What I would like to have: If dotCover translate to that command , could you update me how to overcome and use (the dotcover in cake) your solution in cake itself ?
Can we able to configure this dotCoverCover, translate the execution according to linux ? Or Is there any approach in achieving the Goal.
If dotCover translate to that command , could you update me how to overcome and use (the dotcover in cake) your solution in cake itself ?
Sorry, you can't (or at least, not really). This needs to be fixed in Cake.
As a workaround you can do this.
dotcover-xplatform.cake
// Workaround for: https://github.com/cake-build/cake/issues/4096
internal sealed class DotCoverProcessRunner : IProcessRunner {
public FilePath FilePath { get; set; }
public ProcessSettings ProcessSettings { get; set; }
private sealed class InterceptedProcess : IProcess
{
public void Dispose()
{
}
public void WaitForExit()
{
}
public bool WaitForExit(int milliseconds)
{
return true;
}
public int GetExitCode()
{
return 0;
}
public IEnumerable<string> GetStandardError()
{
return Enumerable.Empty<string>();
}
public IEnumerable<string> GetStandardOutput()
{
return Enumerable.Empty<string>();
}
public void Kill()
{
}
}
public IProcess Start(FilePath filePath, ProcessSettings settings)
{
FilePath = filePath;
ProcessSettings = settings;
return new InterceptedProcess();
}
}
internal sealed class DotCoverContext : CakeContextAdapter {
private readonly DotCoverProcessRunner _runner;
public override ICakeLog Log { get; }
public override IProcessRunner ProcessRunner => _runner;
public FilePath FilePath => _runner.FilePath;
public ProcessSettings Settings => _runner.ProcessSettings;
public DotCoverContext(ICakeContext context) : base(context)
{
Log = new NullLog();
_runner = new DotCoverProcessRunner();
}
}
void RunDotCoverWithFixedArgs(ICakeContext context, Action<ICakeContext> callback) {
var interceptor = new DotCoverContext(context);
callback.Invoke(interceptor);
Information("Original args: {0}", interceptor.Settings.Arguments.Render());
FilePath toolPath = context.Tools.Resolve("dotnet-dotCover.exe") ?? context.Tools.Resolve("dotnet-dotCover");
string toolArgs = interceptor.Settings.Arguments.Render();
toolArgs = System.Text.RegularExpressions.Regex.Replace(toolArgs, @"\s/", " --");
Information("Replaced args: {0}", toolArgs);
var settings = interceptor.Settings;
settings.Arguments = ProcessArgumentBuilder.FromString(toolArgs);
context.StartProcess(toolPath, settings);
}
And in your build.cake
:
#load "dotcover-xplatform.cake"
RunDotCoverWithFixedArgs(context, ctx => ctx.DotCoverCover(
tool => tool.DotNetTest(pathFilter, testSettings),
codeCoverageResultsFile,
dotCoverSettings));
This is a huge hack of course, but it works as a workaround until this bug is fixed.
One of the confusions I have with Cake DotCover, related to this issue, is it's not clear to me how to tell Cake to use all the different command line tools JetBrains now have for running DotCover. For example, there's at a minimum, either running dotnet dotcover
or dotcover.exe
. Which are supported, which should be supported, do they have the same command lines?
I certainly agree that the Unix-style arguments should be used uniformly, I guess I'm curious whether this issue is highlighting a wider mismatch in expectations (i.e. it's only ever been designed with Windows DotCover in mind). I don't see how the current Cake Tool
design really can cope with supporting both executables and dotnet tools, for example.
Prerequisites
Cake runner
Cake .NET Tool
Cake version
2.3.0
Operating system
Linux
Operating system architecture
64-Bit
CI Server
TeamCity and localy
What are you seeing?
When running on unix-like systems (im my case mcr.microsoft.com/dotnet/sdk:6.0-alpine docker container) DotCoverAliasses are still using windows style cli arguments. For example, when running task:
DotCoverCover executes:
/usr/bin/mono "/src/tools/JetBrains.dotCover.GlobalTool.2022.3.0/tools/netcoreapp3.1/any/dotCover.exe" Cover /TargetExecutable="/usr/bin/dotnet" /TargetArguments="test \"./Test.sln\" --configuration Release - -no-build" /Output="/src/Out/Coverage/result.dcvr"
As a result an error occures:[JetBrains dotCover] Configuration file '/TargetExecutable=/usr/bin/dotnet' not found.
Running on Windows 10 works perfectly
What is expected?
DotCover works on linux same way it is works on Windows
Steps to Reproduce
Run DotCoverCover(or other DotCoverAlias) in a cake file with any test runner (even passing null as an Action has the same result) on a linux system
Output log
When running task: