Skip to content

Commit a0156ab

Browse files
committed
Update ambuildscript to support git-tag
1 parent 0f40916 commit a0156ab

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

AMBuildScript

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def runAndReturn(argv):
4747
output, ignored = p.communicate()
4848
rval = p.poll()
4949
if rval:
50-
raise subprocess.CalledProcessError(rval, argv)
50+
return None
5151
text = output.decode('utf8')
5252
return text.strip()
5353

@@ -227,8 +227,16 @@ extern const char* PLUGIN_REVISION_COUNT;
227227
builder.AddConfigureFile(git_head_path)
228228
builder.AddConfigureFile(direct_head)
229229

230-
revision_count = runAndReturn(['git', 'rev-list', '--count', 'HEAD'])
231-
revision_hash = runAndReturn(['git', 'log', '--pretty=format:%h:%H', '-n', '1'])
230+
tag = runAndReturn(['git', 'describe', '--tags']) or 'MISSING_TAG'
231+
commits_after_tag = '0'
232+
233+
tag_match = re.match(r'(.+?)\-(\d+)\-g[a-f\d]+$', tag, re.MULTILINE)
234+
if tag_match is not None:
235+
tag = tag_match.group(1)
236+
commits_after_tag = tag_match.group(2)
237+
238+
revision_count = runAndReturn(['git', 'rev-list', '--count', 'HEAD']) or 'MISSING_COUNT'
239+
revision_hash = runAndReturn(['git', 'log', '--pretty=format:%h:%H', '-n', '1']) or 'MISSING_SHORTHASH:MISSING_LONGHASH'
232240
shorthash, longhash = revision_hash.split(':')
233241

234242
if '{{git-shorthash}}' in version:
@@ -240,6 +248,12 @@ extern const char* PLUGIN_REVISION_COUNT;
240248
if '{{git-count}}' in version:
241249
version = version.replace('{{git-count}}', revision_count)
242250

251+
if '{{git-tag}}' in version:
252+
version = version.replace('{{git-tag}}', tag)
253+
254+
if '{{git-commits-after-tag}}' in version:
255+
version = version.replace('{{git-commits-after-tag}}', commits_after_tag)
256+
243257
# For the version strings and git hashes compile that to a static library instead,
244258
# to prevent a full recompilation on version/git changes which would only trigger this cpp
245259
# and linking to be performed

plugin-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"url": "https://github.com/GAMMACASE/Source2SchemaDumper",
88
"log_tag": "SCHEMADUMP",
99
"license": "MIT",
10-
"version": "1.0.1.{{git-shorthash}}"
10+
"version": "{{git-tag}}.{{git-shorthash}}"
1111
}

0 commit comments

Comments
 (0)