Skip to content

Commit 71b7725

Browse files
committed
[build-script] Log CMake Bootstrap build time
Include the CMake bootstrap time in the build-script build times. We're including everything else. Would be good to determine how much time we can save by caching a new enough pre-built CMake in the builder images. Importing the log_time_in_scope exposes a cyclic dependency cycle between the `swift_build_support` and `build_swift` python modules in such a way that the tests fail due to re-importing parts of build_swift: ``` ImportError: Failed to import test module: tests.build_swift.test_migration Traceback (most recent call last): File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path module = self._get_module_from_name(name) File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name __import__(name) File "/home/build-user/swift/utils/build_swift/tests/build_swift/test_migration.py", line 14, in <module> from build_swift import migration File "/home/build-user/swift/utils/build_swift/build_swift/migration.py", line 18, in <module> from swift_build_support.swift_build_support.targets import \ File "/home/build-user/swift/utils/swift_build_support/swift_build_support/targets.py", line 15, in <module> from . import cmake File "/home/build-user/swift/utils/swift_build_support/swift_build_support/cmake.py", line 26, in <module> from swift_build_support.swift_build_support.utils import log_time_in_scope File "/home/build-user/swift/utils/swift_build_support/swift_build_support/utils.py", line 20, in <module> from build_swift.build_swift.constants import SWIFT_BUILD_ROOT ModuleNotFoundError: No module named 'build_swift.build_swift' ``` I've put the import of log_time_in_scope into the function definition to ensure that build_swift has been fully loaded by the time we need log_time_in_scope, ensuring that there is order between the two pieces. Python caches the imported module, so if we accidentally re-import the log_time_in_scope, nothing actually changes. This re-orders the instantiation of the BuildScriptInvocation object so that it comes before the creation of the CMake path. This ensures that BuildScriptInvocation() does not delete the build log after logging the CMake bootstrap time. This is fine because the toolchain and arguments are reference types, so updating the CMake path in both of those will be reflected in the copy taken in the BuildScriptInvocation() object.
1 parent c7ddbee commit 71b7725

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

utils/build-script

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,12 @@ def main_normal():
695695
if args.cmake is not None:
696696
toolchain.cmake = args.cmake
697697

698+
# Preprocess the arguments to apply defaults.
699+
apply_default_arguments(toolchain, args)
700+
701+
# Create the build script invocation.
702+
invocation = build_script_invocation.BuildScriptInvocation(toolchain, args)
703+
698704
cmake = CMake(args=args, toolchain=toolchain)
699705
# Check the CMake version is sufficient on Linux and build from source
700706
# if not.
@@ -703,9 +709,6 @@ def main_normal():
703709
toolchain.cmake = cmake_path
704710
args.cmake = cmake_path
705711

706-
# Preprocess the arguments to apply defaults.
707-
apply_default_arguments(toolchain, args)
708-
709712
# Validate the arguments.
710713
validate_arguments(toolchain, args)
711714

@@ -716,9 +719,6 @@ def main_normal():
716719
# Capture the output because we don't want to see the stats.
717720
shell.capture([toolchain.sccache, "--show-stats"])
718721

719-
# Create the build script invocation.
720-
invocation = build_script_invocation.BuildScriptInvocation(toolchain, args)
721-
722722
# Sanitize the runtime environment.
723723
initialize_runtime_environment()
724724

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,18 @@ def build_cmake(self, source_root, build_root):
267267
if not os.path.isdir(cmake_build_dir):
268268
os.makedirs(cmake_build_dir)
269269

270-
cwd = os.getcwd()
271-
os.chdir(cmake_build_dir)
272-
build_jobs = self.args.build_jobs or multiprocessing.cpu_count()
273-
shell.call_without_sleeping([cmake_bootstrap, '--no-qt-gui',
274-
'--parallel=%s' % build_jobs, '--',
275-
'-DCMAKE_USE_OPENSSL=OFF'], echo=True)
276-
shell.call_without_sleeping(['make', '-j%s' % build_jobs],
277-
echo=True)
270+
print("--- Bootstrap Local CMake ---", flush=True)
271+
from swift_build_support.swift_build_support.utils \
272+
import log_time_in_scope
273+
with log_time_in_scope("Bootstrap Local CMake"):
274+
cwd = os.getcwd()
275+
os.chdir(cmake_build_dir)
276+
build_jobs = self.args.build_jobs or multiprocessing.cpu_count()
277+
shell.call_without_sleeping([cmake_bootstrap, '--no-qt-gui',
278+
'--parallel=%s' % build_jobs, '--',
279+
'-DCMAKE_USE_OPENSSL=OFF'], echo=True)
280+
shell.call_without_sleeping(['make', '-j%s' % build_jobs],
281+
echo=True)
278282
os.chdir(cwd)
279283
return os.path.join(cmake_build_dir, 'bin', 'cmake')
280284

0 commit comments

Comments
 (0)