Skip to content

[BOLT] Guard llvm-bolt-wrapper logic of NFC-Mode behind a flag #146209

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 30 additions & 12 deletions bolt/utils/nfc-check-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def main():
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.
previous revision).
"""
)
)
Expand All @@ -59,6 +58,12 @@ def main():
default=os.getcwd(),
help="Path to BOLT build directory, default is current " "directory",
)
parser.add_argument(
"--create-wrapper",
default=False,
action="store_true",
help="Sets up llvm-bolt as a symlink to llvm-bolt-wrapper. Passes the options through to llvm-bolt-wrapper.",
)
parser.add_argument(
"--check-bolt-sources",
default=False,
Expand All @@ -76,7 +81,12 @@ def main():
default="HEAD^",
help="Revision to checkout to compare vs HEAD",
)

# When creating a wrapper, pass any unknown arguments to it. Otherwise, die.
args, wrapper_args = parser.parse_known_args()
if not args.create_wrapper and len(wrapper_args) > 0:
parser.parse_args()

bolt_path = f"{args.build_dir}/bin/llvm-bolt"

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

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
Expand Down Expand Up @@ -131,15 +139,25 @@ def main():
)
# 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 args.create_wrapper:
script_dir = os.path.dirname(os.path.abspath(__file__))
wrapper_path = f"{script_dir}/llvm-bolt-wrapper.py"
try:
# 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)
except Exception as e:
sys.exit("Failed to create a wrapper:\n" + str(e))

if args.switch_back:
if stash:
subprocess.run(shlex.split("git stash pop"), cwd=source_dir)
Expand Down
Loading