[PATCH] D126941: [BOLT][UTILS] Usability improvements for nfc-check-setup

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 20:15:36 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

1. Print a message that the source repository revision has been changed, with instructions to switch back.
2. Make the script executable.
3. Print sample instructions how to run bolt tests.
4. Assume that llvm-bolt-wrapper script is in the same source directory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126941

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


Index: bolt/utils/nfc-check-setup.py
===================================================================
--- bolt/utils/nfc-check-setup.py
+++ bolt/utils/nfc-check-setup.py
@@ -7,6 +7,17 @@
 import sys
 import textwrap
 
+def get_git_ref_or_rev(dir: str) -> str:
+    # Run 'git symbolic-ref -q --short HEAD || git rev-parse --short HEAD'
+    cmd_ref = 'git symbolic-ref -q --short HEAD'
+    ref = subprocess.run(shlex.split(cmd_ref), cwd=dir, text=True,
+                         stdout=subprocess.PIPE)
+    if not ref.returncode:
+        return ref.stdout.strip()
+    cmd_rev = 'git rev-parse --short HEAD'
+    return subprocess.check_output(shlex.split(cmd_rev), cwd=dir,
+                                   text=True).strip()
+
 
 def main():
     parser = argparse.ArgumentParser(description=textwrap.dedent('''
@@ -29,16 +40,19 @@
     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')
+    script_dir = os.path.dirname(os.path.abspath(__file__))
+    wrapper_path = f'{script_dir}/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')
+    # memorize the old hash for logging
+    old_ref = get_git_ref_or_rev(source_dir)
     # check out the previous commit
-    subprocess.run(shlex.split("git checkout -f HEAD^"),
-                   cwd=source_dir)
+    subprocess.run(shlex.split("git checkout -f HEAD^"), cwd=source_dir)
+    # get the parent commit hash for logging
+    new_ref = get_git_ref_or_rev(source_dir)
     # build the previous commit
     subprocess.run(shlex.split("cmake --build . --target llvm-bolt"),
                    cwd=args.build_dir)
@@ -53,6 +67,11 @@
         f.write(ini)
     # symlink llvm-bolt-wrapper
     os.symlink(wrapper_path, bolt_path)
+    print(f"The repository {source_dir} has been switched from rev {old_ref} "
+          f"to {new_ref}.\nSwitch back using\n\tgit checkout {old_ref}\n"
+          "Current build directory is ready to run BOLT tests, e.g.\n\t"
+          "bin/llvm-lit -sv tools/bolt/test\nor\n\t"
+          "bin/llvm-lit -sv tools/bolttests")
 
 
 if __name__ == "__main__":


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126941.433941.patch
Type: text/x-patch
Size: 2355 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220603/1415212c/attachment.bin>


More information about the llvm-commits mailing list