Skip to content

Commit 02a3a62

Browse files
Skip Updating CopyComplete Marker When Not Necessary (#6698)
Fixes ##6576 ### Context #6576 revealed that the `.copycomplete` file marker is updated even when the `Copy` task in `_GetCopyFilesMarkedLocal` doesn't _actually_ copy anything. This can mess with incremental builds. ### Changes Made This change adds an output parameter, `CopiedAtLeastOneFile` to the `Copy` task that the `Touch` task is now conditioned off of. ### Testing Tested local builds ### Notes This could also be done by having an ITaskItem[] that contains all files that were actually copied. Then the touch task could check if that item were empty. I opted for the straightforward route since the ITaskItem[] solution isn't needed yet, and this implementation can easily be changed when we do need that. Co-authored-by: Forgind <Forgind@users.noreply.github.com>
1 parent 48ffc98 commit 02a3a62

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

ref/Microsoft.Build.Tasks.Core/net/Microsoft.Build.Tasks.Core.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public Copy() { }
207207
public Microsoft.Build.Framework.ITaskItem[] SourceFiles { get { throw null; } set { } }
208208
public bool UseHardlinksIfPossible { get { throw null; } set { } }
209209
public bool UseSymboliclinksIfPossible { get { throw null; } set { } }
210+
[Microsoft.Build.Framework.OutputAttribute]
211+
public bool WroteAtLeastOneFile { get { throw null; } }
210212
public void Cancel() { }
211213
public override bool Execute() { throw null; }
212214
}

ref/Microsoft.Build.Tasks.Core/netstandard/Microsoft.Build.Tasks.Core.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public Copy() { }
137137
public Microsoft.Build.Framework.ITaskItem[] SourceFiles { get { throw null; } set { } }
138138
public bool UseHardlinksIfPossible { get { throw null; } set { } }
139139
public bool UseSymboliclinksIfPossible { get { throw null; } set { } }
140+
[Microsoft.Build.Framework.OutputAttribute]
141+
public bool WroteAtLeastOneFile { get { throw null; } }
140142
public void Cancel() { }
141143
public override bool Execute() { throw null; }
142144
}

src/Tasks/Copy.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public Copy()
139139
[Output]
140140
public ITaskItem[] CopiedFiles { get; private set; }
141141

142+
[Output]
143+
public bool WroteAtLeastOneFile { get; private set; }
144+
142145
/// <summary>
143146
/// Whether to overwrite files in the destination
144147
/// that have the read-only attribute set.
@@ -298,6 +301,9 @@ FileState destinationFileState // The destination file
298301

299302
File.Copy(sourceFileState.Name, destinationFileState.Name, true);
300303
}
304+
305+
// Files were successfully copied or linked. Those are equivalent here.
306+
WroteAtLeastOneFile = true;
301307

302308
destinationFileState.Reset();
303309

src/Tasks/Microsoft.Common.CurrentVersion.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4696,6 +4696,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
46964696

46974697
<Output TaskParameter="DestinationFiles" ItemName="FileWritesShareable"/>
46984698
<Output TaskParameter="CopiedFiles" ItemName="ReferencesCopiedInThisBuild"/>
4699+
<Output TaskParameter="WroteAtLeastOneFile" PropertyName="WroteAtLeastOneFile"/>
46994700

47004701
</Copy>
47014702

@@ -4705,7 +4706,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
47054706
input to projects that reference this one. -->
47064707
<Touch Files="@(CopyUpToDateMarker)"
47074708
AlwaysCreate="true"
4708-
Condition="'@(ReferencesCopiedInThisBuild)' != ''">
4709+
Condition="'@(ReferencesCopiedInThisBuild)' != '' and '$(WroteAtLeastOneFile)' == 'true'">
47094710
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
47104711
</Touch>
47114712

0 commit comments

Comments
 (0)