From 33f9193c94d3afb9120369e6557ddcd71133c5ee Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 21 Mar 2024 19:41:40 -0400 Subject: [PATCH] casync build: caidx filename is canonical representation of build (#31964) * canonical * short commit * channel * cleanup * let's do 9 characters * fixes * set the build style during release creation * as a property --- release/copy_build_files.sh | 2 +- release/create_casync_release.py | 8 ++++++-- system/updated/casync/common.py | 4 ++-- system/version.py | 12 ++++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/release/copy_build_files.sh b/release/copy_build_files.sh index 31fd8af778..b40bd4b763 100755 --- a/release/copy_build_files.sh +++ b/release/copy_build_files.sh @@ -11,5 +11,5 @@ else fi cd $SOURCE_DIR -cp -pR --parents $(cat release/files_common) $BUILD_DIR/ +cp -pR --parents $(cat release/files_common) $TARGET_DIR/ cp -pR --parents $(cat $FILES_SRC) $TARGET_DIR/ diff --git a/release/create_casync_release.py b/release/create_casync_release.py index 8977e09abc..9aa75eca5d 100755 --- a/release/create_casync_release.py +++ b/release/create_casync_release.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import os import pathlib from openpilot.system.updated.casync.common import create_caexclude_file, create_casync_release, create_build_metadata_file @@ -17,9 +18,12 @@ if __name__ == "__main__": target_dir = pathlib.Path(args.target_dir) output_dir = pathlib.Path(args.output_dir) - create_build_metadata_file(target_dir, get_build_metadata(), args.channel) + build_metadata = get_build_metadata() + build_metadata.openpilot.build_style = "release" if os.environ.get("RELEASE", None) is not None else "debug" + + create_build_metadata_file(target_dir, build_metadata, args.channel) create_caexclude_file(target_dir) - digest, caidx = create_casync_release(target_dir, output_dir, args.channel) + digest, caidx = create_casync_release(target_dir, output_dir, build_metadata.canonical) print(f"Created casync release from {target_dir} to {caidx} with digest {digest}") diff --git a/system/updated/casync/common.py b/system/updated/casync/common.py index 1703c74a76..7061689c66 100644 --- a/system/updated/casync/common.py +++ b/system/updated/casync/common.py @@ -46,8 +46,8 @@ def create_build_metadata_file(path: pathlib.Path, build_metadata: BuildMetadata f.write(json.dumps(build_metadata_dict)) -def create_casync_release(target_dir: pathlib.Path, output_dir: pathlib.Path, channel: str): - caidx_file = output_dir / f"{channel}.caidx" +def create_casync_release(target_dir: pathlib.Path, output_dir: pathlib.Path, caidx_name: str): + caidx_file = output_dir / f"{caidx_name}.caidx" run(["casync", "make", *CASYNC_ARGS, caidx_file, target_dir]) digest = run(["casync", "digest", *CASYNC_ARGS, target_dir]).decode("utf-8").strip() return digest, caidx_file diff --git a/system/version.py b/system/version.py index ab8082dce2..902f013469 100755 --- a/system/version.py +++ b/system/version.py @@ -62,13 +62,14 @@ def is_dirty(cwd: str = BASEDIR) -> bool: return dirty -@dataclass(frozen=True) +@dataclass class OpenpilotMetadata: version: str release_notes: str git_commit: str git_origin: str git_commit_date: str + build_style: str is_dirty: bool # whether there are local changes @property @@ -90,7 +91,7 @@ class OpenpilotMetadata: .replace(":", "/", 1) -@dataclass(frozen=True) +@dataclass class BuildMetadata: channel: str openpilot: OpenpilotMetadata @@ -103,6 +104,10 @@ class BuildMetadata: def release_channel(self) -> bool: return self.channel in RELEASE_BRANCHES + @property + def canonical(self) -> str: + return f"{self.openpilot.version}-{self.openpilot.git_commit}-{self.openpilot.build_style}" + def build_metadata_from_dict(build_metadata: dict) -> BuildMetadata: channel = build_metadata.get("channel", "unknown") @@ -112,6 +117,7 @@ def build_metadata_from_dict(build_metadata: dict) -> BuildMetadata: git_commit = openpilot_metadata.get("git_commit", "unknown") git_origin = openpilot_metadata.get("git_origin", "unknown") git_commit_date = openpilot_metadata.get("git_commit_date", "unknown") + build_style = openpilot_metadata.get("build_style", "unknown") return BuildMetadata(channel, OpenpilotMetadata( version=version, @@ -119,6 +125,7 @@ def build_metadata_from_dict(build_metadata: dict) -> BuildMetadata: git_commit=git_commit, git_origin=git_origin, git_commit_date=git_commit_date, + build_style=build_style, is_dirty=False)) @@ -139,6 +146,7 @@ def get_build_metadata(path: str = BASEDIR) -> BuildMetadata: git_commit=get_commit(path), git_origin=get_origin(path), git_commit_date=get_commit_date(path), + build_style="unknown", is_dirty=is_dirty(path))) cloudlog.exception("unable to get build metadata")