Update s2_sample_mm AMBuildScript

Adds git-tag and git-commits-after-tag version strings, also fixes errors on fresh/empty git repos
This commit is contained in:
GAMMACASE 2025-08-12 19:28:54 +03:00
parent 2221689ce8
commit 2f75343a6b

View File

@ -47,7 +47,7 @@ def runAndReturn(argv):
output, ignored = p.communicate() output, ignored = p.communicate()
rval = p.poll() rval = p.poll()
if rval: if rval:
raise subprocess.CalledProcessError(rval, argv) return None
text = output.decode('utf8') text = output.decode('utf8')
return text.strip() return text.strip()
@ -227,8 +227,16 @@ extern const char* PLUGIN_REVISION_COUNT;
builder.AddConfigureFile(git_head_path) builder.AddConfigureFile(git_head_path)
builder.AddConfigureFile(direct_head) builder.AddConfigureFile(direct_head)
revision_count = runAndReturn(['git', 'rev-list', '--count', 'HEAD']) tag = runAndReturn(['git', 'describe', '--tags']) or 'MISSING_TAG'
revision_hash = runAndReturn(['git', 'log', '--pretty=format:%h:%H', '-n', '1']) commits_after_tag = '0'
tag_match = re.match(r'(.+?)\-(\d+)\-g[a-f\d]+$', tag, re.MULTILINE)
if tag_match is not None:
tag = tag_match.group(1)
commits_after_tag = tag_match.group(2)
revision_count = runAndReturn(['git', 'rev-list', '--count', 'HEAD']) or 'MISSING_COUNT'
revision_hash = runAndReturn(['git', 'log', '--pretty=format:%h:%H', '-n', '1']) or 'MISSING_SHORTHASH:MISSING_LONGHASH'
shorthash, longhash = revision_hash.split(':') shorthash, longhash = revision_hash.split(':')
if '{{git-shorthash}}' in version: if '{{git-shorthash}}' in version:
@ -240,6 +248,12 @@ extern const char* PLUGIN_REVISION_COUNT;
if '{{git-count}}' in version: if '{{git-count}}' in version:
version = version.replace('{{git-count}}', revision_count) version = version.replace('{{git-count}}', revision_count)
if '{{git-tag}}' in version:
version = version.replace('{{git-tag}}', tag)
if '{{git-commits-after-tag}}' in version:
version = version.replace('{{git-commits-after-tag}}', commits_after_tag)
# For the version strings and git hashes compile that to a static library instead, # For the version strings and git hashes compile that to a static library instead,
# to prevent a full recompilation on version/git changes which would only trigger this cpp # to prevent a full recompilation on version/git changes which would only trigger this cpp
# and linking to be performed # and linking to be performed