scripts: zephyr_module now handles when unable to retrieve git rev
We now return "unknown" as the revision, and only concat onto the revision if the revision is a valid git has value. Signed-off-by: Andy Lee <andy@chiefmarley.com>
This commit is contained in:
parent
aa469e05fe
commit
45746c172e
1 changed files with 26 additions and 16 deletions
|
@ -453,6 +453,13 @@ def process_twister(module, meta):
|
|||
|
||||
return out
|
||||
|
||||
def is_valid_git_revision(revision):
|
||||
"""
|
||||
Returns True if the given string is a valid git revision hash (40 hex digits).
|
||||
"""
|
||||
if not isinstance(revision, str):
|
||||
return False
|
||||
return bool(re.fullmatch(r'[0-9a-fA-F]{40}', revision))
|
||||
|
||||
def _create_meta_project(project_path):
|
||||
def git_revision(path):
|
||||
|
@ -480,7 +487,7 @@ def _create_meta_project(project_path):
|
|||
if rc:
|
||||
return revision + '-dirty', True
|
||||
return revision, False
|
||||
return None, False
|
||||
return "unknown", False
|
||||
|
||||
def git_remote(path):
|
||||
popen = subprocess.Popen(['git', 'remote'],
|
||||
|
@ -575,7 +582,7 @@ def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
|
|||
workspace_extra = extra_modules is not None
|
||||
workspace_off = zephyr_off
|
||||
|
||||
if zephyr_off:
|
||||
if zephyr_off and is_valid_git_revision(zephyr_project['revision']):
|
||||
zephyr_project['revision'] += '-off'
|
||||
|
||||
meta['zephyr'] = zephyr_project
|
||||
|
@ -607,7 +614,7 @@ def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
|
|||
manifest_project, manifest_dirty = _create_meta_project(
|
||||
projects[0].posixpath)
|
||||
manifest_off = manifest_project.get("remote") is None
|
||||
if manifest_off:
|
||||
if manifest_off and is_valid_git_revision(manifest_project['revision']):
|
||||
manifest_project["revision"] += "-off"
|
||||
|
||||
if manifest_project:
|
||||
|
@ -630,6 +637,7 @@ def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
|
|||
off = True
|
||||
|
||||
if off:
|
||||
if is_valid_git_revision(meta_project['revision']):
|
||||
meta_project['revision'] += '-off'
|
||||
workspace_off |= off
|
||||
|
||||
|
@ -667,6 +675,7 @@ def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
|
|||
|
||||
if propagate_state:
|
||||
zephyr_revision = zephyr_project['revision']
|
||||
if is_valid_git_revision(zephyr_revision):
|
||||
if workspace_dirty and not zephyr_dirty:
|
||||
zephyr_revision += '-dirty'
|
||||
if workspace_extra:
|
||||
|
@ -677,6 +686,7 @@ def process_meta(zephyr_base, west_projs, modules, extra_modules=None,
|
|||
|
||||
if west_projs is not None:
|
||||
manifest_revision = manifest_project['revision']
|
||||
if is_valid_git_revision(manifest_revision):
|
||||
if workspace_dirty and not manifest_dirty:
|
||||
manifest_revision += '-dirty'
|
||||
if workspace_extra:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue