Skip to content

1155 deterministicbuildfix #1442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
96e723b
Add project name to the CoverletSourceRootsMapping file to avoid file…
Apr 8, 2022
d6dd658
bump build sdk
Apr 8, 2022
6b602c5
bump build sdk
Apr 8, 2022
b727487
bump build sdk
Apr 8, 2022
ea859af
bump sdk version
Apr 8, 2022
c6b3547
bump runtime for tests
Apr 8, 2022
850eca9
cleanup
Apr 8, 2022
9b4d3c0
update yaml
Apr 8, 2022
e82ce4c
add logs
Apr 8, 2022
44d3ee3
add logs
Apr 8, 2022
6fc6c6b
updates
Apr 8, 2022
b93b548
Merge branch 'coverlet-coverage:master' into determisticbuildfix
MarcoRossignoli May 20, 2022
1830d17
updates
MarcoRossignoli Mar 19, 2022
7199108
updates
MarcoRossignoli Mar 20, 2022
e53eddb
bump build sdk
Apr 8, 2022
7331331
bump build sdk
Apr 8, 2022
4c0ca75
bump build sdk
Apr 8, 2022
6f35cae
bump sdk version
Apr 8, 2022
387c0e7
bump runtime for tests
Apr 8, 2022
4e30b35
cleanup
Apr 8, 2022
f76d917
update yaml
Apr 8, 2022
10079a9
add logs
Apr 8, 2022
d4a6dd0
add logs
Apr 8, 2022
9490547
updates
Apr 8, 2022
717a062
Merge branch 'determisticbuildfix' of https://github.com/MarcoRossign…
MarcoRossignoli May 20, 2022
573407b
updates
MarcoRossignoli May 21, 2022
c363b0a
add blame
MarcoRossignoli May 21, 2022
fa0dc2a
updates
MarcoRossignoli May 21, 2022
cea8475
updates
MarcoRossignoli May 21, 2022
9d81df0
updates
MarcoRossignoli May 21, 2022
7f49cd8
updates
MarcoRossignoli May 21, 2022
339fcf1
updates
MarcoRossignoli May 21, 2022
afe95df
updates
MarcoRossignoli May 21, 2022
05f6e5d
updates
MarcoRossignoli May 21, 2022
2fa79a9
updates
MarcoRossignoli May 21, 2022
fda7a76
updates
MarcoRossignoli May 21, 2022
a8459e5
updates
MarcoRossignoli May 21, 2022
ca7f584
updates
MarcoRossignoli May 21, 2022
5fa57be
updates
MarcoRossignoli May 21, 2022
cf64722
updates
MarcoRossignoli May 21, 2022
8a5f51a
updates
MarcoRossignoli May 21, 2022
e2b21ca
updates
MarcoRossignoli May 21, 2022
62a8917
updates
MarcoRossignoli May 21, 2022
7907b63
updates
MarcoRossignoli May 21, 2022
fa05f12
updates
MarcoRossignoli May 21, 2022
e0ecc6e
updates
MarcoRossignoli May 21, 2022
c8f95b0
updates
MarcoRossignoli May 21, 2022
9f584b6
updates
MarcoRossignoli May 22, 2022
7b47ccf
updates
MarcoRossignoli May 22, 2022
ca98c62
updates
MarcoRossignoli May 22, 2022
9438a03
updates
MarcoRossignoli May 22, 2022
a35e867
updates
MarcoRossignoli May 22, 2022
1ac4b71
Revert "updates"
MarcoRossignoli May 22, 2022
04208ef
Revert "updates"
MarcoRossignoli May 22, 2022
e3644ab
updates
MarcoRossignoli May 22, 2022
4502c40
updates
MarcoRossignoli May 22, 2022
453d663
updates
MarcoRossignoli May 22, 2022
42468d1
Add project name to the CoverletSourceRootsMapping file to avoid file…
Apr 8, 2022
e93cebb
update
MarcoRossignoli May 22, 2022
a1d44ab
updates
MarcoRossignoli May 22, 2022
f1edf74
updates
MarcoRossignoli May 22, 2022
cc8fc50
updates
MarcoRossignoli May 22, 2022
2793a14
test
daveMueller Feb 11, 2023
6c45ba7
nit
daveMueller Feb 11, 2023
6dbc165
nit
daveMueller Feb 11, 2023
f12c1f8
test
daveMueller Feb 11, 2023
895752b
nit
daveMueller Feb 11, 2023
f6c9ee7
test
daveMueller Feb 11, 2023
ed3a163
test
daveMueller Feb 11, 2023
8428003
nit
daveMueller Feb 11, 2023
1accbc4
test
daveMueller Feb 11, 2023
c3c43cb
nit
daveMueller Feb 11, 2023
8260822
nit
daveMueller Feb 11, 2023
849cbef
nit
daveMueller Feb 11, 2023
544ed0a
test
daveMueller Feb 11, 2023
8d1d6d8
nit
daveMueller Feb 12, 2023
a84d190
nit
daveMueller Feb 12, 2023
f44b162
adapted sourceroottranlator tests
daveMueller Feb 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.assert" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1"/>
<PackageReference Update="Tmds.ExecFunction" Version="0.4.0" />
<PackageReference Update="Tmds.ExecFunction" Version="0.5.0" />
</ItemGroup>

<!-- Deterministic build workaround -->
Expand Down
4 changes: 2 additions & 2 deletions Documentation/Examples/VSTest/DeterministicBuild/HowTo.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Add collectors package version generated to `"..\Documentation\Examples\VSTest\D
Go to test project folder and run
```
C:\git\coverlet\Documentation\Examples\VSTest\DeterministicBuild (detbuilddocs -> origin)
λ dotnet test --collect:"XPlat Code Coverage" /p:DeterministicSourcePaths=true
λ dotnet test --collect:"XPlat Code Coverage" /p:DeterministicSourcePaths=true -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.DeterministicReport=true
Test run for C:\git\coverlet\Documentation\Examples\VSTest\DeterministicBuild\XUnitTestProject1\bin\Debug\netcoreapp3.1\XUnitTestProject1.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.5.0
Copyright (c) Microsoft Corporation. All rights reserved.
Expand All @@ -78,5 +78,5 @@ Total tests: 1
You should see on output folder the coverlet source root mapping file generated.
This is the confirmation that you're running coverage on deterministic build.
```
Documentation\Examples\VSTest\DeterministicBuild\XUnitTestProject1\bin\Debug\netcoreapp3.1\CoverletSourceRootsMapping
Documentation\Examples\VSTest\DeterministicBuild\XUnitTestProject1\bin\Debug\netcoreapp3.1\CoverletSourceRootsMapping_XUnitTestProject1
```
10 changes: 9 additions & 1 deletion eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ steps:
version: 5.0.401
displayName: Install .NET Core SDK 5.0.401

- task: UseDotNet@2
inputs:
version: 6.0.300
displayName: Install .NET Core SDK 6.0.300

- script: dotnet --info
displayName: dotnet --info

- script: dotnet restore
displayName: Restore packages

Expand All @@ -22,5 +30,5 @@ steps:
displayName: Run tests
inputs:
command: test
arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[coverlet.collector]*%2c[coverlet.core]*%2c[coverlet.msbuild.tasks]*" /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*"
arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[coverlet.collector]*%2c[coverlet.core]*%2c[coverlet.msbuild.tasks]*" /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*" --blame-crash --blame-hang --blame-hang-timeout 15m
testRunTitle: $(Agent.JobName)
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.401",
"version": "6.0.300",
"rollForward": "latestMajor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<_mapping Include="@(_byProject->'%(Identity)|%(OriginalPath)=%(MappedPath)')" />
</ItemGroup>
<PropertyGroup>
<_sourceRootMappingFilePath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))CoverletSourceRootsMapping</_sourceRootMappingFilePath>
<_sourceRootMappingFilePath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))CoverletSourceRootsMapping_$(AssemblyName)</_sourceRootMappingFilePath>
</PropertyGroup>
<WriteLinesToFile File="$(_sourceRootMappingFilePath)" Lines="@(_mapping)"
Overwrite="true" Encoding="Unicode"
Expand Down
6 changes: 4 additions & 2 deletions src/coverlet.core/Helpers/SourceRootTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class SourceRootTranslator : ISourceRootTranslator
private readonly IFileSystem _fileSystem;
private readonly Dictionary<string, List<SourceRootMapping>> _sourceRootMapping;
private readonly Dictionary<string, List<string>> _sourceToDeterministicPathMapping;
private const string MappingFileName = "CoverletSourceRootsMapping";
private readonly string _mappingFileName;
private Dictionary<string, string> _resolutionCacheFiles;

public SourceRootTranslator(ILogger logger, IFileSystem fileSystem)
Expand All @@ -44,6 +44,7 @@ public SourceRootTranslator(string moduleTestPath, ILogger logger, IFileSystem f
{
throw new FileNotFoundException($"Module test path '{moduleTestPath}' not found", moduleTestPath);
}
_mappingFileName = $"CoverletSourceRootsMapping_coverletsample.integration.determisticbuild";
_sourceRootMapping = LoadSourceRootMapping(Path.GetDirectoryName(moduleTestPath));
_sourceToDeterministicPathMapping = LoadSourceToDeterministicPathMapping(_sourceRootMapping);
}
Expand Down Expand Up @@ -75,7 +76,8 @@ private Dictionary<string, List<SourceRootMapping>> LoadSourceRootMapping(string
{
var mapping = new Dictionary<string, List<SourceRootMapping>>();

string mappingFilePath = Path.Combine(directory, MappingFileName);
string mappingFilePath = Path.Combine(directory, _mappingFileName);
//throw new Exception(mappingFilePath + " --- " + _fileSystem.Exists(mappingFilePath));
if (!_fileSystem.Exists(mappingFilePath))
{
return mapping;
Expand Down
2 changes: 1 addition & 1 deletion src/coverlet.msbuild.tasks/coverlet.msbuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<_mapping Include="@(_byProject->'%(Identity)|%(OriginalPath)=%(MappedPath)')" />
</ItemGroup>
<PropertyGroup>
<_sourceRootMappingFilePath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))CoverletSourceRootsMapping</_sourceRootMappingFilePath>
<_sourceRootMappingFilePath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))CoverletSourceRootsMapping_$(AssemblyName)</_sourceRootMappingFilePath>
</PropertyGroup>
<WriteLinesToFile File="$(_sourceRootMappingFilePath)" Lines="@(_mapping)"
Overwrite="true" Encoding="Unicode"
Expand Down
8 changes: 4 additions & 4 deletions test/coverlet.core.tests/Helpers/SourceRootTranslatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Translate_Success()
var fileSystem = new Mock<IFileSystem>();
fileSystem.Setup(f => f.Exists(It.IsAny<string>())).Returns((string p) =>
{
if (p == "testLib.dll" || p == @"C:\git\coverlet\src\coverlet.core\obj\Debug\netstandard2.0\coverlet.core.pdb" || p == "CoverletSourceRootsMapping") return true;
if (p == "testLib.dll" || p == @"C:\git\coverlet\src\coverlet.core\obj\Debug\netstandard2.0\coverlet.core.pdb" || p == "CoverletSourceRootsMapping_testLib") return true;
return false;
});
fileSystem.Setup(f => f.ReadAllLines(It.IsAny<string>())).Returns(File.ReadAllLines(@"TestAssets/CoverletSourceRootsMappingTest"));
Expand All @@ -39,7 +39,7 @@ public void TranslatePathRoot_Success()
var fileSystem = new Mock<IFileSystem>();
fileSystem.Setup(f => f.Exists(It.IsAny<string>())).Returns((string p) =>
{
if (p == "testLib.dll" || p == @"C:\git\coverlet\src\coverlet.core\obj\Debug\netstandard2.0\coverlet.core.pdb" || p == "CoverletSourceRootsMapping") return true;
if (p == "testLib.dll" || p == @"C:\git\coverlet\src\coverlet.core\obj\Debug\netstandard2.0\coverlet.core.pdb" || p == "CoverletSourceRootsMapping_testLib") return true;
return false;
});
fileSystem.Setup(f => f.ReadAllLines(It.IsAny<string>())).Returns(File.ReadAllLines(@"TestAssets/CoverletSourceRootsMappingTest"));
Expand All @@ -55,7 +55,7 @@ public void Translate_EmptyFile()
var fileSystem = new Mock<IFileSystem>();
fileSystem.Setup(f => f.Exists(It.IsAny<string>())).Returns((string p) =>
{
if (p == "testLib.dll" || p == "CoverletSourceRootsMapping") return true;
if (p == "testLib.dll" || p == "CoverletSourceRootsMapping_testLib") return true;
return false;
});
fileSystem.Setup(f => f.ReadAllLines(It.IsAny<string>())).Returns(new string[0]);
Expand All @@ -71,7 +71,7 @@ public void Translate_MalformedFile()
var fileSystem = new Mock<IFileSystem>();
fileSystem.Setup(f => f.Exists(It.IsAny<string>())).Returns((string p) =>
{
if (p == "testLib.dll" || p == "CoverletSourceRootsMapping") return true;
if (p == "testLib.dll" || p == "CoverletSourceRootsMapping_testLib") return true;
return false;
});
fileSystem.Setup(f => f.ReadAllLines(It.IsAny<string>())).Returns(new string[1] { "malformedRow" });
Expand Down
8 changes: 4 additions & 4 deletions test/coverlet.integration.tests/DeterministicBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Msbuild()
CreateDeterministicTestPropsFile();
DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string _, _testProjectPath);
Assert.Contains("Build succeeded.", standardOutput);
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping");
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, $"CoverletSourceRootsMapping_coverletsample.integration.determisticbuild");
Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath);
Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file");
Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath));
Expand All @@ -98,7 +98,7 @@ public void Msbuild_SourceLink()
CreateDeterministicTestPropsFile();
DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string _, _testProjectPath);
Assert.Contains("Build succeeded.", standardOutput);
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, "CoverletSourceRootsMapping");
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", _buildConfiguration, _testProjectTfm!, $"CoverletSourceRootsMapping_coverletsample.integration.determisticbuild");
Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath);
Assert.True(!string.IsNullOrEmpty(File.ReadAllText(sourceRootMappingFilePath)), "Empty CoverletSourceRootsMapping file");
Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath));
Expand All @@ -122,7 +122,7 @@ public void Collectors()
CreateDeterministicTestPropsFile();
DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string _, _testProjectPath);
Assert.Contains("Build succeeded.", standardOutput);
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping");
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, $"CoverletSourceRootsMapping_coverletsample.integration.determisticbuild");
Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath);
Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath));
Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath));
Expand Down Expand Up @@ -150,7 +150,7 @@ public void Collectors_SourceLink()
CreateDeterministicTestPropsFile();
DotnetCli($"build -c {_buildConfiguration} /p:DeterministicSourcePaths=true", out string standardOutput, out string _, _testProjectPath);
Assert.Contains("Build succeeded.", standardOutput);
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, "CoverletSourceRootsMapping");
string sourceRootMappingFilePath = Path.Combine(_testProjectPath, "bin", GetAssemblyBuildConfiguration().ToString(), _testProjectTfm!, $"CoverletSourceRootsMapping_coverletsample.integration.determisticbuild");
Assert.True(File.Exists(sourceRootMappingFilePath), sourceRootMappingFilePath);
Assert.NotEmpty(File.ReadAllText(sourceRootMappingFilePath));
Assert.Contains("=/_/", File.ReadAllText(sourceRootMappingFilePath));
Expand Down