Skip to content

[AIX] Add git revision to .file string #88164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/PowerPC/git_revision.ll
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/PowerPC/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions llvm/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down