Skip to content

Commit da467b6

Browse files
committed
run.py に build と format サブコマンドを追加
- momo の実装を参考にサブコマンド形式に変更 - build コマンド: 既存のビルド機能を _build 関数に移動 - format コマンド: clang-format を使用したコードフォーマット機能を追加 - clang-format の自動検出機能を実装(clang-format-14 から clang-format-50 まで検索) - ソースファイルの import 順序を自動整理
1 parent 0361ace commit da467b6

File tree

5 files changed

+71
-21
lines changed

5 files changed

+71
-21
lines changed

run.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import glob
23
import logging
34
import multiprocessing
45
import os
@@ -209,22 +210,39 @@ def install_deps(
209210
install_openh264(**install_openh264_args)
210211

211212

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
224221

225-
args = parser.parse_args()
226222

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
228246
configuration_dir = "debug" if args.debug else "release"
229247
source_dir = os.path.join(BASE_DIR, "_source", platform, configuration_dir)
230248
build_dir = os.path.join(BASE_DIR, "_build", platform, configuration_dir)
@@ -322,5 +340,36 @@ def main():
322340
f.write(f"PACKAGE_NAME={archive_name}\n")
323341

324342

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+
325374
if __name__ == "__main__":
326375
main()

src/nop_video_decoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// WebRTC
44
#include <api/video/i420_buffer.h>
55
#include <media/base/media_constants.h>
6-
#include <modules/video_coding/include/video_error_codes.h>
76
#include <modules/video_coding/codecs/av1/libaom_av1_encoder.h>
87
#include <modules/video_coding/codecs/h264/include/h264.h>
98
#include <modules/video_coding/codecs/vp8/include/vp8.h>
109
#include <modules/video_coding/codecs/vp9/include/vp9.h>
10+
#include <modules/video_coding/include/video_error_codes.h>
1111

1212
bool NopVideoDecoder::Configure(const Settings& settings) {
1313
return true;

src/virtual_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class VirtualClient : public std::enable_shared_from_this<VirtualClient>,
7676
void OnPush(std::string text) override {}
7777
void OnMessage(std::string label, std::string data) override {}
7878

79-
void OnTrack(webrtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver)
80-
override {}
79+
void OnTrack(webrtc::scoped_refptr<webrtc::RtpTransceiverInterface>
80+
transceiver) override {}
8181
void OnRemoveTrack(
8282
webrtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver) override {}
8383

src/zakuro.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,10 @@ int Zakuro::Run() {
437437
// signaling URL のバリデーション
438438
for (const auto& url : config_.sora_signaling_urls) {
439439
if (url.find("wss://") != 0 && url.find("ws://") != 0) {
440-
std::cerr << "[" << config_.name << "] Error: Invalid signaling URL: " << url << std::endl;
441-
std::cerr << "Signaling URL must start with 'ws://' or 'wss://'" << std::endl;
440+
std::cerr << "[" << config_.name
441+
<< "] Error: Invalid signaling URL: " << url << std::endl;
442+
std::cerr << "Signaling URL must start with 'ws://' or 'wss://'"
443+
<< std::endl;
442444
return 1;
443445
}
444446
}

src/zakuro_audio_device_module.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include <vector>
1111

1212
// webrtc
13-
#include "api/make_ref_counted.h"
1413
#include "api/environment/environment_factory.h"
14+
#include "api/make_ref_counted.h"
1515
#include "modules/audio_device/audio_device_buffer.h"
1616
#include "modules/audio_device/include/audio_device.h"
1717
#include "rtc_base/ref_counted_object.h"
@@ -39,7 +39,6 @@ struct ZakuroAudioDeviceModuleConfig {
3939
std::function<void(std::vector<int16_t>&)> render;
4040
int sample_rate;
4141
int channels;
42-
4342
};
4443

4544
class ZakuroAudioDeviceModule : public webrtc::AudioDeviceModule {

0 commit comments

Comments
 (0)