Skip to content

Commit

Permalink
Adds Cobalt Version to build info. (#907) (#922)
Browse files Browse the repository at this point in the history
b/290993560

Change-Id: Icb8871a184d82496cca20860bf5e151aedf2af02
(cherry picked from commit 493e3ea)

Co-authored-by: Brian Ting <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and briantting authored Jul 13, 2023
1 parent 4ec389d commit b1cd4de
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cobalt/build/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

_BUILD_ID_PATTERN = '^BUILD_NUMBER=([1-9][0-9]{6,})$'
_GIT_REV_PATTERN = '^GitOrigin-RevId: ([0-9a-f]{40})$'
_COBALT_VERSION_PATTERN = '^#define COBALT_VERSION "(.*)"$'


def get_build_id_and_git_rev_from_commits(cwd):
Expand Down Expand Up @@ -77,13 +78,24 @@ def _get_subject_from_last_commit(cwd):
return _get_last_commit_with_format(r'%s', cwd=cwd)


def _get_cobalt_version():
version_header_path = os.path.join(os.path.dirname(FILE_DIR), 'version.h')
contents = ''
with open(version_header_path, 'r', encoding='utf-8') as f:
contents = f.read()
compiled_cobalt_version_pattern = re.compile(
_COBALT_VERSION_PATTERN, flags=re.MULTILINE)
return compiled_cobalt_version_pattern.search(contents).group(1)


def main(output_path, cwd=FILE_DIR):
"""Writes a Cobalt build_info json file."""
build_rev = _get_hash_from_last_commit(cwd=cwd)
build_id, git_rev = get_build_id_and_git_rev_from_commits(cwd=cwd)
if build_id is None:
build_id = get_build_id_from_commit_count(cwd=cwd)
git_rev = build_rev
cobalt_version = _get_cobalt_version()
build_time = datetime.datetime.now().ctime()
author = _get_author_from_last_commit(cwd=cwd)
commit = _get_subject_from_last_commit(cwd=cwd)
Expand All @@ -92,6 +104,7 @@ def main(output_path, cwd=FILE_DIR):
'build_id': build_id,
'build_rev': build_rev,
'git_rev': git_rev,
'cobalt_version': cobalt_version,
'build_time': build_time,
'author': author,
'commit': commit
Expand All @@ -108,6 +121,7 @@ def main(output_path, cwd=FILE_DIR):
Build ID: {build_id}
Build Rev: {build_rev}
Git Rev: {git_rev}
Cobalt Version: {cobalt_version}
Build Time: {build_time}
Author: {author}
Commit: {commit}
Expand Down

0 comments on commit b1cd4de

Please sign in to comment.