@@ -267,39 +267,53 @@ 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
281- # For Linux and FreeBSD only, determine the version of the installed
282- # CMake compared to the source and build the source if necessary.
283- # Returns the path to the cmake binary.
284- def check_cmake_version (self , source_root , build_root ):
285- if not platform .system () in ["Linux" , "FreeBSD" ]:
286- return
285+ # Get the path to CMake to use for the build
286+ # This function will not build CMake for Apple platforms.
287+ # For other platforms, this builds CMake if a new enough version is not
288+ # available.
289+ def get_cmake_path (self , source_root , build_root ):
290+ if platform .system () == 'Darwin' :
291+ return self .toolchain .cmake
287292
288293 cmake_source_dir = os .path .join (source_root , 'cmake' )
289- # If the source is not checked out then don't attempt to build cmake.
290294 if not os .path .isdir (cmake_source_dir ):
291- return
292-
293- cmake_binary = 'cmake'
294- try :
295- if self .args .cmake is not None :
296- cmake_binary = self .args .cmake
297- except AttributeError :
298- cmake_binary = 'cmake'
299-
300- installed_ver = self .installed_cmake_version (cmake_binary )
301- if installed_ver >= self .cmake_source_version (cmake_source_dir ):
302- return
303- else :
304- # Build CMake from source and return the path to the executable.
305- return self .build_cmake (source_root , build_root )
295+ return self .toolchain .cmake
296+
297+ cmake_required_version = self .cmake_source_version (cmake_source_dir )
298+
299+ # If we have already built a CMake, see if that is new enough. If it is,
300+ # we don't need to build it again. This is a good indication that the
301+ # system either doesn't have a CMake installed or it wasn't new enough
302+ # so prefer our built CMake first.
303+ cmake_built_path = os .path .join (build_root ,
304+ f'cmake-{ self .args .host_target } ' ,
305+ 'bin' , 'cmake' )
306+ if os .path .isfile (cmake_built_path ):
307+ cmake_built_version = self .installed_cmake_version (cmake_built_path )
308+ if cmake_built_version >= cmake_required_version :
309+ return cmake_built_path
310+
311+ # If we already have a new enough CMake installed on the system, use it
312+ if self .toolchain .cmake is not None :
313+ cmake_installed_version = self .installed_cmake_version (self .toolchain .cmake )
314+ if cmake_installed_version >= cmake_required_version :
315+ return self .toolchain .cmake
316+
317+ # The pre-installed CMake isn't new enough. Build one from our sources
318+ # and return the path to that.
319+ return self .build_cmake (source_root , build_root )
0 commit comments