forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[xa-prep-tasks] implemented GitCommitTime task
Context: dotnet#181 (in comments) In several places throughout the build, we are running a command such as `<Exec Command="touch -m -t `git log -1 --format=%25cd --date=format-local:%25Y%25m%25d%25H%25M.%25S` Makefile" />`, which will not work on Windows. The solution is to create an MSBuild task in xa-prep-tasks named `GitCommitTime` that will work cross-platform. `GitCommitTime` returns a string value that can be passed to the `Touch` MSBuild task.
- Loading branch information
1 parent
024db5f
commit 3e49396
Showing
8 changed files
with
86 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/GitCommitTime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
|
||
using Microsoft.Build.Framework; | ||
|
||
namespace Xamarin.Android.BuildTools.PrepTasks | ||
{ | ||
public sealed class GitCommitTime : Git | ||
{ | ||
[Output] | ||
public string Time { get; set; } | ||
|
||
protected override bool LogTaskMessages { | ||
get { return false; } | ||
} | ||
|
||
public GitCommitTime () | ||
{ | ||
} | ||
|
||
public override bool Execute () | ||
{ | ||
Log.LogMessage (MessageImportance.Low, $"Task {nameof (GitCommitTime)}"); | ||
Log.LogMessage (MessageImportance.Low, $" {nameof (WorkingDirectory)}: {WorkingDirectory.ItemSpec}"); | ||
|
||
base.Execute (); | ||
|
||
Log.LogMessage (MessageImportance.High, $" [Output] {nameof (Time)}: {Time}"); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
protected override string GenerateCommandLineCommands () | ||
{ | ||
//NOTE: this command needs to return a string that is valid to pass to DateTime.Parse() | ||
// The <Touch> MSBuild task requires this: https://docs.microsoft.com/en-us/visualstudio/msbuild/touch-task | ||
return "log -1 --format=%cd --date=format-local:\"%Y/%m/%d %H:%M:%S\""; | ||
} | ||
|
||
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) | ||
{ | ||
if (string.IsNullOrEmpty (singleLine)) | ||
return; | ||
Time = singleLine; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters