已合并
[feat]suppport ninja #34213
一只食醉狗创建于 4月23日
[feat]suppport ninja #34213
已合并
共 2 个文件变更+15-4
| @@ -314,6 +314,7 @@ class Clean(distutils.command.clean.clean): | |||
| 314 | if os.path.exists(file_path): | 314 | if os.path.exists(file_path): |
| 315 | os.remove(file_path) | 315 | os.remove(file_path) |
| 316 | 316 | ||
| 317 | +USE_NINJA = os.environ["CMAKE_GENERATOR"].lower() == "ninja" if "CMAKE_GENERATOR" in os.environ else shutil.which("ninja") | ||
| 317 | 318 | ||
| 318 | class CPPLibBuild(build_clib, object): | 319 | class CPPLibBuild(build_clib, object): |
| 319 | def run(self): | 320 | def run(self): |
| @@ -366,8 +367,15 @@ class CPPLibBuild(build_clib, object): | |||
| 366 | if os.getenv('_ABI_VERSION') is not None: | 367 | if os.getenv('_ABI_VERSION') is not None: |
| 367 | cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION')) | 368 | cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION')) |
| 368 | 369 | ||
| 369 | - max_jobs = os.getenv("MAX_JOBS", str(multiprocessing.cpu_count())) | 370 | + if USE_NINJA: |
| 370 | - build_args = ['-j', max_jobs] | 371 | + cmake_args.append("-GNinja") |
| 372 | + | ||
| 373 | + max_jobs = os.getenv("MAX_JOBS") | ||
| 374 | + if max_jobs is not None or not USE_NINJA: | ||
| 375 | + max_jobs = max_jobs or str(multiprocessing.cpu_count()) | ||
| 376 | + build_args = ['-j', max_jobs] | ||
| 377 | + else: | ||
| 378 | + build_args = [] | ||
| 371 | 379 | ||
| 372 | subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ) | 380 | subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ) |
| 373 | for base_dir, dirs, files in os.walk(build_type_dir): | 381 | for base_dir, dirs, files in os.walk(build_type_dir): |
| @@ -378,7 +386,10 @@ class CPPLibBuild(build_clib, object): | |||
| 378 | file_path = os.path.join(base_dir, file_name) | 386 | file_path = os.path.join(base_dir, file_name) |
| 379 | os.chmod(file_path, mode=BUILD_PERMISSION) | 387 | os.chmod(file_path, mode=BUILD_PERMISSION) |
| 380 | 388 | ||
| 381 | - subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ) | 389 | + if USE_NINJA: |
| 390 | + subprocess.check_call(['ninja'] + build_args, cwd=build_type_dir, env=os.environ) | ||
| 391 | + else: | ||
| 392 | + subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ) | ||
| 382 | 393 | ||
| 383 | 394 | ||
| 384 | class Build(build_ext, object): | 395 | class Build(build_ext, object): |