Switch to using File.LastWriteTimeUtc
This commit is contained in:
parent
07fbb3d967
commit
be18ee31be
4 changed files with 33 additions and 38 deletions
|
@ -19,9 +19,9 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public string ProjectFilePath { get; set; }
|
||||
|
||||
public DateTime LastProjectFileWriteTime { get; set; }
|
||||
public DateTime LastProjectFileWriteTimeUtc { get; set; }
|
||||
|
||||
public DateTime LastLockFileWriteTime { get; set; }
|
||||
public DateTime LastLockFileWriteTimeUtc { get; set; }
|
||||
|
||||
public bool HasChanged
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
return true;
|
||||
}
|
||||
|
||||
if (LastProjectFileWriteTime < File.GetLastWriteTime(ProjectFilePath))
|
||||
if (LastProjectFileWriteTimeUtc < File.GetLastWriteTimeUtc(ProjectFilePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
return true;
|
||||
}
|
||||
|
||||
if (LastLockFileWriteTime < File.GetLastWriteTime(LockFilePath))
|
||||
if (LastLockFileWriteTimeUtc < File.GetLastWriteTimeUtc(LockFilePath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
ProjectContexts.Clear();
|
||||
ProjectFilePath = null;
|
||||
LockFilePath = null;
|
||||
LastLockFileWriteTime = DateTime.MinValue;
|
||||
LastProjectFileWriteTime = DateTime.MinValue;
|
||||
LastLockFileWriteTimeUtc = DateTime.MinValue;
|
||||
LastProjectFileWriteTimeUtc = DateTime.MinValue;
|
||||
ProjectDiagnostics.Clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
{
|
||||
currentEntry.Model = project;
|
||||
currentEntry.FilePath = project.ProjectFilePath;
|
||||
currentEntry.UpdateLastWriteTime();
|
||||
currentEntry.UpdateLastWriteTimeUtc();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
{
|
||||
currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName);
|
||||
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath);
|
||||
currentEntry.UpdateLastWriteTime();
|
||||
currentEntry.UpdateLastWriteTimeUtc();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,13 +248,13 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
currentEntry.Project = project;
|
||||
currentEntry.ProjectFilePath = project.ProjectFilePath;
|
||||
currentEntry.LastProjectFileWriteTime = File.GetLastWriteTime(currentEntry.ProjectFilePath);
|
||||
currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath);
|
||||
|
||||
var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName);
|
||||
if (File.Exists(lockFilePath))
|
||||
{
|
||||
currentEntry.LockFilePath = lockFilePath;
|
||||
currentEntry.LastLockFileWriteTime = File.GetLastWriteTime(lockFilePath);
|
||||
currentEntry.LastLockFileWriteTimeUtc = File.GetLastWriteTimeUtc(lockFilePath);
|
||||
}
|
||||
|
||||
currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics);
|
||||
|
@ -265,7 +265,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
private class FileModelEntry<TModel> where TModel : class
|
||||
{
|
||||
private DateTime _lastWriteTime;
|
||||
private DateTime _lastWriteTimeUtc;
|
||||
|
||||
public TModel Model { get; set; }
|
||||
|
||||
|
@ -273,9 +273,9 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public List<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
|
||||
|
||||
public void UpdateLastWriteTime()
|
||||
public void UpdateLastWriteTimeUtc()
|
||||
{
|
||||
_lastWriteTime = File.GetLastWriteTime(FilePath);
|
||||
_lastWriteTimeUtc = File.GetLastWriteTimeUtc(FilePath);
|
||||
}
|
||||
|
||||
public bool IsInvalid
|
||||
|
@ -292,7 +292,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
return true;
|
||||
}
|
||||
|
||||
return _lastWriteTime < File.GetLastWriteTime(FilePath);
|
||||
return _lastWriteTimeUtc < File.GetLastWriteTimeUtc(FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
Model = null;
|
||||
FilePath = null;
|
||||
Diagnostics.Clear();
|
||||
_lastWriteTime = DateTime.MinValue;
|
||||
_lastWriteTimeUtc = DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using Microsoft.DotNet.Cli.Compiler.Common;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Compiler;
|
||||
using Microsoft.DotNet.ProjectModel.Utilities;
|
||||
using Microsoft.DotNet.Cli.Compiler.Common;
|
||||
using Microsoft.DotNet.Tools.Compiler;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Build
|
||||
{
|
||||
|
@ -115,21 +114,21 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
// find the output with the earliest write time
|
||||
var minOutputPath = compilerIO.Outputs.First();
|
||||
var minDate = File.GetLastWriteTime(minOutputPath);
|
||||
var minDateUtc = File.GetLastWriteTimeUtc(minOutputPath);
|
||||
|
||||
foreach (var outputPath in compilerIO.Outputs)
|
||||
{
|
||||
if (File.GetLastWriteTime(outputPath) >= minDate)
|
||||
if (File.GetLastWriteTimeUtc(outputPath) >= minDateUtc)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
minDate = File.GetLastWriteTime(outputPath);
|
||||
minDateUtc = File.GetLastWriteTimeUtc(outputPath);
|
||||
minOutputPath = outputPath;
|
||||
}
|
||||
|
||||
// find inputs that are older than the earliest output
|
||||
var newInputs = compilerIO.Inputs.FindAll(p => File.GetLastWriteTime(p) > minDate);
|
||||
var newInputs = compilerIO.Inputs.FindAll(p => File.GetLastWriteTimeUtc(p) > minDateUtc);
|
||||
|
||||
if (!newInputs.Any())
|
||||
{
|
||||
|
@ -140,7 +139,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
Reporter.Output.WriteLine($"Project {project.GetDisplayName()} will be compiled because some of its inputs were newer than its oldest output.");
|
||||
Reporter.Verbose.WriteLine();
|
||||
Reporter.Verbose.WriteLine($" Oldest output item:");
|
||||
Reporter.Verbose.WriteLine($" {minDate}: {minOutputPath}");
|
||||
Reporter.Verbose.WriteLine($" {minDateUtc.ToLocalTime()}: {minOutputPath}");
|
||||
Reporter.Verbose.WriteLine();
|
||||
|
||||
Reporter.Verbose.WriteLine($" Inputs newer than the oldest output item:");
|
||||
|
|
|
@ -2,16 +2,12 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tests.EndToEnd
|
||||
{
|
||||
|
@ -57,16 +53,16 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
||||
|
||||
var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);
|
||||
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(
|
||||
var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
||||
binariesOutputDirectory);
|
||||
|
||||
// second build; should get skipped (incremental because no inputs changed)
|
||||
buildCommand.Execute().Should().Pass();
|
||||
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
||||
|
||||
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(
|
||||
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
||||
binariesOutputDirectory);
|
||||
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
|
||||
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild);
|
||||
|
||||
TouchSourceFileInDirectory(TestDirectory);
|
||||
|
||||
|
@ -74,9 +70,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
buildCommand.Execute().Should().Pass();
|
||||
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
||||
|
||||
var latestWriteTimeThirdBuild = GetLastWriteTimeOfDirectoryFiles(
|
||||
var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles(
|
||||
binariesOutputDirectory);
|
||||
Assert.NotEqual(latestWriteTimeSecondBuild, latestWriteTimeThirdBuild);
|
||||
Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -129,15 +125,15 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
|
||||
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
||||
|
||||
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory);
|
||||
var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
|
||||
|
||||
// second build; should be skipped because nothing changed
|
||||
buildCommand.Execute().Should().Pass();
|
||||
|
||||
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
|
||||
|
||||
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory);
|
||||
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
|
||||
var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
|
||||
Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -206,9 +202,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd
|
|||
return false;
|
||||
}
|
||||
|
||||
private static DateTime GetLastWriteTimeOfDirectoryFiles(string outputDirectory)
|
||||
private static DateTime GetLastWriteTimeUtcOfDirectoryFiles(string outputDirectory)
|
||||
{
|
||||
return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTime(f));
|
||||
return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTimeUtc(f));
|
||||
}
|
||||
|
||||
private static void TouchSourceFileInDirectory(string directory)
|
||||
|
|
Loading…
Reference in a new issue