| HERE = Path(__file__).parent.absolute() | HERE = Path(__file__).parent.absolute() | ||||
| PROJECT_ROOT = HERE.parent | PROJECT_ROOT = HERE.parent | ||||
| BUILD_DIR = PROJECT_ROOT / '_build' | BUILD_DIR = PROJECT_ROOT / '_build' | ||||
| BOOTSTRAP_DIR = BUILD_DIR / '_bootstrap' | |||||
| BOOTSTRAP_BASE_DIR = BUILD_DIR / '_bootstrap' | |||||
| PREBUILT_DIR = PROJECT_ROOT / '_prebuilt' | PREBUILT_DIR = PROJECT_ROOT / '_prebuilt' | ||||
| EXE_SUFFIX = '.exe' if os.name == 'nt' else '' | EXE_SUFFIX = '.exe' if os.name == 'nt' else '' | ||||
| raise subprocess.CalledProcessError(res.returncode, cmd) | raise subprocess.CalledProcessError(res.returncode, cmd) | ||||
| def _clone_bootstrap_phase(ph: str) -> None: | |||||
| def _clone_bootstrap_phase(ph: str) -> Path: | |||||
| print(f'Cloning: {ph}') | print(f'Cloning: {ph}') | ||||
| if BOOTSTRAP_DIR.exists(): | |||||
| shutil.rmtree(BOOTSTRAP_DIR) | |||||
| bts_dir = BOOTSTRAP_BASE_DIR / ph | |||||
| if bts_dir.exists(): | |||||
| shutil.rmtree(bts_dir) | |||||
| _run_quiet([ | _run_quiet([ | ||||
| 'git', | 'git', | ||||
| 'clone', | 'clone', | ||||
| '--depth=1', | '--depth=1', | ||||
| f'--branch={ph}', | f'--branch={ph}', | ||||
| f'file://{PROJECT_ROOT}', | f'file://{PROJECT_ROOT}', | ||||
| BOOTSTRAP_DIR, | |||||
| bts_dir, | |||||
| ]) | ]) | ||||
| return bts_dir | |||||
| def _build_bootstrap_phase(ph: str, args: argparse.Namespace) -> None: | |||||
| def _build_bootstrap_phase(ph: str, bts_dir: Path, args: argparse.Namespace) -> None: | |||||
| print(f'Running build: {ph} (Please wait a moment...)') | print(f'Running build: {ph} (Please wait a moment...)') | ||||
| env = os.environ.copy() | env = os.environ.copy() | ||||
| env['DDS_BOOTSTRAP_PREV_EXE'] = str(PREBUILT_DIR / 'dds') | env['DDS_BOOTSTRAP_PREV_EXE'] = str(PREBUILT_DIR / 'dds') | ||||
| [ | [ | ||||
| sys.executable, | sys.executable, | ||||
| '-u', | '-u', | ||||
| str(BOOTSTRAP_DIR / 'tools/build.py'), | |||||
| str(bts_dir / 'tools/build.py'), | |||||
| f'--cxx={args.cxx}', | f'--cxx={args.cxx}', | ||||
| ], | ], | ||||
| env=env, | env=env, | ||||
| ) | ) | ||||
| def _pull_executable() -> Path: | |||||
| def _pull_executable(bts_dir: Path) -> Path: | |||||
| prebuild_dir = (PROJECT_ROOT / '_prebuilt') | prebuild_dir = (PROJECT_ROOT / '_prebuilt') | ||||
| prebuild_dir.mkdir(exist_ok=True) | prebuild_dir.mkdir(exist_ok=True) | ||||
| generated = list(BOOTSTRAP_DIR.glob(f'_build/dds{EXE_SUFFIX}')) | |||||
| generated = list(bts_dir.glob(f'_build/dds{EXE_SUFFIX}')) | |||||
| assert len(generated) == 1, repr(generated) | assert len(generated) == 1, repr(generated) | ||||
| exe, = generated | exe, = generated | ||||
| dest = prebuild_dir / exe.name | dest = prebuild_dir / exe.name | ||||
| def _run_boot_phase(phase: str, args: argparse.Namespace) -> Path: | def _run_boot_phase(phase: str, args: argparse.Namespace) -> Path: | ||||
| _clone_bootstrap_phase(phase) | |||||
| _build_bootstrap_phase(phase, args) | |||||
| return _pull_executable() | |||||
| bts_dir = _clone_bootstrap_phase(phase) | |||||
| _build_bootstrap_phase(phase, bts_dir, args) | |||||
| return _pull_executable(bts_dir) | |||||
| def main(argv: Sequence[str]) -> int: | def main(argv: Sequence[str]) -> int: |