Skip to content

Commit 8cde1cf

Browse files
authored
[AIX] Add git revision to .file string (#88164)
If `LLVM_APPEND_VC_REV` is on, add the git revision to the `.file` string. The revision can be set with `LLVM_FORCE_VC_REVISION`. Before: `.file "git_revision.cpp",,"LLVM version 19.0.0git"` After: `.file "git_revision.cpp",,"LLVM version 19.0.0git (LLVM_REVISION)"`
1 parent 75f7295 commit 8cde1cf

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "llvm/Support/MathExtras.h"
115115
#include "llvm/Support/Path.h"
116116
#include "llvm/Support/Timer.h"
117+
#include "llvm/Support/VCSRevision.h"
117118
#include "llvm/Support/raw_ostream.h"
118119
#include "llvm/Target/TargetLoweringObjectFile.h"
119120
#include "llvm/Target/TargetMachine.h"
@@ -497,12 +498,15 @@ bool AsmPrinter::doInitialization(Module &M) {
497498
else
498499
FileName = M.getSourceFileName();
499500
if (MAI->hasFourStringsDotFile()) {
500-
#ifdef PACKAGE_VENDOR
501501
const char VerStr[] =
502-
PACKAGE_VENDOR " " PACKAGE_NAME " version " PACKAGE_VERSION;
503-
#else
504-
const char VerStr[] = PACKAGE_NAME " version " PACKAGE_VERSION;
502+
#ifdef PACKAGE_VENDOR
503+
PACKAGE_VENDOR " "
504+
#endif
505+
PACKAGE_NAME " version " PACKAGE_VERSION
506+
#ifdef LLVM_REVISION
507+
" (" LLVM_REVISION ")"
505508
#endif
509+
;
506510
// TODO: Add timestamp and description.
507511
OutStreamer->emitFileDirective(FileName, VerStr, "", "");
508512
} else {

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ llvm_canonicalize_cmake_booleans(
2525
LLVM_INCLUDE_DXIL_TESTS
2626
LLVM_TOOL_LLVM_DRIVER_BUILD
2727
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
28+
LLVM_APPEND_VC_REV
2829
)
2930

3031
configure_lit_site_cfg(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; Check that the git revision is contained in the assembly/object files
2+
3+
; REQUIRES: vc-rev-enabled
4+
5+
; RUN: llc < %s | FileCheck %s -DREVISION=git-revision
6+
; RUN: llc -filetype=obj < %s | FileCheck %s -DREVISION=git-revision
7+
8+
; CHECK: ([[REVISION]])
9+
10+
source_filename = "git_revision.cpp"
11+
target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512"
12+
target triple = "powerpc64-ibm-aix7.2.0.0"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
if not "PowerPC" in config.root.targets:
22
config.unsupported = True
33

4+
import subprocess
5+
46
config.suffixes.add(".py")
7+
8+
def get_revision(repo_path):
9+
cmd = ['git', '-C', repo_path, 'rev-parse', 'HEAD']
10+
try:
11+
return subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode()
12+
except subprocess.CalledProcessError:
13+
print("An error occurred retrieving the git revision.")
14+
return None
15+
16+
if config.have_vc_rev:
17+
if config.force_vc_rev:
18+
git_revision = config.force_vc_rev
19+
else:
20+
git_revision = get_revision(config.llvm_src_root)
21+
if git_revision:
22+
config.substitutions.append(("git-revision", git_revision))
23+
config.available_features.add("vc-rev-enabled")

llvm/test/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
6161
config.dxil_tests = @LLVM_INCLUDE_DXIL_TESTS@
6262
config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
6363
config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
64+
config.have_vc_rev = @LLVM_APPEND_VC_REV@
65+
config.force_vc_rev = "@LLVM_FORCE_VC_REVISION@"
6466

6567
import lit.llvm
6668
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)