Skip to content

Commit 3408f7b

Browse files
[BOLT] Guard llvm-bolt-wrapper logic of NFC-Mode behind a flag (#146209)
Buildbot (`BOLTBuilder`) no longer relies on a wrapper script to run tests. This patch guards the wrapper logic under a flag that is disabled by default. This it allows to: - Eliminate the need for special handling in some tests. - Fix the issue of a wrapper loop (described below) - Simplify the NFC-Mode setup. **Background:** Previously, tests ran unconditionally, which also compiled any missing utilities and the unit tests. The `nfc-check-setup.py` created: - `llvm-bolt.new`, renamed from the current compilation - `llvm-bolt.old`, built from the previous SHA - `llvm-bolt`: a python wrapper pointing to `llvm-bolt.new` Current behaviour and wrapper issue: As before, the old/new binaries identify whether a patch affects BOLT. If so, `ninja check-bolt` builds missing dependencies and run tests, overwriting the `llvm-bolt` wrapper with a binary. However, if Ninja reports: ``` ninja: no work to do. ``` the wrapper remains in place. If the next commit also does no work, `nfc-check-setup.py` renames the existing wrapper to `llvm-bolt.new`, causing an infinite loop. Allowing to disable the wrapper logic prevents this scenario and simplifies the flow. **Test plan:** Creates llvm-bolt.new and llvm-bolt.old and stays on previous revision: ``` ./nfc-check-setup.py build ``` Creates llvm-bolt.new and llvm-bolt.old and returns on current revision: ``` ./nfc-check-setup.py build --switch-back ``` Creates llvm-bolt.new and llvm-bolt.old, returns on current revision, and creates a wrapper: ``` ./nfc-check-setup.py build --switch-back --create-wrapper ``` Creates llvm-bolt.new and llvm-bolt.old, and passes an invalid argument to the wrapper: ``` ./nfc-check-setup.py build --switch-back --create-wrapper --random-arg ```
1 parent 03a1708 commit 3408f7b

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

bolt/utils/nfc-check-setup.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def main():
4848
description=textwrap.dedent(
4949
"""
5050
This script builds two versions of BOLT (with the current and
51-
previous revision) and sets up symlink for llvm-bolt-wrapper.
52-
Passes the options through to llvm-bolt-wrapper.
51+
previous revision).
5352
"""
5453
)
5554
)
@@ -59,6 +58,12 @@ def main():
5958
default=os.getcwd(),
6059
help="Path to BOLT build directory, default is current " "directory",
6160
)
61+
parser.add_argument(
62+
"--create-wrapper",
63+
default=False,
64+
action="store_true",
65+
help="Sets up llvm-bolt as a symlink to llvm-bolt-wrapper. Passes the options through to llvm-bolt-wrapper.",
66+
)
6267
parser.add_argument(
6368
"--check-bolt-sources",
6469
default=False,
@@ -76,7 +81,12 @@ def main():
7681
default="HEAD^",
7782
help="Revision to checkout to compare vs HEAD",
7883
)
84+
85+
# When creating a wrapper, pass any unknown arguments to it. Otherwise, die.
7986
args, wrapper_args = parser.parse_known_args()
87+
if not args.create_wrapper and len(wrapper_args) > 0:
88+
parser.parse_args()
89+
8090
bolt_path = f"{args.build_dir}/bin/llvm-bolt"
8191

8292
source_dir = None
@@ -89,8 +99,6 @@ def main():
8999
if not source_dir:
90100
sys.exit("Source directory is not found")
91101

92-
script_dir = os.path.dirname(os.path.abspath(__file__))
93-
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
94102
# build the current commit
95103
subprocess.run(
96104
shlex.split("cmake --build . --target llvm-bolt"), cwd=args.build_dir
@@ -131,15 +139,25 @@ def main():
131139
)
132140
# rename llvm-bolt
133141
os.replace(bolt_path, f"{bolt_path}.old")
134-
# set up llvm-bolt-wrapper.ini
135-
ini = subprocess.check_output(
136-
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new") + wrapper_args,
137-
text=True,
138-
)
139-
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
140-
f.write(ini)
142+
141143
# symlink llvm-bolt-wrapper
142-
os.symlink(wrapper_path, bolt_path)
144+
if args.create_wrapper:
145+
script_dir = os.path.dirname(os.path.abspath(__file__))
146+
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
147+
try:
148+
# set up llvm-bolt-wrapper.ini
149+
ini = subprocess.check_output(
150+
shlex.split(f"{wrapper_path} {bolt_path}.old {bolt_path}.new")
151+
+ wrapper_args,
152+
text=True,
153+
)
154+
with open(f"{args.build_dir}/bin/llvm-bolt-wrapper.ini", "w") as f:
155+
f.write(ini)
156+
# symlink llvm-bolt-wrapper
157+
os.symlink(wrapper_path, bolt_path)
158+
except Exception as e:
159+
sys.exit("Failed to create a wrapper:\n" + str(e))
160+
143161
if args.switch_back:
144162
if stash:
145163
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)

0 commit comments

Comments
 (0)