Skip to content

Commit 7e9b763

Browse files
committed
Include branch and commit hash in the .ident string
1 parent e6de349 commit 7e9b763

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

build-tools/scripts/XABuildConfig.cs.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Xamarin.Android.Tools
99
public const string NDKRevision = "@NDK_REVISION@";
1010
public const string NDKRelease = "@NDK_RELEASE@";
1111
public const string XamarinAndroidVersion = "@XAMARIN_ANDROID_VERSION@";
12+
public const string XamarinAndroidCommitHash = "@XAMARIN_ANDROID_COMMIT_HASH@";
13+
public const string XamarinAndroidBranch = "@XAMARIN_ANDROID_BRANCH@";
1214
public const int NDKMinimumApiAvailable = @NDK_MINIMUM_API_AVAILABLE@;
1315
public const int AndroidLatestStableApiLevel = @ANDROID_LATEST_STABLE_API_LEVEL@;
1416
public static readonly Version NDKVersion = new Version (@NDK_VERSION_MAJOR@, @NDK_VERSION_MINOR@, @NDK_VERSION_MICRO@);

build-tools/xaprepare/xaprepare/Application/BuildInfo.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ partial class BuildInfo : AppObject
2525
public string MonoHash { get; private set; } = String.Empty;
2626
public string FullMonoHash { get; private set; } = String.Empty;
2727

28+
public string XACommitHash { get; private set; } = String.Empty;
29+
public string XABranch { get; private set; } = String.Empty;
30+
2831
public async Task GatherGitInfo (Context context)
2932
{
3033
if (context == null)
@@ -36,6 +39,14 @@ public async Task GatherGitInfo (Context context)
3639
Log.StatusLine ();
3740
DetermineMonoHash (context);
3841
Log.StatusLine ();
42+
DetermineXACommitInfo (context);
43+
}
44+
45+
void DetermineXACommitInfo (Context context)
46+
{
47+
GitRunner git = CreateGitRunner (context);
48+
XACommitHash = git.GetTopCommitHash (shortHash: false);
49+
XABranch = git.GetBranchName ();
3950
}
4051

4152
public bool GatherNDKInfo (Context context)

build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
168168
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
169169
{ "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) },
170170
{ "@XAMARIN_ANDROID_VERSION@", context.Properties.GetRequiredValue (KnownProperties.ProductVersion) },
171+
{ "@XAMARIN_ANDROID_COMMIT_HASH@", context.BuildInfo.XACommitHash },
172+
{ "@XAMARIN_ANDROID_BRANCH@", context.BuildInfo.XABranch },
171173
};
172174

173175
return new GeneratedPlaceholdersFile (

build-tools/xaprepare/xaprepare/ToolRunners/GitRunner.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,33 @@ public async Task<bool> SubmoduleUpdate (string? workingDirectory = null, bool i
135135
return await RunGit (runner, "submodule-update");
136136
}
137137

138+
public string GetBranchName (string? workingDirectory = null)
139+
{
140+
string runnerWorkingDirectory = DetermineRunnerWorkingDirectory (workingDirectory);
141+
var runner = CreateGitRunner (runnerWorkingDirectory);
142+
runner
143+
.AddArgument ("name-rev")
144+
.AddArgument ("--name-only")
145+
.AddArgument ("--exclude=tags/*")
146+
.AddArgument ("HEAD");
147+
148+
string branchName = String.Empty;
149+
using (var outputSink = (OutputSink)SetupOutputSink (runner)) {
150+
outputSink.LineCallback = (string? line) => {
151+
if (!String.IsNullOrEmpty (branchName)) {
152+
return;
153+
}
154+
branchName = line?.Trim () ?? String.Empty;
155+
};
156+
157+
if (!runner.Run ()) {
158+
return String.Empty;
159+
}
160+
161+
return branchName;
162+
}
163+
}
164+
138165
public string GetTopCommitHash (string? workingDirectory = null, bool shortHash = true)
139166
{
140167
string runnerWorkingDirectory = DetermineRunnerWorkingDirectory (workingDirectory);

src/Xamarin.Android.Build.Tasks/Utilities/NativeAssemblyGenerator/NativeAssemblyGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public virtual void WriteFileEnd ()
224224
Output.WriteLine ();
225225
}
226226

227-
WriteDirective (".ident", QuoteString ($"Xamarin.Android {XABuildConfig.XamarinAndroidVersion}"));
227+
WriteDirective (".ident", QuoteString ($"Xamarin.Android {XABuildConfig.XamarinAndroidBranch} @ {XABuildConfig.XamarinAndroidCommitHash}"));
228228
}
229229

230230
NativeType GetNativeType<T> ()

0 commit comments

Comments
 (0)