Merge pull request #1078 from dotnet/prkrishn/lastwritetimeutc

Switch to using File.LastWriteTimeUtc
This commit is contained in:
Pranav K 2016-01-29 19:35:38 -08:00
commit 4e365921f7
4 changed files with 33 additions and 38 deletions

View file

@ -19,9 +19,9 @@ namespace Microsoft.DotNet.ProjectModel
public string ProjectFilePath { get; set; } 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 public bool HasChanged
{ {
@ -32,7 +32,7 @@ namespace Microsoft.DotNet.ProjectModel
return true; return true;
} }
if (LastProjectFileWriteTime < File.GetLastWriteTime(ProjectFilePath)) if (LastProjectFileWriteTimeUtc < File.GetLastWriteTimeUtc(ProjectFilePath))
{ {
return true; return true;
} }
@ -42,7 +42,7 @@ namespace Microsoft.DotNet.ProjectModel
return true; return true;
} }
if (LastLockFileWriteTime < File.GetLastWriteTime(LockFilePath)) if (LastLockFileWriteTimeUtc < File.GetLastWriteTimeUtc(LockFilePath))
{ {
return true; return true;
} }
@ -57,8 +57,8 @@ namespace Microsoft.DotNet.ProjectModel
ProjectContexts.Clear(); ProjectContexts.Clear();
ProjectFilePath = null; ProjectFilePath = null;
LockFilePath = null; LockFilePath = null;
LastLockFileWriteTime = DateTime.MinValue; LastLockFileWriteTimeUtc = DateTime.MinValue;
LastProjectFileWriteTime = DateTime.MinValue; LastProjectFileWriteTimeUtc = DateTime.MinValue;
ProjectDiagnostics.Clear(); ProjectDiagnostics.Clear();
} }
} }

View file

@ -180,7 +180,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
currentEntry.Model = project; currentEntry.Model = project;
currentEntry.FilePath = project.ProjectFilePath; currentEntry.FilePath = project.ProjectFilePath;
currentEntry.UpdateLastWriteTime(); currentEntry.UpdateLastWriteTimeUtc();
} }
} }
@ -206,7 +206,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName); currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName);
currentEntry.Model = LockFileReader.Read(currentEntry.FilePath); currentEntry.Model = LockFileReader.Read(currentEntry.FilePath);
currentEntry.UpdateLastWriteTime(); currentEntry.UpdateLastWriteTimeUtc();
} }
} }
@ -248,13 +248,13 @@ namespace Microsoft.DotNet.ProjectModel
currentEntry.Project = project; currentEntry.Project = project;
currentEntry.ProjectFilePath = project.ProjectFilePath; currentEntry.ProjectFilePath = project.ProjectFilePath;
currentEntry.LastProjectFileWriteTime = File.GetLastWriteTime(currentEntry.ProjectFilePath); currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath);
var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName); var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName);
if (File.Exists(lockFilePath)) if (File.Exists(lockFilePath))
{ {
currentEntry.LockFilePath = lockFilePath; currentEntry.LockFilePath = lockFilePath;
currentEntry.LastLockFileWriteTime = File.GetLastWriteTime(lockFilePath); currentEntry.LastLockFileWriteTimeUtc = File.GetLastWriteTimeUtc(lockFilePath);
} }
currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics); currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics);
@ -265,7 +265,7 @@ namespace Microsoft.DotNet.ProjectModel
private class FileModelEntry<TModel> where TModel : class private class FileModelEntry<TModel> where TModel : class
{ {
private DateTime _lastWriteTime; private DateTime _lastWriteTimeUtc;
public TModel Model { get; set; } public TModel Model { get; set; }
@ -273,9 +273,9 @@ namespace Microsoft.DotNet.ProjectModel
public List<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>(); 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 public bool IsInvalid
@ -292,7 +292,7 @@ namespace Microsoft.DotNet.ProjectModel
return true; return true;
} }
return _lastWriteTime < File.GetLastWriteTime(FilePath); return _lastWriteTimeUtc < File.GetLastWriteTimeUtc(FilePath);
} }
} }
@ -301,7 +301,7 @@ namespace Microsoft.DotNet.ProjectModel
Model = null; Model = null;
FilePath = null; FilePath = null;
Diagnostics.Clear(); Diagnostics.Clear();
_lastWriteTime = DateTime.MinValue; _lastWriteTimeUtc = DateTime.MinValue;
} }
} }

View file

@ -5,12 +5,11 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.Compiler.Common;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Compiler;
using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Tools.Compiler;
namespace Microsoft.DotNet.Tools.Build namespace Microsoft.DotNet.Tools.Build
{ {
@ -115,21 +114,21 @@ namespace Microsoft.DotNet.Tools.Build
// find the output with the earliest write time // find the output with the earliest write time
var minOutputPath = compilerIO.Outputs.First(); var minOutputPath = compilerIO.Outputs.First();
var minDate = File.GetLastWriteTime(minOutputPath); var minDateUtc = File.GetLastWriteTimeUtc(minOutputPath);
foreach (var outputPath in compilerIO.Outputs) foreach (var outputPath in compilerIO.Outputs)
{ {
if (File.GetLastWriteTime(outputPath) >= minDate) if (File.GetLastWriteTimeUtc(outputPath) >= minDateUtc)
{ {
continue; continue;
} }
minDate = File.GetLastWriteTime(outputPath); minDateUtc = File.GetLastWriteTimeUtc(outputPath);
minOutputPath = outputPath; minOutputPath = outputPath;
} }
// find inputs that are older than the earliest output // 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()) 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.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();
Reporter.Verbose.WriteLine($" Oldest output item:"); Reporter.Verbose.WriteLine($" Oldest output item:");
Reporter.Verbose.WriteLine($" {minDate}: {minOutputPath}"); Reporter.Verbose.WriteLine($" {minDateUtc.ToLocalTime()}: {minOutputPath}");
Reporter.Verbose.WriteLine(); Reporter.Verbose.WriteLine();
Reporter.Verbose.WriteLine($" Inputs newer than the oldest output item:"); Reporter.Verbose.WriteLine($" Inputs newer than the oldest output item:");

View file

@ -2,16 +2,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; 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.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
namespace Microsoft.DotNet.Tests.EndToEnd namespace Microsoft.DotNet.Tests.EndToEnd
{ {
@ -62,16 +58,16 @@ namespace Microsoft.DotNet.Tests.EndToEnd
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false); var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles( var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(
binariesOutputDirectory); binariesOutputDirectory);
// second build; should get skipped (incremental because no inputs changed) // second build; should get skipped (incremental because no inputs changed)
buildCommand.Execute().Should().Pass(); buildCommand.Execute().Should().Pass();
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles( var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(
binariesOutputDirectory); binariesOutputDirectory);
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild); Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild);
TouchSourceFileInDirectory(TestDirectory); TouchSourceFileInDirectory(TestDirectory);
@ -79,9 +75,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd
buildCommand.Execute().Should().Pass(); buildCommand.Execute().Should().Pass();
TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
var latestWriteTimeThirdBuild = GetLastWriteTimeOfDirectoryFiles( var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles(
binariesOutputDirectory); binariesOutputDirectory);
Assert.NotEqual(latestWriteTimeSecondBuild, latestWriteTimeThirdBuild); Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild);
} }
[Fact] [Fact]
@ -134,15 +130,15 @@ namespace Microsoft.DotNet.Tests.EndToEnd
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory); var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
// second build; should be skipped because nothing changed // second build; should be skipped because nothing changed
buildCommand.Execute().Should().Pass(); buildCommand.Execute().Should().Pass();
TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory); var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild); Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild);
} }
[Fact] [Fact]
@ -224,9 +220,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd
return false; 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) private static void TouchSourceFileInDirectory(string directory)