|
|
@ -2,6 +2,7 @@ |
|
|
|
import os |
|
|
|
import os |
|
|
|
import subprocess |
|
|
|
import subprocess |
|
|
|
from typing import List, Optional |
|
|
|
from typing import List, Optional |
|
|
|
|
|
|
|
from functools import lru_cache |
|
|
|
|
|
|
|
|
|
|
|
from common.basedir import BASEDIR |
|
|
|
from common.basedir import BASEDIR |
|
|
|
from selfdrive.swaglog import cloudlog |
|
|
|
from selfdrive.swaglog import cloudlog |
|
|
@ -9,9 +10,16 @@ from selfdrive.swaglog import cloudlog |
|
|
|
|
|
|
|
|
|
|
|
TESTED_BRANCHES = ['devel', 'release2-staging', 'release3-staging', 'dashcam-staging', 'release2', 'release3', 'dashcam'] |
|
|
|
TESTED_BRANCHES = ['devel', 'release2-staging', 'release3-staging', 'dashcam-staging', 'release2', 'release3', 'dashcam'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training_version: bytes = b"0.2.0" |
|
|
|
|
|
|
|
terms_version: bytes = b"2" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cache(user_function, /): |
|
|
|
|
|
|
|
return lru_cache(maxsize=None)(user_function) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_cmd(cmd: List[str]) -> str: |
|
|
|
def run_cmd(cmd: List[str]) -> str: |
|
|
|
return subprocess.check_output(cmd, encoding='utf8').strip() |
|
|
|
return subprocess.check_output(cmd, encoding='utf8').strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[str]: |
|
|
|
def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[str]: |
|
|
@ -21,19 +29,23 @@ def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[s |
|
|
|
return default |
|
|
|
return default |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_git_commit(branch: str = "HEAD", default: Optional[str] = None) -> Optional[str]: |
|
|
|
@cache |
|
|
|
|
|
|
|
def get_commit(branch: str = "HEAD", default: Optional[str] = None) -> Optional[str]: |
|
|
|
return run_cmd_default(["git", "rev-parse", branch], default=default) |
|
|
|
return run_cmd_default(["git", "rev-parse", branch], default=default) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_git_branch(default: Optional[str] = None) -> Optional[str]: |
|
|
|
@cache |
|
|
|
|
|
|
|
def get_short_branch(default: Optional[str] = None) -> Optional[str]: |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"], default=default) |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"], default=default) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_git_full_branchname(default: Optional[str] = None) -> Optional[str]: |
|
|
|
@cache |
|
|
|
|
|
|
|
def get_branch(default: Optional[str] = None) -> Optional[str]: |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], default=default) |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], default=default) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_git_remote(default: Optional[str] = None) -> Optional[str]: |
|
|
|
@cache |
|
|
|
|
|
|
|
def get_origin(default: Optional[str] = None) -> Optional[str]: |
|
|
|
try: |
|
|
|
try: |
|
|
|
local_branch = run_cmd(["git", "name-rev", "--name-only", "HEAD"]) |
|
|
|
local_branch = run_cmd(["git", "name-rev", "--name-only", "HEAD"]) |
|
|
|
tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) |
|
|
|
tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) |
|
|
@ -42,55 +54,68 @@ def get_git_remote(default: Optional[str] = None) -> Optional[str]: |
|
|
|
return run_cmd_default(["git", "config", "--get", "remote.origin.url"], default=default) |
|
|
|
return run_cmd_default(["git", "config", "--get", "remote.origin.url"], default=default) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_version(): |
|
|
|
@cache |
|
|
|
|
|
|
|
def get_version() -> str: |
|
|
|
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "common", "version.h")) as _versionf: |
|
|
|
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "common", "version.h")) as _versionf: |
|
|
|
version = _versionf.read().split('"')[1] |
|
|
|
version = _versionf.read().split('"')[1] |
|
|
|
return version |
|
|
|
return version |
|
|
|
|
|
|
|
|
|
|
|
version = get_version() |
|
|
|
|
|
|
|
prebuilt = os.path.exists(os.path.join(BASEDIR, 'prebuilt')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training_version: bytes = b"0.2.0" |
|
|
|
@cache |
|
|
|
terms_version: bytes = b"2" |
|
|
|
def get_prebuilt() -> bool: |
|
|
|
|
|
|
|
return os.path.exists(os.path.join(BASEDIR, 'prebuilt')) |
|
|
|
|
|
|
|
|
|
|
|
dirty: bool = True |
|
|
|
|
|
|
|
comma_remote: bool = False |
|
|
|
|
|
|
|
tested_branch: bool = False |
|
|
|
|
|
|
|
origin = get_git_remote() |
|
|
|
|
|
|
|
branch = get_git_full_branchname() |
|
|
|
|
|
|
|
commit = get_git_commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (origin is not None) and (branch is not None): |
|
|
|
@cache |
|
|
|
try: |
|
|
|
def get_comma_remote() -> bool: |
|
|
|
comma_remote = origin.startswith('git@github.com:commaai') or origin.startswith('https://github.com/commaai') |
|
|
|
origin = get_origin() |
|
|
|
tested_branch = get_git_branch() in TESTED_BRANCHES |
|
|
|
if origin is None: |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return origin.startswith('git@github.com:commaai') or origin.startswith('https://github.com/commaai') |
|
|
|
|
|
|
|
|
|
|
|
dirty = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
|
|
|
|
def get_tested_branch() -> bool: |
|
|
|
|
|
|
|
return get_short_branch() in TESTED_BRANCHES |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
|
|
|
|
def get_dirty() -> bool: |
|
|
|
|
|
|
|
origin = get_origin() |
|
|
|
|
|
|
|
branch = get_branch() |
|
|
|
|
|
|
|
if (origin is None) or (branch is None): |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dirty = False |
|
|
|
|
|
|
|
try: |
|
|
|
# Actually check dirty files |
|
|
|
# Actually check dirty files |
|
|
|
if not prebuilt: |
|
|
|
if not get_prebuilt(): |
|
|
|
# This is needed otherwise touched files might show up as modified |
|
|
|
# This is needed otherwise touched files might show up as modified |
|
|
|
try: |
|
|
|
try: |
|
|
|
subprocess.check_call(["git", "update-index", "--refresh"]) |
|
|
|
subprocess.check_call(["git", "update-index", "--refresh"]) |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
pass |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"]) != 0) |
|
|
|
dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"]) != 0) |
|
|
|
|
|
|
|
|
|
|
|
# Log dirty files |
|
|
|
# Log dirty files |
|
|
|
if dirty and comma_remote: |
|
|
|
if dirty and get_comma_remote(): |
|
|
|
try: |
|
|
|
try: |
|
|
|
dirty_files = run_cmd(["git", "diff-index", branch, "--"]) |
|
|
|
dirty_files = run_cmd(["git", "diff-index", branch, "--"]) |
|
|
|
cloudlog.event("dirty comma branch", version=version, dirty=dirty, origin=origin, branch=branch, |
|
|
|
cloudlog.event("dirty comma branch", version=get_version(), dirty=dirty, origin=origin, branch=branch, |
|
|
|
dirty_files=dirty_files, commit=commit, origin_commit=get_git_commit(branch)) |
|
|
|
dirty_files=dirty_files, commit=get_commit(), origin_commit=get_commit(branch)) |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
pass |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
dirty = dirty or (not comma_remote) |
|
|
|
dirty = dirty or (not get_comma_remote()) |
|
|
|
dirty = dirty or ('master' in branch) |
|
|
|
dirty = dirty or ('master' in branch) |
|
|
|
|
|
|
|
|
|
|
|
except subprocess.CalledProcessError: |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
dirty = True |
|
|
|
|
|
|
|
cloudlog.exception("git subprocess failed while checking dirty") |
|
|
|
cloudlog.exception("git subprocess failed while checking dirty") |
|
|
|
|
|
|
|
dirty = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dirty |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
@ -100,8 +125,9 @@ if __name__ == "__main__": |
|
|
|
params.put("TermsVersion", terms_version) |
|
|
|
params.put("TermsVersion", terms_version) |
|
|
|
params.put("TrainingVersion", training_version) |
|
|
|
params.put("TrainingVersion", training_version) |
|
|
|
|
|
|
|
|
|
|
|
print("Dirty: %s" % dirty) |
|
|
|
print("Dirty: %s" % get_dirty()) |
|
|
|
print("Version: %s" % version) |
|
|
|
print("Version: %s" % get_version()) |
|
|
|
print("Remote: %s" % origin) |
|
|
|
print("Origin: %s" % get_origin()) |
|
|
|
print("Branch: %s" % branch) |
|
|
|
print("Branch: %s" % get_branch()) |
|
|
|
print("Prebuilt: %s" % prebuilt) |
|
|
|
print("Short branch: %s" % get_short_branch()) |
|
|
|
|
|
|
|
print("Prebuilt: %s" % get_prebuilt()) |
|
|
|