[PATCH] D118516: [BOLT] Add nfc-check-setup script

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 4 18:03:43 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f928cbac259: [BOLT] Add nfc-check-setup script (authored by Amir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118516/new/

https://reviews.llvm.org/D118516

Files:
  bolt/utils/nfc-check-setup.py


Index: bolt/utils/nfc-check-setup.py
===================================================================
--- /dev/null
+++ bolt/utils/nfc-check-setup.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+import argparse
+import os
+import re
+import shlex
+import subprocess
+import sys
+import textwrap
+
+
+def main():
+    parser = argparse.ArgumentParser(description=textwrap.dedent('''
+            This script builds two versions of BOLT (with the current and
+            previous revision) and sets up symlink for llvm-bolt-wrapper.
+            Passes the options through to llvm-bolt-wrapper.
+            '''))
+    parser.add_argument('build_dir', nargs='?', default=os.getcwd(),
+                        help='Path to BOLT build directory, default is current directory')
+    args, wrapper_args = parser.parse_known_args()
+    bolt_path = f'{args.build_dir}/bin/llvm-bolt'
+
+    source_dir = None
+    # find the repo directory
+    with open(f'{args.build_dir}/CMakeCache.txt') as f:
+        for line in f:
+            m = re.match(r'LLVM_SOURCE_DIR:STATIC=(.*)', line)
+            if m:
+                source_dir = m.groups()[0]
+    if not source_dir:
+        sys.exit("Source directory is not found")
+
+    wrapper_path = os.path.abspath(
+        f'{source_dir}/../bolt/utils/llvm-bolt-wrapper.py')
+    # build the current commit
+    subprocess.run(shlex.split("cmake --build . --target llvm-bolt"),
+                   cwd=args.build_dir)
+    # rename llvm-bolt
+    os.replace(bolt_path, f'{bolt_path}.new')
+    # check out the previous commit
+    subprocess.run(shlex.split("git checkout -f HEAD^"),
+                   cwd=source_dir)
+    # build the previous commit
+    subprocess.run(shlex.split("cmake --build . --target llvm-bolt"),
+                   cwd=args.build_dir)
+    # rename llvm-bolt
+    os.replace(bolt_path, f'{bolt_path}.old')
+    # set up llvm-bolt-wrapper.ini
+    ini = subprocess.check_output(
+        shlex.split(
+            f"{wrapper_path} {bolt_path}.old {bolt_path}.new") + wrapper_args,
+        text=True)
+    with open(f'{args.build_dir}/bin/llvm-bolt-wrapper.ini', 'w') as f:
+        f.write(ini)
+    # symlink llvm-bolt-wrapper
+    os.symlink(wrapper_path, bolt_path)
+
+
+if __name__ == "__main__":
+    main()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118516.406138.patch
Type: text/x-patch
Size: 2284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220205/497feee2/attachment.bin>


More information about the llvm-commits mailing list