Revert sourcelink patch, will need to flow in latest version

This commit is contained in:
Michael Simons 2023-04-10 22:10:22 +00:00
parent 23f565e535
commit 8adfab91ad

View file

@ -1,276 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Matou=C5=A1ek?=
<tmat@users.noreply.github.com>
Date: Mon, 10 Apr 2023 14:25:53 -0700
Subject: [PATCH] Fix FileWrites (#995)
Backport: https://github.com/dotnet/sourcelink/issues/993
---
.../GenerateSourceLinkFileTests.cs | 4 --
.../GenerateSourceLinkFile.cs | 16 +----
.../build/Microsoft.SourceLink.Common.targets | 11 +++-
.../CloudHostedProvidersTests.cs | 61 ++++++++++++++-----
4 files changed, 56 insertions(+), 36 deletions(-)
diff --git a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs
index 50ecb7c..9234421 100644
--- a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs
+++ b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs
@@ -40,7 +40,6 @@ public void Empty(bool noWarning)
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedOutput, engine.Log);
Assert.Null(task.SourceLink);
- Assert.Null(task.FileWrite);
}
[Theory]
@@ -73,7 +72,6 @@ public void NoRepositoryUrl(bool noWarning)
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedOutput, engine.Log);
Assert.Null(task.SourceLink);
- Assert.Null(task.FileWrite);
}
[Fact]
@@ -100,7 +98,6 @@ public void Empty_DeleteExistingFile()
string.Format(Resources.SourceLinkEmptyDeletingExistingFile, sourceLinkFile.Path), engine.Log);
Assert.Null(task.SourceLink);
- Assert.Equal(sourceLinkFile.Path, task.FileWrite);
}
[Fact]
@@ -235,7 +232,6 @@ public void DoesNotRewriteContentIfFileContentIsSame()
Assert.Equal(@"{""documents"":{""/_\""_/*"":""https://raw.githubusercontent.com/repo/*""}}", File.ReadAllText(tempFile.Path, Encoding.UTF8));
Assert.Equal(tempFile.Path, task.SourceLink);
- Assert.Equal(tempFile.Path, task.FileWrite);
result = task.Execute();
diff --git a/src/SourceLink.Common/GenerateSourceLinkFile.cs b/src/SourceLink.Common/GenerateSourceLinkFile.cs
index 8a07616..859cf0d 100644
--- a/src/SourceLink.Common/GenerateSourceLinkFile.cs
+++ b/src/SourceLink.Common/GenerateSourceLinkFile.cs
@@ -21,12 +21,6 @@ public sealed class GenerateSourceLinkFile : Task
[Required, NotNull]
public string? OutputFile { get; set; }
- /// <summary>
- /// Set to <see cref="OutputFile"/> if the output file was written to, null otherwise.
- /// </summary>
- [Output]
- public string? FileWrite { get; set; }
-
/// <summary>
/// Set to <see cref="OutputFile"/> if the output Source Link file should be passed to the compiler.
/// </summary>
@@ -60,14 +54,14 @@ static string jsonEscape(string str)
if (!localPath.EndsWithSeparator())
{
- Log.LogError(Resources.MustEndWithDirectorySeparator, (isMapped ? Names.SourceRoot.MappedPathFullName : Names.SourceRoot.Name), localPath);
+ Log.LogError(Resources.MustEndWithDirectorySeparator, isMapped ? Names.SourceRoot.MappedPathFullName : Names.SourceRoot.Name, localPath);
success = false;
continue;
}
if (localPath.Contains('*'))
{
- Log.LogError(Resources.MustNotContainWildcard, (isMapped ? Names.SourceRoot.MappedPathFullName : Names.SourceRoot.Name), localPath);
+ Log.LogError(Resources.MustNotContainWildcard, isMapped ? Names.SourceRoot.MappedPathFullName : Names.SourceRoot.Name, localPath);
success = false;
continue;
}
@@ -127,7 +121,6 @@ private void WriteSourceLinkFile(string? content)
Log.LogMessage(Resources.SourceLinkEmptyDeletingExistingFile, OutputFile);
File.Delete(OutputFile);
- FileWrite = OutputFile;
return;
}
@@ -151,14 +144,11 @@ private void WriteSourceLinkFile(string? content)
Log.LogMessage(Resources.SourceLinkFileUpdated, OutputFile);
File.WriteAllText(OutputFile, content);
- FileWrite = SourceLink = OutputFile;
+ SourceLink = OutputFile;
}
catch (Exception e)
{
Log.LogError(Resources.ErrorWritingToSourceLinkFile, OutputFile, e.Message);
-
- // Part of the file might have been written.
- FileWrite = OutputFile;
}
}
}
diff --git a/src/SourceLink.Common/build/Microsoft.SourceLink.Common.targets b/src/SourceLink.Common/build/Microsoft.SourceLink.Common.targets
index ea05b19..0f9a861 100644
--- a/src/SourceLink.Common/build/Microsoft.SourceLink.Common.targets
+++ b/src/SourceLink.Common/build/Microsoft.SourceLink.Common.targets
@@ -58,11 +58,16 @@
<!-- Set SourceLink property passed to compilers -->
<Output TaskParameter="SourceLink" PropertyName="SourceLink" />
-
- <!-- Log file write if the content of the file has been updated -->
- <Output TaskParameter="FileWrite" ItemName="FileWrites" />
</Microsoft.SourceLink.Common.GenerateSourceLinkFile>
+ <!--
+ Include the output file whenever it exists, even if it hasn't been written to (it was up-to-date).
+ This is needed so that incremental clean doesn't delete the file.
+ -->
+ <ItemGroup Condition="'$(SourceLink)' != ''">
+ <FileWrites Include="$(SourceLink)" />
+ </ItemGroup>
+
<!-- C++ Link task currently doesn't recognize SourceLink property -->
<ItemGroup Condition="'$(Language)' == 'C++' and '$(SourceLink)' != ''">
<Link Update="@(Link)">
diff --git a/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs b/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs
index 8a91a9a..58129d0 100644
--- a/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs
+++ b/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs
@@ -131,6 +131,11 @@ public void NoCommit_NoRemote_NoWarnings()
<PkgMicrosoft_Build_Tasks_Git></PkgMicrosoft_Build_Tasks_Git>
<PkgMicrosoft_SourceLink_Common></PkgMicrosoft_SourceLink_Common>
</PropertyGroup>
+ <Target Name="_CaptureFileWrites" DependsOnTargets="GenerateSourceLinkFile" BeforeTargets="AfterBuild">
+ <ItemGroup>
+ <_SourceLinkFileWrites Include="@(FileWrites)" Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').EndsWith('sourcelink.json'))"/>
+ </ItemGroup>
+ </Target>
""",
customTargets: "",
targets: new[]
@@ -141,11 +146,13 @@ public void NoCommit_NoRemote_NoWarnings()
{
"@(SourceRoot)",
"$(SourceLink)",
+ "@(_SourceLinkFileWrites)",
},
expectedResults: new[]
{
NuGetPackageFolders,
"",
+ "",
});
}
@@ -160,6 +167,11 @@ public void Commit_NoRemote_NoWarnings()
<PkgMicrosoft_Build_Tasks_Git></PkgMicrosoft_Build_Tasks_Git>
<PkgMicrosoft_SourceLink_Common></PkgMicrosoft_SourceLink_Common>
</PropertyGroup>
+ <Target Name="_CaptureFileWrites" DependsOnTargets="GenerateSourceLinkFile" BeforeTargets="AfterBuild">
+ <ItemGroup>
+ <_SourceLinkFileWrites Include="@(FileWrites)" Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').EndsWith('sourcelink.json'))"/>
+ </ItemGroup>
+ </Target>
""",
customTargets: "",
targets: new[]
@@ -170,12 +182,14 @@ public void Commit_NoRemote_NoWarnings()
{
"@(SourceRoot)",
"$(SourceLink)",
+ "@(_SourceLinkFileWrites)",
},
expectedResults: new[]
{
NuGetPackageFolders,
ProjectSourceRoot,
"",
+ "",
});
}
@@ -190,6 +204,11 @@ public void NoCommit_Remote_NoWarnings()
<PkgMicrosoft_Build_Tasks_Git></PkgMicrosoft_Build_Tasks_Git>
<PkgMicrosoft_SourceLink_Common></PkgMicrosoft_SourceLink_Common>
</PropertyGroup>
+ <Target Name="_CaptureFileWrites" DependsOnTargets="GenerateSourceLinkFile" BeforeTargets="AfterBuild">
+ <ItemGroup>
+ <_SourceLinkFileWrites Include="@(FileWrites)" Condition="$([MSBuild]::ValueOrDefault('%(Identity)', '').EndsWith('sourcelink.json'))"/>
+ </ItemGroup>
+ </Target>
""",
customTargets: "",
targets: new[]
@@ -200,11 +219,13 @@ public void NoCommit_Remote_NoWarnings()
{
"@(SourceRoot)",
"$(SourceLink)",
+ "@(_SourceLinkFileWrites)",
},
expectedResults: new[]
{
NuGetPackageFolders,
"",
+ "",
});
}
@@ -230,21 +251,27 @@ public void CustomTranslation()
DependsOnTargets=""$(SourceControlManagerUrlTranslationTargets)""
BeforeTargets=""SourceControlManagerPublishTranslatedUrls"">
- <PropertyGroup>
- <_Pattern>https://([^.]+)[.]visualstudio.com/([^/]+)/_git/([^/]+)</_Pattern>
- <_Replacement>https://github.com/$2/$3</_Replacement>
- </PropertyGroup>
-
- <PropertyGroup>
- <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
- </PropertyGroup>
-
- <ItemGroup>
- <SourceRoot Update=""@(SourceRoot)"">
- <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace(%(SourceRoot.ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
- </SourceRoot>
- </ItemGroup>
- </Target>
+ <PropertyGroup>
+ <_Pattern>https://([^.]+)[.]visualstudio.com/([^/]+)/_git/([^/]+)</_Pattern>
+ <_Replacement>https://github.com/$2/$3</_Replacement>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace($(ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <SourceRoot Update=""@(SourceRoot)"">
+ <ScmRepositoryUrl>$([System.Text.RegularExpressions.Regex]::Replace(%(SourceRoot.ScmRepositoryUrl), $(_Pattern), $(_Replacement)))</ScmRepositoryUrl>
+ </SourceRoot>
+ </ItemGroup>
+</Target>
+
+<Target Name=""_CaptureFileWrites"" DependsOnTargets=""GenerateSourceLinkFile"" BeforeTargets=""AfterBuild"">
+ <ItemGroup>
+ <_SourceLinkFileWrites Include=""@(FileWrites)"" Condition=""$([MSBuild]::ValueOrDefault('%(Identity)', '').EndsWith('sourcelink.json'))""/>
+ </ItemGroup>
+</Target>
",
targets: new[]
{
@@ -256,7 +283,8 @@ public void CustomTranslation()
"@(SourceRoot->'%(SourceLinkUrl)')",
"$(SourceLink)",
"$(PrivateRepositoryUrl)",
- "$(RepositoryUrl)"
+ "$(RepositoryUrl)",
+ "@(_SourceLinkFileWrites)",
},
expectedResults: new[]
{
@@ -266,6 +294,7 @@ public void CustomTranslation()
s_relativeSourceLinkJsonPath,
$"https://github.com/test-org/{repoName}",
$"https://github.com/test-org/{repoName}",
+ s_relativeSourceLinkJsonPath
});
AssertEx.AreEqual(