|
8 | 8 | import shutil
|
9 | 9 | import sys
|
10 | 10 | from pathlib import Path
|
| 11 | +from typing import Tuple, Optional |
11 | 12 |
|
12 | 13 | BASEDIR = Path(sys.argv[1])
|
13 | 14 | RELEASE = sys.argv[2]
|
14 | 15 | VERSION = RELEASE.split("-")[0]
|
15 |
| -AP_SOURCE_DIR = BASEDIR / "ap-releases" / f"async-profiler-{VERSION}-code" / "src" |
16 |
| -AP_CONVERTER_SOURCE_DIR = AP_SOURCE_DIR / "converter" |
17 |
| -AP_RESOURCES_SOURCE_DIR = AP_SOURCE_DIR / "res" |
18 |
| -AP_API_SOURCE_DIR = AP_SOURCE_DIR / "api" / "one" / "profiler" |
19 |
| -TARGET_SOURCE_DIR = BASEDIR / "src" / "main" / "java" |
| 16 | + |
| 17 | +def either(*dirs: Path) -> Path: |
| 18 | + for dir in dirs: |
| 19 | + if dir.exists(): |
| 20 | + return dir |
| 21 | + raise AssertionError(f"None of {', '.join(map(str, dirs))} exists") |
| 22 | + |
| 23 | + |
| 24 | +def either_or_none(*dirs: Path) -> Optional[Path]: |
| 25 | + return ([dir for dir in dirs if dir.exists()] + [None]) [0] |
| 26 | + |
| 27 | + |
| 28 | +AP_SOURCE_DIR = either(BASEDIR / "ap-releases" / f"async-profiler-{VERSION}-code" / "src") |
| 29 | +AP_CONVERTER_SOURCE_DIR = either(AP_SOURCE_DIR / "converter") |
| 30 | +AP_RESOURCES_SOURCE_DIR = either_or_none(AP_SOURCE_DIR / "res", AP_SOURCE_DIR / "main" / "resources") |
| 31 | +AP_API_SOURCE_DIR = either(AP_SOURCE_DIR / "api" / "one" / "profiler") |
| 32 | +TARGET_SOURCE_DIR = either(BASEDIR / "src" / "main" / "java") |
20 | 33 | TARGET_ONE_DIR = TARGET_SOURCE_DIR / "one"
|
21 |
| -TARGET_ONE_PROFILER_DIR = TARGET_ONE_DIR / "profiler" |
| 34 | +TARGET_ONE_PROFILER_DIR = either(TARGET_ONE_DIR / "profiler") |
22 | 35 | TARGET_CONVERTER_DIR = TARGET_ONE_DIR / "converter"
|
23 | 36 | TARGET_RESOURCES_DIR = BASEDIR / "src" / "main" / "resources"
|
24 | 37 |
|
25 |
| -assert AP_SOURCE_DIR.exists(), f"Source directory {AP_SOURCE_DIR} does not exist" |
26 |
| -assert AP_CONVERTER_SOURCE_DIR.exists(), f"Source directory {AP_CONVERTER_SOURCE_DIR} does not exist" |
27 |
| -assert AP_API_SOURCE_DIR.exists() |
28 |
| -assert TARGET_SOURCE_DIR.exists() |
29 |
| -assert TARGET_ONE_PROFILER_DIR.exists() |
30 |
| -assert AP_RESOURCES_SOURCE_DIR.exists() |
31 | 38 |
|
32 | 39 | PROJECT_FILES = ["AsyncProfilerLoader.java"]
|
33 | 40 |
|
|
71 | 78 | else:
|
72 | 79 | shutil.copy(f, target_file)
|
73 | 80 |
|
74 |
| -print("Copy converter resource files") |
75 |
| -for f in AP_RESOURCES_SOURCE_DIR.glob("*"): |
76 |
| - target_file = TARGET_RESOURCES_DIR / f.name |
77 |
| - if DRY_RUN: |
78 |
| - print(f"would copy {f} to {target_file}") |
79 |
| - else: |
80 |
| - shutil.copy(f, target_file) |
| 81 | +if AP_RESOURCES_SOURCE_DIR: |
| 82 | + print("Copy converter resource files") |
| 83 | + for f in AP_RESOURCES_SOURCE_DIR.glob("*"): |
| 84 | + target_file = TARGET_RESOURCES_DIR / f.name |
| 85 | + if DRY_RUN: |
| 86 | + print(f"would copy {f} to {target_file}") |
| 87 | + else: |
| 88 | + shutil.copy(f, target_file) |
81 | 89 |
|
82 | 90 | print("Copy converter directories")
|
83 | 91 | for directory in AP_CONVERTER_SOURCE_DIR.glob("one/*"):
|
|
0 commit comments