[PATCH] D95507: [utils] collect_and_build_with_pgo.py: Print shell commands

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 22:26:05 PST 2021


kazu created this revision.
kazu added reviewers: MaskRay, kristof.beyls, george.burgess.iv.
Herald added a subscriber: wenlei.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch teaches collect_and_build_with_pgo.py to print shell
commands on --dry-run like:

  (cd /home/kazu/llvm-project/llvm/out/instrumented &&
    ninja check-llvm check-clang)

instead of messages like:

  Running `['ninja', 'check-llvm', 'check-clang']` in
  /home/kazu/llvm-project/llvm/out/instrumented

This way, we could use the python script to generate a shell script
and debug things in the shell script form before updating the python
script.  As another use case, we could use the shell script as a
starting point when we wish to heavily customize the build process.
For example, we could reuse the same profile to build several versions
of the optimized compiler with different sets of compiler flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95507

Files:
  llvm/utils/collect_and_build_with_pgo.py


Index: llvm/utils/collect_and_build_with_pgo.py
===================================================================
--- llvm/utils/collect_and_build_with_pgo.py
+++ llvm/utils/collect_and_build_with_pgo.py
@@ -164,8 +164,8 @@
                     cwd=None,
                     check=False,
                     silent_unless_error=False):
-        print(
-            'Running `%s` in %s' % (cmd, shlex.quote(cwd or os.getcwd())))
+        print('(cd %s && %s)' % (shlex.quote(cwd or os.getcwd()),
+                                 ' '.join([shlex.quote(arg) for arg in cmd])))
 
         if self.dry_run:
             return
@@ -236,7 +236,10 @@
 
 
 def _run_fresh_cmake(env, cmake, target_dir):
-    if not env.dry_run:
+    if env.dry_run:
+        print('rm -rf %s' % shlex.quote(target_dir))
+        print('mkdir -p %s' % shlex.quote(target_dir))
+    else:
         try:
             shutil.rmtree(target_dir)
         except FileNotFoundError:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95507.319468.patch
Type: text/x-patch
Size: 954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210127/3ae7ab95/attachment.bin>


More information about the llvm-commits mailing list