|
1 | 1 | import argparse
|
| 2 | +import glob |
2 | 3 | import logging
|
3 | 4 | import multiprocessing
|
4 | 5 | import os
|
@@ -209,22 +210,39 @@ def install_deps(
|
209 | 210 | install_openh264(**install_openh264_args)
|
210 | 211 |
|
211 | 212 |
|
212 |
| -def main(): |
213 |
| - parser = argparse.ArgumentParser() |
214 |
| - parser.add_argument( |
215 |
| - "target", choices=["macos_arm64", "ubuntu-22.04_x86_64", "ubuntu-24.04_x86_64"] |
216 |
| - ) |
217 |
| - parser.add_argument("--debug", action="store_true") |
218 |
| - parser.add_argument("--relwithdebinfo", action="store_true") |
219 |
| - parser.add_argument("--local-webrtc-build-dir", type=os.path.abspath) |
220 |
| - parser.add_argument("--local-webrtc-build-args", default="", type=shlex.split) |
221 |
| - parser.add_argument("--local-sora-cpp-sdk-dir", type=os.path.abspath) |
222 |
| - parser.add_argument("--local-sora-cpp-sdk-args", default="", type=shlex.split) |
223 |
| - parser.add_argument("--package", action="store_true") |
| 213 | +def _find_clang_binary(name: str) -> Optional[str]: |
| 214 | + if shutil.which(name) is not None: |
| 215 | + return name |
| 216 | + else: |
| 217 | + for n in range(50, 14, -1): |
| 218 | + if shutil.which(f"{name}-{n}") is not None: |
| 219 | + return f"{name}-{n}" |
| 220 | + return None |
224 | 221 |
|
225 |
| - args = parser.parse_args() |
226 | 222 |
|
227 |
| - platform = args.target |
| 223 | +def _format( |
| 224 | + clang_format_path: Optional[str] = None, |
| 225 | +): |
| 226 | + if clang_format_path is None: |
| 227 | + clang_format_path = _find_clang_binary("clang-format") |
| 228 | + if clang_format_path is None: |
| 229 | + raise Exception("clang-format not found. Please install it or specify the path.") |
| 230 | + patterns = [ |
| 231 | + "src/**/*.h", |
| 232 | + "src/**/*.cpp", |
| 233 | + ] |
| 234 | + target_files = [] |
| 235 | + for pattern in patterns: |
| 236 | + files = glob.glob(pattern, recursive=True) |
| 237 | + target_files.extend(files) |
| 238 | + if target_files: |
| 239 | + cmd([clang_format_path, "-i"] + target_files) |
| 240 | + |
| 241 | + |
| 242 | +def _build(args): |
| 243 | + |
| 244 | + target = args.target |
| 245 | + platform = target |
228 | 246 | configuration_dir = "debug" if args.debug else "release"
|
229 | 247 | source_dir = os.path.join(BASE_DIR, "_source", platform, configuration_dir)
|
230 | 248 | build_dir = os.path.join(BASE_DIR, "_build", platform, configuration_dir)
|
@@ -322,5 +340,36 @@ def main():
|
322 | 340 | f.write(f"PACKAGE_NAME={archive_name}\n")
|
323 | 341 |
|
324 | 342 |
|
| 343 | +def main(): |
| 344 | + parser = argparse.ArgumentParser() |
| 345 | + sp = parser.add_subparsers(dest="command") |
| 346 | + |
| 347 | + # build コマンド |
| 348 | + bp = sp.add_parser("build") |
| 349 | + bp.add_argument( |
| 350 | + "target", choices=["macos_arm64", "ubuntu-22.04_x86_64", "ubuntu-24.04_x86_64"] |
| 351 | + ) |
| 352 | + bp.add_argument("--debug", action="store_true") |
| 353 | + bp.add_argument("--relwithdebinfo", action="store_true") |
| 354 | + bp.add_argument("--local-webrtc-build-dir", type=os.path.abspath) |
| 355 | + bp.add_argument("--local-webrtc-build-args", default="", type=shlex.split) |
| 356 | + bp.add_argument("--local-sora-cpp-sdk-dir", type=os.path.abspath) |
| 357 | + bp.add_argument("--local-sora-cpp-sdk-args", default="", type=shlex.split) |
| 358 | + bp.add_argument("--package", action="store_true") |
| 359 | + |
| 360 | + # format コマンド |
| 361 | + fp = sp.add_parser("format") |
| 362 | + fp.add_argument("--clang-format-path", type=str, default=None) |
| 363 | + |
| 364 | + args = parser.parse_args() |
| 365 | + |
| 366 | + if args.command == "build": |
| 367 | + _build(args) |
| 368 | + elif args.command == "format": |
| 369 | + _format(clang_format_path=args.clang_format_path) |
| 370 | + else: |
| 371 | + parser.print_help() |
| 372 | + |
| 373 | + |
325 | 374 | if __name__ == "__main__":
|
326 | 375 | main()
|
0 commit comments