Skip to content

Commit 853d255

Browse files
committed
run.py に build と format サブコマンドを追加
- momo を参考にして build と format サブコマンドを実装 - .github/workflows/build.yml のコマンドを新形式に変更 - opus_audio_decoder.cpp のコードフォーマットを修正
1 parent 7c34b6a commit 853d255

File tree

5 files changed

+80
-26
lines changed

5 files changed

+80
-26
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- run: uv sync
4242
- name: Generate pyi
4343
run: |
44-
uv run python run.py ubuntu-24.04_x86_64
44+
uv run python run.py build ubuntu-24.04_x86_64
4545
mkdir libdatachannel/
4646
cp src/libdatachannel/py.typed libdatachannel/
4747
cp src/libdatachannel/libdatachannel_ext.pyi libdatachannel/
@@ -92,7 +92,7 @@ jobs:
9292
uv sync
9393
9494
- run: |
95-
uv run python run.py ${{ matrix.platform.target }}
95+
uv run python run.py build ${{ matrix.platform.target }}
9696
uv run python -m build
9797
9898
- run: |
@@ -150,7 +150,7 @@ jobs:
150150
uv sync
151151
152152
- run: |
153-
uv run python run.py ${{ matrix.platform.target }} --debug
153+
uv run python run.py build ${{ matrix.platform.target }} --debug
154154
uv run python -m build --outdir dist_debug
155155
env:
156156
BUILD_PROFILE: debug
@@ -274,7 +274,7 @@ jobs:
274274
- run: |
275275
uv python pin ${{ matrix.python_version }}
276276
uv sync
277-
uv run python run.py ${{ matrix.platform.target }} --debug
277+
uv run python run.py build ${{ matrix.platform.target }} --debug
278278
uv run python -m build --outdir dist_debug
279279
env:
280280
BUILD_PROFILE: debug

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- [CHANGE] リリースを GH コマンドに変更
1717
- `gh release create` を使用してリリースを作成するように変更する
1818
- @voluntas
19+
- [CHANGE] run.py に build と format サブコマンドを追加
20+
- .github/workflows/build.yml も修正
21+
- @voluntas
1922
- [ADD] デバッグビルドの追加
2023
- ローカルバージョンラベル +debug を指定している
2124
- @voluntas

run.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import argparse
2+
import glob
23
import multiprocessing
34
import os
45
import shutil
56
import sys
7+
from typing import Optional
68

79
from buildbase import (
810
Platform,
@@ -179,29 +181,52 @@ def install_deps(
179181
]
180182

181183

182-
def main():
183-
parser = argparse.ArgumentParser()
184-
parser.add_argument("--debug", action="store_true")
185-
parser.add_argument("--relwithdebinfo", action="store_true")
186-
parser.add_argument("target", choices=AVAILABLE_TARGETS)
184+
def _find_clang_binary(name: str) -> Optional[str]:
185+
if shutil.which(name) is not None:
186+
return name
187+
else:
188+
for n in range(50, 14, -1):
189+
if shutil.which(f"{name}-{n}") is not None:
190+
return f"{name}-{n}"
191+
return None
187192

188-
args = parser.parse_args()
189-
if args.target == "windows_x86_64":
193+
194+
def _format(
195+
clang_format_path: Optional[str] = None,
196+
):
197+
if clang_format_path is None:
198+
clang_format_path = _find_clang_binary("clang-format")
199+
if clang_format_path is None:
200+
raise Exception("clang-format not found. Please install it or specify the path.")
201+
patterns = [
202+
"src/**/*.cpp",
203+
"src/**/*.h",
204+
]
205+
target_files = []
206+
for pattern in patterns:
207+
files = glob.glob(pattern, recursive=True)
208+
target_files.extend(files)
209+
cmd([clang_format_path, "-i"] + target_files)
210+
211+
212+
def _build(args):
213+
target = args.target
214+
if target == "windows_x86_64":
190215
platform = Platform("windows", get_windows_osver(), "x86_64")
191-
elif args.target == "macos_x86_64":
216+
elif target == "macos_x86_64":
192217
platform = Platform("macos", get_macos_osver(), "x86_64")
193-
elif args.target == "macos_arm64":
218+
elif target == "macos_arm64":
194219
platform = Platform("macos", get_macos_osver(), "arm64")
195-
elif args.target == "ubuntu-22.04_x86_64":
220+
elif target == "ubuntu-22.04_x86_64":
196221
platform = Platform("ubuntu", "22.04", "x86_64")
197-
elif args.target == "ubuntu-24.04_x86_64":
222+
elif target == "ubuntu-24.04_x86_64":
198223
platform = Platform("ubuntu", "24.04", "x86_64")
199-
elif args.target == "ubuntu-24.04_armv8":
224+
elif target == "ubuntu-24.04_armv8":
200225
platform = Platform("ubuntu", "24.04", "armv8")
201-
elif args.target == "ubuntu-22.04_armv8_jetson":
226+
elif target == "ubuntu-22.04_armv8_jetson":
202227
platform = Platform("jetson", None, "armv8", "ubuntu-22.04")
203228
else:
204-
raise Exception(f"Unknown target {args.target}")
229+
raise Exception(f"Unknown target {target}")
205230

206231
source_dir = os.path.join(BASE_DIR, "_source", platform.target.package_name)
207232
build_dir = os.path.join(BASE_DIR, "_build", platform.target.package_name)
@@ -341,5 +366,29 @@ def main():
341366
)
342367

343368

369+
def main():
370+
parser = argparse.ArgumentParser()
371+
sp = parser.add_subparsers(dest="command")
372+
373+
# build コマンド
374+
bp = sp.add_parser("build")
375+
bp.add_argument("target", choices=AVAILABLE_TARGETS)
376+
bp.add_argument("--debug", action="store_true")
377+
bp.add_argument("--relwithdebinfo", action="store_true")
378+
379+
# format コマンド
380+
fp = sp.add_parser("format")
381+
fp.add_argument("--clang-format-path", type=str, default=None)
382+
383+
args = parser.parse_args()
384+
385+
if args.command == "build":
386+
_build(args)
387+
elif args.command == "format":
388+
_format(clang_format_path=args.clang_format_path)
389+
else:
390+
parser.print_help()
391+
392+
344393
if __name__ == "__main__":
345394
main()

src/opus_audio_decoder.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class OpusAudioDecoder : public AudioDecoder {
2525
}
2626

2727
int error = 0;
28-
decoder_ = opus_decoder_create(settings_.sample_rate, settings_.channels, &error);
28+
decoder_ =
29+
opus_decoder_create(settings_.sample_rate, settings_.channels, &error);
2930
if (error != OPUS_OK) {
3031
PLOG_ERROR << "Failed to create opus decoder";
3132
return false;
@@ -50,8 +51,9 @@ class OpusAudioDecoder : public AudioDecoder {
5051
return;
5152
}
5253

53-
int samples = opus_decode_float(decoder_, encoded.data.data(), encoded.data.shape(0),
54-
pcm_buf_.data(), pcm_buf_.size() / settings_.channels, 0);
54+
int samples = opus_decode_float(decoder_, encoded.data.data(),
55+
encoded.data.shape(0), pcm_buf_.data(),
56+
pcm_buf_.size() / settings_.channels, 0);
5557
if (samples < 0) {
5658
PLOG_ERROR << "Failed to opus_decode_float: result=" << samples;
5759
return;
@@ -62,19 +64,19 @@ class OpusAudioDecoder : public AudioDecoder {
6264
frame.sample_rate = settings_.sample_rate;
6365
frame.timestamp = encoded.timestamp;
6466
frame.pcm = CreatePCMFloat(samples, settings_.channels);
65-
67+
6668
// PCMデータをコピー
6769
// frame.pcm.data() で生のポインタを取得
6870
float* pcm_data = static_cast<float*>(frame.pcm.data());
69-
memcpy(pcm_data, pcm_buf_.data(), samples * settings_.channels * sizeof(float));
71+
memcpy(pcm_data, pcm_buf_.data(),
72+
samples * settings_.channels * sizeof(float));
7073

7174
if (on_decode_) {
7275
on_decode_(frame);
7376
}
7477
}
7578

76-
void SetOnDecode(
77-
std::function<void(const AudioFrame&)> on_decode) override {
79+
void SetOnDecode(std::function<void(const AudioFrame&)> on_decode) override {
7880
on_decode_ = on_decode;
7981
}
8082

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)