@@ -74,6 +74,9 @@ printHelp () {
74
74
${tab}${tab} build multiple targets at once in parallel
75
75
${tab}${tab} beware: return code will be inaccurate
76
76
77
+ ${tab} -u
78
+ ${tab}${tab} write username in version string (requires -v)
79
+
77
80
${tab} -v
78
81
${tab}${tab} write package version strings
79
82
@@ -242,11 +245,52 @@ package () {
242
245
)
243
246
}
244
247
248
+ printVersion () {
249
+ local tag_string=' 0'
250
+ local date_string=' '
251
+ local ref_string=' '
252
+ local dirt_string=' '
253
+
254
+ local git_last_commit_short=" $( git rev-parse --short HEAD) "
255
+
256
+ if [ -n " ${git_last_commit_short} " ]
257
+ then
258
+ local git_describe_string=" $( git describe --tags --match ' v[0-9].*' 2> /dev/null | cut -c2-) "
259
+ local git_closest_tag=" $( git describe --tags --abbrev=0 --match ' v[0-9].*' 2> /dev/null | cut -c2-) "
260
+ local git_last_commit_date=" $( date --date=" @$( git log -1 ' --pretty=format:%ct' ) " --utc ' +%Y%m%d-%H%M%S' ) "
261
+
262
+ if [ -n " ${git_closest_tag} " ]
263
+ then
264
+ tag_string=" ${git_closest_tag} "
265
+
266
+ if [ " ${git_closest_tag} " != " ${git_describe_string} " ]
267
+ then
268
+ date_string=" -${git_last_commit_date} "
269
+ ref_string=" -${git_last_commit_short} "
270
+ fi
271
+ else
272
+ date_string=" -${git_last_commit_date} "
273
+ ref_string=" -${git_last_commit_short} "
274
+ fi
275
+ else
276
+ date_string=" -$( date --utc ' +%Y%m%d-%H%M%S' ) "
277
+ ref_string=' -0'
278
+ fi
279
+
280
+ if ! git diff --quiet 2> /dev/null
281
+ then
282
+ dirt_string=' -dirty'
283
+ fi
284
+
285
+ echo " ${tag_string}${date_string}${ref_string}${dirt_string} "
286
+ }
287
+
245
288
build () {
246
289
local job_count=" ${1} "
247
290
local write_version_string=" ${2} "
248
- local root_dir=" ${3} "
249
- local target=" ${4} "
291
+ local write_username_string=" ${3} "
292
+ local root_dir=" ${4} "
293
+ local target=" ${5} "
250
294
251
295
local symbol_archive_basename=' symbols'
252
296
local vmpak_archive_basename=' '
@@ -342,17 +386,11 @@ build () {
342
386
343
387
if " ${write_version_string} "
344
388
then
345
- git_last_commit=" $( git rev-list HEAD | head -n 1) "
346
- git_last_commit_short=" $( git rev-list HEAD | head -n 1 | cut -c1-7) "
347
- git_ref=" $( git describe --tags --match ' v*' | cut -c2-) "
348
- git_last_tag=" $( git describe --tags --match ' v*' | cut -f1 -d' -' | cut -c2-) "
349
- git_last_date=" $( date --date=" @$( git log -1 ' --pretty=format:%ct' ) " -u ' +%Y%m%d-%H%M%S' ) "
389
+ build_version=" $( printVersion) "
350
390
351
- if [ " ${git_ref} " = " ${git_last_tag} " ]
391
+ if " ${write_username_string} "
352
392
then
353
- build_version=" ${git_ref} "
354
- else
355
- build_version=" ${git_last_tag} +${git_last_date} +${git_last_commit_short} +$( getUserName) "
393
+ build_version+=" -$( whoami | tr ' [:upper:]' ' [:lower:]' ) "
356
394
fi
357
395
358
396
vmpak_version_string=" _${build_version} "
@@ -741,6 +779,7 @@ root_dir="$(git rev-parse --show-toplevel)"
741
779
job_count=' '
742
780
parallel_target=' false'
743
781
write_version_string=' false'
782
+ write_username_string=' false'
744
783
target_list=' '
745
784
746
785
while [ -n " ${1:- } " ]
765
804
parallel_target=' true'
766
805
shift
767
806
;;
807
+ ' -u' )
808
+ write_username_string=' true'
809
+ shift
810
+ ;;
768
811
' -v' )
769
812
write_version_string=' true'
770
813
shift
@@ -785,9 +828,9 @@ for target in ${target_list}
785
828
do
786
829
if " ${parallel_target} "
787
830
then
788
- build " ${job_count} " " ${write_version_string} " " ${root_dir} " " ${target} " &
831
+ build " ${job_count} " " ${write_version_string} " " ${write_username_string} " " ${ root_dir}" " ${target} " &
789
832
else
790
- build " ${job_count} " " ${write_version_string} " " ${root_dir} " " ${target} "
833
+ build " ${job_count} " " ${write_version_string} " " ${write_username_string} " " ${ root_dir}" " ${target} "
791
834
fi
792
835
done
793
836
wait
0 commit comments