Skip to content

Commit 6105077

Browse files
authored
build-script: validate arguments before running sccache (#61375)
When a user passes `--sccache` flag when `sccache` is not installed, we still attempt to make a shell invocation to `sccache`, which leads to an inscrutable error: ``` Traceback (most recent call last): File "/root/swift-source/swift/utils/build-script", line 789, in <module> exit_code = main() File "/root/swift-source/swift/utils/build-script", line 784, in main return main_normal() File "/root/swift-source/swift/utils/build-script", line 687, in main_normal shell.capture([toolchain.sccache, "--show-stats"]) File "/root/swift-source/swift/utils/swift_build_support/swift_build_support/shell.py", line 133, in capture return subprocess.check_output(command, env=_env, stderr=stderr, File "/usr/lib/python3.10/subprocess.py", line 420, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 501, in run with Popen(*popenargs, **kwargs) as process: File "/usr/lib/python3.10/subprocess.py", line 969, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.10/subprocess.py", line 1720, in _execute_child and os.path.dirname(executable) File "/usr/lib/python3.10/posixpath.py", line 152, in dirname p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType ``` `validate_arguments` should be called before `shell.capture([toolchain.sccache, "--show-stats"])` so that a more meaningful error message is shown to the user, asking them to install `sccache`.
1 parent b9cce00 commit 6105077

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

utils/build-script

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,6 @@ def main_normal():
679679
toolchain.libtool = args.host_libtool
680680
if args.cmake is not None:
681681
toolchain.cmake = args.cmake
682-
if args.sccache:
683-
print("Ensuring the sccache server is running...")
684-
# Use --show-stats to ensure the server is started, because using
685-
# --start-server will fail if the server is already running.
686-
# Capture the output because we don't want to see the stats.
687-
shell.capture([toolchain.sccache, "--show-stats"])
688682

689683
cmake = CMake(args=args, toolchain=toolchain)
690684
# Check the CMake version is sufficient on Linux and build from source
@@ -700,6 +694,13 @@ def main_normal():
700694
# Validate the arguments.
701695
validate_arguments(toolchain, args)
702696

697+
if args.sccache:
698+
print("Ensuring the sccache server is running...")
699+
# Use --show-stats to ensure the server is started, because using
700+
# --start-server will fail if the server is already running.
701+
# Capture the output because we don't want to see the stats.
702+
shell.capture([toolchain.sccache, "--show-stats"])
703+
703704
# Create the build script invocation.
704705
invocation = build_script_invocation.BuildScriptInvocation(toolchain, args)
705706

0 commit comments

Comments
 (0)