[llvm] 8cde1cf - [AIX] Add git revision to .file string (#88164)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 17:37:39 PDT 2024
Author: Jake Egan
Date: 2024-04-30T20:37:35-04:00
New Revision: 8cde1cfc60e36a1b4f632d00810983f0a7eb5462
URL: https://github.com/llvm/llvm-project/commit/8cde1cfc60e36a1b4f632d00810983f0a7eb5462
DIFF: https://github.com/llvm/llvm-project/commit/8cde1cfc60e36a1b4f632d00810983f0a7eb5462.diff
LOG: [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)"`
Added:
llvm/test/CodeGen/PowerPC/git_revision.ll
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CMakeLists.txt
llvm/test/CodeGen/PowerPC/lit.local.cfg
llvm/test/lit.site.cfg.py.in
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 721d144d7f4c67..869670d43a1785 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -114,6 +114,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/VCSRevision.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
@@ -497,12 +498,15 @@ bool AsmPrinter::doInitialization(Module &M) {
else
FileName = M.getSourceFileName();
if (MAI->hasFourStringsDotFile()) {
-#ifdef PACKAGE_VENDOR
const char VerStr[] =
- PACKAGE_VENDOR " " PACKAGE_NAME " version " PACKAGE_VERSION;
-#else
- const char VerStr[] = PACKAGE_NAME " version " PACKAGE_VERSION;
+#ifdef PACKAGE_VENDOR
+ PACKAGE_VENDOR " "
+#endif
+ PACKAGE_NAME " version " PACKAGE_VERSION
+#ifdef LLVM_REVISION
+ " (" LLVM_REVISION ")"
#endif
+ ;
// TODO: Add timestamp and description.
OutStreamer->emitFileDirective(FileName, VerStr, "", "");
} else {
diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index 6127b76db06b7f..eb401351141641 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -25,6 +25,7 @@ llvm_canonicalize_cmake_booleans(
LLVM_INCLUDE_DXIL_TESTS
LLVM_TOOL_LLVM_DRIVER_BUILD
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
+ LLVM_APPEND_VC_REV
)
configure_lit_site_cfg(
diff --git a/llvm/test/CodeGen/PowerPC/git_revision.ll b/llvm/test/CodeGen/PowerPC/git_revision.ll
new file mode 100644
index 00000000000000..86dcc5048425e4
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/git_revision.ll
@@ -0,0 +1,12 @@
+; Check that the git revision is contained in the assembly/object files
+
+; REQUIRES: vc-rev-enabled
+
+; RUN: llc < %s | FileCheck %s -DREVISION=git-revision
+; RUN: llc -filetype=obj < %s | FileCheck %s -DREVISION=git-revision
+
+; CHECK: ([[REVISION]])
+
+source_filename = "git_revision.cpp"
+target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512"
+target triple = "powerpc64-ibm-aix7.2.0.0"
diff --git a/llvm/test/CodeGen/PowerPC/lit.local.cfg b/llvm/test/CodeGen/PowerPC/lit.local.cfg
index 3e8c0f8b184201..4cc802afef4a02 100644
--- a/llvm/test/CodeGen/PowerPC/lit.local.cfg
+++ b/llvm/test/CodeGen/PowerPC/lit.local.cfg
@@ -1,4 +1,23 @@
if not "PowerPC" in config.root.targets:
config.unsupported = True
+import subprocess
+
config.suffixes.add(".py")
+
+def get_revision(repo_path):
+ cmd = ['git', '-C', repo_path, 'rev-parse', 'HEAD']
+ try:
+ return subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode()
+ except subprocess.CalledProcessError:
+ print("An error occurred retrieving the git revision.")
+ return None
+
+if config.have_vc_rev:
+ if config.force_vc_rev:
+ git_revision = config.force_vc_rev
+ else:
+ git_revision = get_revision(config.llvm_src_root)
+ if git_revision:
+ config.substitutions.append(("git-revision", git_revision))
+ config.available_features.add("vc-rev-enabled")
diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in
index b6f255d472d16f..60a68b0edaf933 100644
--- a/llvm/test/lit.site.cfg.py.in
+++ b/llvm/test/lit.site.cfg.py.in
@@ -61,6 +61,8 @@ config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@
config.dxil_tests = @LLVM_INCLUDE_DXIL_TESTS@
config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
+config.have_vc_rev = @LLVM_APPEND_VC_REV@
+config.force_vc_rev = "@LLVM_FORCE_VC_REVISION@"
import lit.llvm
lit.llvm.initialize(lit_config, config)
More information about the llvm-commits
mailing list