mirror of
https://github.com/esphome/esphome.git
synced 2026-07-11 09:25:34 +00:00
Move CodSpeed library setup to Python script
Extract inline shell from CI workflow into script/setup_codspeed_lib.py. Pins codspeed-cpp to a specific commit SHA for reproducibility.
This commit is contained in:
@@ -327,37 +327,12 @@ jobs:
|
||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||
|
||||
- name: Set up CodSpeed benchmark library
|
||||
# CodSpeed requires their google_benchmark fork for instrumentation.
|
||||
# Clone and create a PlatformIO-compatible library layout.
|
||||
run: |
|
||||
CODSPEED_SHA=d6b4111428ae1f1667fec9bff009522378d5d347
|
||||
git clone https://github.com/CodSpeedHQ/codspeed-cpp.git /tmp/codspeed-cpp
|
||||
git -C /tmp/codspeed-cpp checkout "$CODSPEED_SHA"
|
||||
# Create library.json combining google_benchmark + codspeed core
|
||||
cat > /tmp/codspeed-cpp/google_benchmark/library.json << 'LIBJSON'
|
||||
{
|
||||
"name": "benchmark",
|
||||
"version": "0.0.0",
|
||||
"build": {
|
||||
"flags": [
|
||||
"-I/tmp/codspeed-cpp/core/include",
|
||||
"-I/tmp/codspeed-cpp/core/instrument-hooks",
|
||||
"-DHAVE_STD_REGEX",
|
||||
"-DHAVE_STEADY_CLOCK",
|
||||
"-DBENCHMARK_STATIC_DEFINE"
|
||||
],
|
||||
"srcFilter": ["+<src/*.cc>", "+</tmp/codspeed-cpp/core/src/*.cpp>"],
|
||||
"includeDir": "include"
|
||||
}
|
||||
}
|
||||
LIBJSON
|
||||
|
||||
- name: Build benchmarks
|
||||
id: build
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
BENCHMARK_LIB="symlink:///tmp/codspeed-cpp/google_benchmark" \
|
||||
BENCHMARK_LIB=$(python script/setup_codspeed_lib.py)
|
||||
BENCHMARK_LIB="$BENCHMARK_LIB" \
|
||||
script/cpp_benchmark.py --all --build-only 2>&1 | tee /tmp/bench-build.log
|
||||
BINARY=$(tail -1 /tmp/bench-build.log)
|
||||
echo "binary=$BINARY" >> $GITHUB_OUTPUT
|
||||
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Set up CodSpeed's google_benchmark fork as a PlatformIO library.
|
||||
|
||||
CodSpeed requires their codspeed-cpp fork for CPU simulation instrumentation.
|
||||
This script clones the repo and creates a PlatformIO-compatible library.json
|
||||
that combines the google_benchmark and codspeed core sources.
|
||||
|
||||
Usage:
|
||||
python script/setup_codspeed_lib.py [--output-dir DIR]
|
||||
|
||||
Prints the PlatformIO library path (symlink:// URL) to stdout.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
# Pin to a specific commit for reproducibility
|
||||
CODSPEED_CPP_REPO = "https://github.com/CodSpeedHQ/codspeed-cpp.git"
|
||||
CODSPEED_CPP_SHA = "d6b4111428ae1f1667fec9bff009522378d5d347"
|
||||
|
||||
DEFAULT_OUTPUT_DIR = "/tmp/codspeed-cpp"
|
||||
|
||||
|
||||
def setup_codspeed_lib(output_dir: Path) -> str:
|
||||
"""Clone codspeed-cpp and create PlatformIO library layout.
|
||||
|
||||
Args:
|
||||
output_dir: Directory to clone into
|
||||
|
||||
Returns:
|
||||
PlatformIO library path (symlink:// URL)
|
||||
"""
|
||||
if not (output_dir / ".git").exists():
|
||||
subprocess.run(
|
||||
["git", "clone", CODSPEED_CPP_REPO, str(output_dir)],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "-C", str(output_dir), "checkout", CODSPEED_CPP_SHA],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
benchmark_dir = output_dir / "google_benchmark"
|
||||
core_dir = output_dir / "core"
|
||||
|
||||
# Create library.json combining google_benchmark + codspeed core
|
||||
library_json = {
|
||||
"name": "benchmark",
|
||||
"version": "0.0.0",
|
||||
"build": {
|
||||
"flags": [
|
||||
f"-I{core_dir / 'include'}",
|
||||
f"-I{core_dir / 'instrument-hooks'}",
|
||||
"-DHAVE_STD_REGEX",
|
||||
"-DHAVE_STEADY_CLOCK",
|
||||
"-DBENCHMARK_STATIC_DEFINE",
|
||||
],
|
||||
"srcFilter": [
|
||||
"+<src/*.cc>",
|
||||
f"+<{core_dir / 'src' / '*.cpp'}>",
|
||||
],
|
||||
"includeDir": "include",
|
||||
},
|
||||
}
|
||||
|
||||
(benchmark_dir / "library.json").write_text(
|
||||
json.dumps(library_json, indent=2) + "\n"
|
||||
)
|
||||
|
||||
return f"symlink://{benchmark_dir}"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--output-dir",
|
||||
type=Path,
|
||||
default=Path(DEFAULT_OUTPUT_DIR),
|
||||
help=f"Directory to clone codspeed-cpp into (default: {DEFAULT_OUTPUT_DIR})",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
lib_path = setup_codspeed_lib(args.output_dir)
|
||||
print(lib_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user