-
Notifications
You must be signed in to change notification settings - Fork 29
/
autorevision.sh
executable file
·1536 lines (1332 loc) · 37.4 KB
/
autorevision.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Copyright (c) 2012 - 2023 dak180 and contributors. See
# https://opensource.org/licenses/mit-license.php or the included
# COPYING.md for licence terms.
#
# autorevision - extracts metadata about the head version from your
# repository.
# shellcheck disable=SC2154,SC2236,SC2030,SC2031
# Usage message.
arUsage() {
tee >&2 << EOF
usage: autorevision {-t output-type | -s symbol} [-o cache-file [-f] ] [-e name] [-U] [-C path] [-q] [-V]
Options include:
-t output-type = specify output type
-s symbol = specify symbol output
-o cache-file = specify cache file location
-f = force the use of cache data
-e name = set a different output name for VCS_EXTRA
-U = check for untracked files in svn
-C path = change to path before working on repository
-q = Silence warnings
-V = emit version and exit
-? = help message
The following are valid output types:
c = C/C++ file
clojure = clojure file
cmake = CMake script file
csharp = CSharp properties file
h = Header for use with c/c++
hpp = Alternate C++ header strings with namespace
ini = INI file
java = Java file
javaprop = Java properties file
js = javascript file
json = JSON file
lua = Lua file
m4 = m4 file
matlab = matlab file
octave = octave file
php = PHP file
pl = Perl file
py = Python file
rpm = rpm file
scheme = scheme file
sed = sed script
sh = Bash sytax
swift = Swift file
tex = (La)TeX file
xcode = Header useful for populating info.plist files
The following are valid symbols:
VCS_TYPE
VCS_BASENAME
VCS_UUID
VCS_NUM
VCS_DATE
VCS_BRANCH
VCS_TAG
VCS_TAG_OPENPGP
VCS_TICK
VCS_EXTRA
VCS_FULL_HASH
VCS_COMMIT_OPENPGP
VCS_SHORT_HASH
VCS_WC_MODIFIED
VCS_ACTION_STAMP
EOF
exit 1
}
# Config
ARVERSION="&&ARVERSION&&"
while getopts ":t:o:s:e:C:VfqU" OPTION; do
case "${OPTION}" in
t)
AFILETYPE="${OPTARG}"
;;
o)
CACHEFILE="${OPTARG}"
;;
f)
CACHEFORCE="1"
;;
s)
VAROUT="${OPTARG}"
;;
e)
EXTRA_NAME="${OPTARG}"
;;
C)
CHANGE_TO_DIR="${OPTARG}"
;;
U)
UNTRACKEDFILES="1"
;;
q)
WARNHIDE="1"
;;
V)
echo "autorevision ${ARVERSION}"
exit 0
;;
?)
# If an unknown flag is used (or -?):
arUsage
;;
esac
done
if [ ! -z "${VAROUT}" ] && [ ! -z "${AFILETYPE}" ]; then
# If both -s and -t are specified:
echo "error: Improper argument combination." 1>&2
exit 1
elif [ -z "${VAROUT}" ] && [ -z "${AFILETYPE}" ]; then
# If neither -s or -t are specified:
arUsage
elif [ -z "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then
# If -f is specified without -o:
arUsage
elif [ ! -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then
# If we are forced to use the cache but it does not exist.
echo "error: Cache forced but no cache found." 1>&2
exit 1
fi
# Only use the local keyword if it is there (ksh we are looking at
# you).
if [ "$(command -v local 2> /dev/null)" = "local" ]; then
LOCAL="local"
elif [ "$(command -v typeset 2> /dev/null)" = "typeset" ]; then
LOCAL="typeset"
else
LOCAL=""
fi
#check if needed software is installed
commands="sed
cut
grep
wc
tail
basename
dirname
tee
getopts
tr
cmp"
for command in ${commands}; do
if ! command -v "${command}" > /dev/null 2>&1; then
echo "${command} is missing, please install"
exit 100
fi
done
# Make sure that the path we are given is one we can source
# (dash, we are looking at you).
if [ ! -z "${CACHEFILE}" ] && ! echo "${CACHEFILE}" | grep -q '^\.*/'; then
CACHEFILE="./${CACHEFILE}"
fi
GENERATED_HEADER="Generated by autorevision - do not hand-hack!"
: "${EXTRA_NAME:="VCS_EXTRA"}"
: "${WARNHIDE:="0"}"
# Functions to extract data from different repo types.
# For git repos
# shellcheck disable=SC2039,SC2164,SC2155
gitRepo() {
${LOCAL} oldPath="$(pwd)"
cd "$(git rev-parse --show-toplevel)"
VCS_TYPE="git"
VCS_BASENAME="$(basename "$(pwd)")"
${LOCAL} currentRev="$(git rev-parse HEAD)"
VCS_UUID="$(git rev-list --max-parents=0 --date-order --reverse "${currentRev}" 2>/dev/null | sed -n 1p)"
if [ -z "${VCS_UUID}" ]; then
VCS_UUID="$(git rev-list --topo-order "${currentRev}" | tail -n 1)"
fi
# Is the working copy clean?
test -z "$(git status --untracked-files=normal --porcelain)"
VCS_WC_MODIFIED="${?}"
# Enumeration of changesets
VCS_NUM="$(git rev-list --count "${currentRev}" 2>/dev/null)"
if [ -z "${VCS_NUM}" ]; then
if [ ! "${WARNHIDE}" = "1" ]; then
echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it." 1>&2
fi
VCS_NUM="$(git rev-list HEAD | wc -l)"
fi
# This may be a git-svn remote. If so, report the Subversion revision.
if [ -z "$(git config svn-remote.svn.url 2>/dev/null)" ]; then
# The full revision hash
VCS_FULL_HASH="$(git rev-parse "${currentRev}")"
# The short hash
VCS_SHORT_HASH="$(git rev-parse --short "${currentRev}")"
else
# The git-svn revision number
VCS_FULL_HASH="$(git svn find-rev "${currentRev}")"
VCS_SHORT_HASH="${VCS_FULL_HASH}"
fi
# Get the current revision's signing key.
VCS_COMMIT_OPENPGP="$(git verify-commit --raw "${currentRev}" 2>&1 | grep "VALIDSIG" | cut -d ' ' -f 12)"
# Current branch
VCS_BRANCH="$(git rev-parse --symbolic-full-name --verify "$(git name-rev --name-only --no-undefined --exclude='refs/tags/*' "${currentRev}" 2>/dev/null)" 2>/dev/null | sed -e 's:refs/heads/::' | sed -e 's:refs/::')"
# Cache the description
${LOCAL} DESCRIPTION="$(git describe --long --tags "${currentRev}" 2>/dev/null)"
# Current or last tag ancestor (empty if no tags)
VCS_TAG="$(echo "${DESCRIPTION}" | sed -e "s:-g${VCS_SHORT_HASH}\$::" -e 's:-[0-9]*$::')"
if [ ! -z "${VCS_TAG}" ]; then
# Determine if the tag is annotated.
${LOCAL} tagType="$(git for-each-ref --format='%(objecttype)' "$(git rev-parse --symbolic-full-name --verify "${VCS_TAG}")")"
if [ ! "${tagType}" = "tag" ]; then
# Let the user know if the current tag is not annotated.
if [ ! "${WARNHIDE}" = "1" ]; then
echo "note: The most recent tag is not annotated; if it is intended to be a release you may want to fix this." 1>&2
fi
else
# You cannot have a signed tag that is not annotated.
VCS_TAG_OPENPGP="$(git verify-tag --raw "${VCS_TAG}" 2>&1 | grep "VALIDSIG" | cut -d ' ' -f 12)"
fi
fi
# Distance to last tag or an alias of VCS_NUM if there is no tag
if [ ! -z "${DESCRIPTION}" ]; then
VCS_TICK="$(echo "${DESCRIPTION}" | sed -e "s:${VCS_TAG}-::" -e "s:-g${VCS_SHORT_HASH}::")"
else
VCS_TICK="${VCS_NUM}"
fi
# Date of the current commit
VCS_DATE="$(TZ=UTC git show -s --date=iso-strict-local --pretty=format:%cd "${currentRev}" 2>/dev/null | sed -e 's|+00:00|Z|')"
if [ -z "${VCS_DATE}" ]; then
if [ ! "${WARNHIDE}" = "1" ]; then
echo "warning: Action stamps require git version 2.7+." 1>&2
fi
VCS_DATE="$(git log -1 --pretty=format:%ci "${currentRev}" | sed -e 's: :T:' -e 's: ::' -e 's|+00:00|Z|')"
${LOCAL} ASdis="1"
fi
# Action Stamp
if [ -z "${ASdis}" ]; then
VCS_ACTION_STAMP="${VCS_DATE}!$(git show -s --pretty=format:%cE "${currentRev}")"
else
VCS_ACTION_STAMP=""
fi
cd "${oldPath}"
}
# For hg repos
# shellcheck disable=SC2039,SC2164
hgRepo() {
${LOCAL} oldPath="$(pwd)"
cd "$(hg root)"
VCS_TYPE="hg"
VCS_BASENAME="$(basename "$(pwd)")"
VCS_UUID="$(hg log -r "0" -l 1 --template '{node}\n')"
# Is the working copy clean?
test -z "$(hg status -duram)"
VCS_WC_MODIFIED="${?}"
# Enumeration of changesets
VCS_NUM="$(hg id -n | tr -d '+')"
# The full revision hash
VCS_FULL_HASH="$(hg log -r "${VCS_NUM}" -l 1 --template '{node}\n')"
# The short hash
VCS_SHORT_HASH="$(hg id -i | tr -d '+')"
# Current bookmark (bookmarks are roughly equivalent to git's branches)
# or branch if no bookmark
VCS_BRANCH="$(hg id -B | cut -d ' ' -f 1)"
# Fall back to the branch if there are no bookmarks
if [ -z "${VCS_BRANCH}" ]; then
VCS_BRANCH="$(hg id -b)"
fi
# Current or last tag ancestor (excluding auto tags, empty if no tags)
VCS_TAG="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttag}\n' 2>/dev/null | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --config 'extensions.color=' --config 'extensions.mq=' --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1)"
# Distance to last tag or an alias of VCS_NUM if there is no tag
if [ ! -z "${VCS_TAG}" ]; then
VCS_TICK="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttagdistance}\n' 2>/dev/null)"
else
VCS_TICK="${VCS_NUM}"
fi
# Date of the current commit
VCS_DATE="$(hg log -r "${VCS_NUM}" -l 1 --template '{date|isodatesec}\n' 2>/dev/null | sed -e 's: :T:' -e 's: ::' -e 's|+00:00|Z|')"
# Action Stamp
VCS_ACTION_STAMP="$(TZ=UTC hg log -r "${VCS_NUM}" -l 1 --template '{date|localdate|rfc3339date}\n' 2>/dev/null | sed -e 's|+00:00|Z|')!$(hg log -r "${VCS_NUM}" -l 1 --template '{author|email}\n' 2>/dev/null)"
cd "${oldPath}"
}
# For bzr repos
# shellcheck disable=SC2039,SC2164
bzrRepo() {
${LOCAL} oldPath="$(pwd)"
cd "$(bzr root)"
VCS_TYPE="bzr"
VCS_BASENAME="$(basename "$(pwd)")"
# Currently unimplemented because more investigation is needed.
VCS_UUID=""
# Is the working copy clean?
bzr version-info --custom --template='{clean}\n' | grep -q '1'
VCS_WC_MODIFIED="${?}"
# Enumeration of changesets
VCS_NUM="$(bzr revno)"
# The full revision hash
VCS_FULL_HASH="$(bzr version-info --custom --template='{revision_id}\n')"
# The short hash
VCS_SHORT_HASH="${VCS_NUM}"
# Nick of the current branch
VCS_BRANCH="$(bzr nick)"
# Current or last tag ancestor (excluding auto tags, empty if no tags)
VCS_TAG="$(bzr tags --sort=time | sed '/?$/d' | tail -n1 | cut -d ' ' -f1)"
# Distance to last tag or an alias of VCS_NUM if there is no tag
if [ ! -z "${VCS_TAG}" ]; then
VCS_TICK="$(bzr log --line -r "tag:${VCS_TAG}.." | tail -n +2 | wc -l | sed -e 's:^ *::')"
else
VCS_TICK="${VCS_NUM}"
fi
# Date of the current commit
VCS_DATE="$(bzr version-info --custom --template='{date}\n' | sed -e 's: :T:' -e 's: ::')"
# Action Stamp
# Currently unimplemented because more investigation is needed.
VCS_ACTION_STAMP=""
cd "${oldPath}"
}
# For svn repos
# shellcheck disable=SC2039,SC2164,SC2155
svnRepo() {
${LOCAL} oldPath="$(pwd)"
VCS_TYPE="svn"
case "$(pwd)" in
/*trunk*|/*branches*|/*tags*)
${LOCAL} fn="$(pwd)"
while [ "$(basename "${fn}")" != 'trunk' ] && [ "$(basename "${fn}")" != 'branches' ] && [ "$(basename "${fn}")" != 'tags' ] && [ "$(basename "${fn}")" != '/' ]; do
${LOCAL} fn="$(dirname "${fn}")"
done
${LOCAL} fn="$(dirname "${fn}")"
if [ "${fn}" = '/' ]; then
VCS_BASENAME="$(basename "$(pwd)")"
else
VCS_BASENAME="$(basename "${fn}")"
fi
;;
*) VCS_BASENAME="$(basename "$(pwd)")" ;;
esac
VCS_UUID="$(svn info --xml | sed -n -e 's:<uuid>::' -e 's:</uuid>::p')"
# Cache svnversion output
${LOCAL} SVNVERSION="$(svnversion)"
# Is the working copy clean?
echo "${SVNVERSION}" | grep -q "M"
case "${?}" in
0)
VCS_WC_MODIFIED="1"
;;
1)
if [ ! -z "${UNTRACKEDFILES}" ]; then
# `svnversion` does not detect untracked files and `svn status` is really slow, so only run it if we really have to.
if [ -z "$(svn status)" ]; then
VCS_WC_MODIFIED="0"
else
VCS_WC_MODIFIED="1"
fi
else
VCS_WC_MODIFIED="0"
fi
;;
esac
# Enumeration of changesets
VCS_NUM="$(echo "${SVNVERSION}" | cut -d : -f 1 | sed -e 's:M::' -e 's:S::' -e 's:P::')"
# The full revision hash
VCS_FULL_HASH="${SVNVERSION}"
# The short hash
VCS_SHORT_HASH="${VCS_NUM}"
# Current branch
case "$(pwd)" in
/*trunk*|/*branches*|/*tags*)
${LOCAL} lastbase=""
${LOCAL} fn="$(pwd)"
while :
do
base="$(basename "${fn}")"
if [ "${base}" = 'trunk' ]; then
VCS_BRANCH='trunk'
break
elif [ "${base}" = 'branches' ] || [ "${base}" = 'tags' ]; then
VCS_BRANCH="${lastbase}"
break
elif [ "${base}" = '/' ]; then
VCS_BRANCH=""
break
fi
${LOCAL} lastbase="${base}"
${LOCAL} fn="$(dirname "${fn}")"
done
;;
*) VCS_BRANCH="" ;;
esac
# Current or last tag ancestor (empty if no tags). But "current
# tag" can't be extracted reliably because Subversion doesn't
# have tags the way other VCSes do.
VCS_TAG=""
VCS_TICK=""
# Date of the current commit
VCS_DATE="$(svn info --xml | sed -n -e 's:<date>::' -e 's:</date>::p')"
# Action Stamp
VCS_ACTION_STAMP="${VCS_DATE}!$(svn log --xml -l 1 -r "${VCS_SHORT_HASH}" | sed -n -e 's:<author>::' -e 's:</author>::p')"
cd "${oldPath}"
}
# Functions to output data in different formats.
# For bash output
# First in list because it is used by autorevision
shOutput() {
tee << EOF
# ${GENERATED_HEADER}
VCS_TYPE="${VCS_TYPE}"
VCS_BASENAME="${VCS_BASENAME}"
VCS_UUID="${VCS_UUID}"
VCS_NUM="${VCS_NUM}"
VCS_DATE="${VCS_DATE}"
VCS_BRANCH="${VCS_BRANCH}"
VCS_TAG="${VCS_TAG}"
VCS_TAG_OPENPGP="${VCS_TAG_OPENPGP}"
VCS_TICK="${VCS_TICK}"
${EXTRA_NAME}="${VCS_EXTRA}"
VCS_ACTION_STAMP="${VCS_ACTION_STAMP}"
VCS_FULL_HASH="${VCS_FULL_HASH}"
VCS_COMMIT_OPENPGP="${VCS_COMMIT_OPENPGP}"
VCS_SHORT_HASH="${VCS_SHORT_HASH}"
VCS_WC_MODIFIED="${VCS_WC_MODIFIED}"
# end
EOF
}
# For source C output
cOutput() {
tee << EOF
/* ${GENERATED_HEADER} */
const char *VCS_TYPE = "${VCS_TYPE}";
const char *VCS_BASENAME = "${VCS_BASENAME}";
const char *VCS_UUID = "${VCS_UUID}";
const int VCS_NUM = ${VCS_NUM};
const char *VCS_DATE = "${VCS_DATE}";
const char *VCS_BRANCH = "${VCS_BRANCH}";
const char *VCS_TAG = "${VCS_TAG}";
const char *VCS_TAG_OPENPGP = "${VCS_TAG_OPENPGP}";
const int VCS_TICK = ${VCS_TICK};
const char *${EXTRA_NAME} = "${VCS_EXTRA}";
const char *VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}";
const char *VCS_FULL_HASH = "${VCS_FULL_HASH}";
const char *VCS_COMMIT_OPENPGP = "${VCS_COMMIT_OPENPGP}";
const char *VCS_SHORT_HASH = "${VCS_SHORT_HASH}";
const int VCS_WC_MODIFIED = ${VCS_WC_MODIFIED};
/* end */
EOF
}
# For Cmake output
cmakeOutput() {
tee << EOF
# ${GENERATED_HEADER}
set(VCS_TYPE ${VCS_TYPE})
set(VCS_BASENAME ${VCS_BASENAME})
set(VCS_UUID ${VCS_UUID})
set(VCS_NUM ${VCS_NUM})
set(VCS_DATE ${VCS_DATE})
set(VCS_BRANCH ${VCS_BRANCH})
set(VCS_TAG ${VCS_TAG})
set(VCS_TAG_OPENPGP ${VCS_TAG_OPENPGP})
set(VCS_TICK ${VCS_TICK})
set(${EXTRA_NAME} ${VCS_EXTRA})
set(VCS_ACTION_STAMP ${VCS_ACTION_STAMP})
set(VCS_FULL_HASH ${VCS_FULL_HASH})
set(VCS_COMMIT_OPENPGP ${VCS_COMMIT_OPENPGP})
set(VCS_SHORT_HASH ${VCS_SHORT_HASH})
set(VCS_WC_MODIFIED ${VCS_WC_MODIFIED})
# end
EOF
}
# For header output
hOutput() {
tee << EOF
/* ${GENERATED_HEADER} */
#ifndef AUTOREVISION_H
#define AUTOREVISION_H
#define VCS_TYPE "${VCS_TYPE}"
#define VCS_BASENAME "${VCS_BASENAME}"
#define VCS_UUID "${VCS_UUID}"
#define VCS_NUM ${VCS_NUM}
#define VCS_DATE "${VCS_DATE}"
#define VCS_BRANCH "${VCS_BRANCH}"
#define VCS_TAG "${VCS_TAG}"
#define VCS_TAG_OPENPGP "${VCS_TAG_OPENPGP}"
#define VCS_TICK ${VCS_TICK}
#define ${EXTRA_NAME} "${VCS_EXTRA}"
#define VCS_ACTION_STAMP "${VCS_ACTION_STAMP}"
#define VCS_FULL_HASH "${VCS_FULL_HASH}"
#define VCS_COMMIT_OPENPGP "${VCS_COMMIT_OPENPGP}"
#define VCS_SHORT_HASH "${VCS_SHORT_HASH}"
#define VCS_WC_MODIFIED ${VCS_WC_MODIFIED}
#endif
/* end */
EOF
}
# A header output for use with xcode to populate info.plist strings
xcodeOutput() {
tee << EOF
/* ${GENERATED_HEADER} */
#ifndef AUTOREVISION_H
#define AUTOREVISION_H
#define VCS_TYPE ${VCS_TYPE}
#define VCS_BASENAME ${VCS_BASENAME}
#define VCS_UUID ${VCS_UUID}
#define VCS_NUM ${VCS_NUM}
#define VCS_DATE ${VCS_DATE}
#define VCS_BRANCH ${VCS_BRANCH}
#define VCS_TAG ${VCS_TAG}
#define VCS_TAG_OPENPGP ${VCS_TAG_OPENPGP}
#define VCS_TICK ${VCS_TICK}
#define ${EXTRA_NAME} ${VCS_EXTRA}
#define VCS_ACTION_STAMP ${VCS_ACTION_STAMP}
#define VCS_FULL_HASH ${VCS_FULL_HASH}
#define VCS_COMMIT_OPENPGP ${VCS_COMMIT_OPENPGP}
#define VCS_SHORT_HASH ${VCS_SHORT_HASH}
#define VCS_WC_MODIFIED ${VCS_WC_MODIFIED}
#endif
/* end */
EOF
}
# For Swift output
swiftOutput() {
case "${VCS_WC_MODIFIED}" in
0) VCS_WC_MODIFIED="false" ;;
1) VCS_WC_MODIFIED="true" ;;
esac
# For values that may not exist depending on the type of repo we
# have read from, set them to `nil` when they are empty.
if [ -z "${VCS_UUID}" ]; then
VCS_UUID="nil"
else
VCS_UUID="\"${VCS_UUID}\""
fi
if [ -z "${VCS_TAG}" ]; then
VCS_TAG="nil"
else
VCS_TAG="\"${VCS_TAG}\""
fi
if [ -z "${VCS_TAG_OPENPGP}" ]; then
VCS_TAG_OPENPGP="nil"
else
VCS_TAG_OPENPGP="\"${VCS_TAG_OPENPGP}\""
fi
: "${VCS_TICK:="nil"}"
if [ -z "${VCS_EXTRA}" ]; then
VCS_EXTRA="nil"
else
VCS_EXTRA="\"${VCS_EXTRA}\""
fi
if [ -z "${VCS_ACTION_STAMP}" ]; then
VCS_ACTION_STAMP="nil"
else
VCS_ACTION_STAMP="\"${VCS_ACTION_STAMP}\""
fi
if [ -z "${VCS_COMMIT_OPENPGP}" ]; then
VCS_COMMIT_OPENPGP="nil"
else
VCS_COMMIT_OPENPGP="\"${VCS_COMMIT_OPENPGP}\""
fi
tee << EOF
/* ${GENERATED_HEADER} */
let VCS_TYPE = "${VCS_TYPE}"
let VCS_BASENAME = "${VCS_BASENAME}"
let VCS_UUID: String? = ${VCS_UUID}
let VCS_NUM: Int = ${VCS_NUM}
let VCS_DATE = "${VCS_DATE}"
let VCS_BRANCH: String = "${VCS_BRANCH}"
let VCS_TAG: String? = ${VCS_TAG}
let VCS_TAG_OPENPGP: String? = ${VCS_TAG_OPENPGP}
let VCS_TICK: Int? = ${VCS_TICK}
let ${EXTRA_NAME}: String? = ${VCS_EXTRA}
let VCS_ACTION_STAMP: String? = ${VCS_ACTION_STAMP}
let VCS_FULL_HASH: String = "${VCS_FULL_HASH}"
let VCS_COMMIT_OPENPGP: String? = ${VCS_COMMIT_OPENPGP}
let VCS_SHORT_HASH: String = "${VCS_SHORT_HASH}"
let VCS_WC_MODIFIED: Bool = ${VCS_WC_MODIFIED}
/* end */
EOF
}
# For Python output
pyOutput() {
case "${VCS_WC_MODIFIED}" in
0) VCS_WC_MODIFIED="False" ;;
1) VCS_WC_MODIFIED="True" ;;
esac
tee << EOF
# ${GENERATED_HEADER}
VCS_TYPE = "${VCS_TYPE}"
VCS_BASENAME = "${VCS_BASENAME}"
VCS_UUID = "${VCS_UUID}"
VCS_NUM = ${VCS_NUM}
VCS_DATE = "${VCS_DATE}"
VCS_BRANCH = "${VCS_BRANCH}"
VCS_TAG = "${VCS_TAG}"
VCS_TAG_OPENPGP = "${VCS_TAG_OPENPGP}"
VCS_TICK = ${VCS_TICK}
${EXTRA_NAME} = "${VCS_EXTRA}"
VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"
VCS_FULL_HASH = "${VCS_FULL_HASH}"
VCS_COMMIT_OPENPGP = "${VCS_COMMIT_OPENPGP}"
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
# end
EOF
}
# For Perl output
plOutput() {
tee << EOF
# ${GENERATED_HEADER}
\$VCS_TYPE = '${VCS_TYPE}';
\$VCS_BASENAME = '${VCS_BASENAME}';
\$VCS_UUID = '${VCS_UUID}';
\$VCS_NUM = ${VCS_NUM};
\$VCS_DATE = '${VCS_DATE}';
\$VCS_BRANCH = '${VCS_BRANCH}';
\$VCS_TAG = '${VCS_TAG}';
\$VCS_TAG_OPENPGP = '${VCS_TAG_OPENPGP}';
\$VCS_TICK = ${VCS_TICK};
\$${EXTRA_NAME} = '${VCS_EXTRA}';
\$VCS_ACTION_STAMP = '${VCS_ACTION_STAMP}';
\$VCS_FULL_HASH = '${VCS_FULL_HASH}';
\$VCS_COMMIT_OPENPGP = '${VCS_COMMIT_OPENPGP}';
\$VCS_SHORT_HASH = '${VCS_SHORT_HASH}';
\$VCS_WC_MODIFIED = ${VCS_WC_MODIFIED};
# end
1;
EOF
}
# For lua output
luaOutput() {
case "${VCS_WC_MODIFIED}" in
0) VCS_WC_MODIFIED="false" ;;
1) VCS_WC_MODIFIED="true" ;;
esac
tee << EOF
-- ${GENERATED_HEADER}
VCS_TYPE = "${VCS_TYPE}"
VCS_BASENAME = "${VCS_BASENAME}"
VCS_UUID = "${VCS_UUID}"
VCS_NUM = ${VCS_NUM}
VCS_DATE = "${VCS_DATE}"
VCS_BRANCH = "${VCS_BRANCH}"
VCS_TAG = "${VCS_TAG}"
VCS_TAG_OPENPGP = "${VCS_TAG_OPENPGP}"
VCS_TICK = ${VCS_TICK}
${EXTRA_NAME} = "${VCS_EXTRA}"
VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"
VCS_FULL_HASH = "${VCS_FULL_HASH}"
VCS_COMMIT_OPENPGP = "${VCS_COMMIT_OPENPGP}"
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
-- end
EOF
}
# For php output
phpOutput() {
case "${VCS_WC_MODIFIED}" in
0) VCS_WC_MODIFIED="false" ;;
1) VCS_WC_MODIFIED="true" ;;
esac
tee << EOF
<?php
# ${GENERATED_HEADER}
return array(
"VCS_TYPE" => "${VCS_TYPE}",
"VCS_BASENAME" => "${VCS_BASENAME}",
"VCS_UUID" => "${VCS_UUID}",
"VCS_NUM" => ${VCS_NUM},
"VCS_DATE" => "${VCS_DATE}",
"VCS_BRANCH" => "${VCS_BRANCH}",
"VCS_TAG" => "${VCS_TAG}",
"VCS_TAG_OPENPGP" => "${VCS_TAG_OPENPGP}",
"VCS_TICK" => ${VCS_TICK},
"${EXTRA_NAME}" => "${VCS_EXTRA}",
"VCS_ACTION_STAMP" => "${VCS_ACTION_STAMP}",
"VCS_FULL_HASH" => "${VCS_FULL_HASH}",
"VCS_COMMIT_OPENPGP" => "${VCS_COMMIT_OPENPGP}",
"VCS_SHORT_HASH" => "${VCS_SHORT_HASH}",
"VCS_WC_MODIFIED" => ${VCS_WC_MODIFIED}
);
# end
?>
EOF
}
# For ini output
iniOutput() {
case "${VCS_WC_MODIFIED}" in
0) VCS_WC_MODIFIED="false" ;;
1) VCS_WC_MODIFIED="true" ;;
esac
tee << EOF
; ${GENERATED_HEADER}
[VCS]
VCS_TYPE = "${VCS_TYPE}"
VCS_BASENAME = "${VCS_BASENAME}"
VCS_UUID = "${VCS_UUID}"
VCS_NUM = ${VCS_NUM}
VCS_DATE = "${VCS_DATE}"
VCS_BRANCH = "${VCS_BRANCH}"
VCS_TAG = "${VCS_TAG}"
VCS_TAG_OPENPGP = "${VCS_TAG_OPENPGP}"
VCS_TICK = ${VCS_TICK}
${EXTRA_NAME} = "${VCS_EXTRA}"
VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}"
VCS_FULL_HASH = "${VCS_FULL_HASH}"
VCS_COMMIT_OPENPGP = "${VCS_COMMIT_OPENPGP}"
VCS_SHORT_HASH = "${VCS_SHORT_HASH}"
VCS_WC_MODIFIED = ${VCS_WC_MODIFIED}
; end
EOF
}
# For javascript output
jsOutput() {
case "${VCS_WC_MODIFIED}" in
1) VCS_WC_MODIFIED="true" ;;
0) VCS_WC_MODIFIED="false" ;;
esac
tee << EOF
/** ${GENERATED_HEADER} */
var autorevision = {
VCS_TYPE: "${VCS_TYPE}",
VCS_BASENAME: "${VCS_BASENAME}",
VCS_UUID: "${VCS_UUID}",
VCS_NUM: ${VCS_NUM},
VCS_DATE: "${VCS_DATE}",
VCS_BRANCH: "${VCS_BRANCH}",
VCS_TAG: "${VCS_TAG}",
VCS_TAG_OPENPGP: "${VCS_TAG_OPENPGP}",
VCS_TICK: ${VCS_TICK},
${EXTRA_NAME}: "${VCS_EXTRA}",
VCS_ACTION_STAMP: "${VCS_ACTION_STAMP}",
VCS_FULL_HASH: "${VCS_FULL_HASH}",
VCS_COMMIT_OPENPGP: "${VCS_COMMIT_OPENPGP}",
VCS_SHORT_HASH: "${VCS_SHORT_HASH}",
VCS_WC_MODIFIED: ${VCS_WC_MODIFIED}
};
/** Node.js compatibility */
if (typeof module !== 'undefined') {
module.exports = autorevision;
}
/** end */
EOF
}
# For JSON output
jsonOutput() {
case "${VCS_WC_MODIFIED}" in
1) VCS_WC_MODIFIED="true" ;;
0) VCS_WC_MODIFIED="false" ;;
esac
tee << EOF
{
"_comment": "${GENERATED_HEADER}",
"VCS_TYPE": "${VCS_TYPE}",
"VCS_BASENAME": "${VCS_BASENAME}",
"VCS_UUID": "${VCS_UUID}",
"VCS_NUM": ${VCS_NUM},
"VCS_DATE": "${VCS_DATE}",
"VCS_BRANCH":"${VCS_BRANCH}",
"VCS_TAG": "${VCS_TAG}",
"VCS_TAG_OPENPGP": "${VCS_TAG_OPENPGP}",
"VCS_TICK": ${VCS_TICK},
"${EXTRA_NAME}": "${VCS_EXTRA}",
"VCS_ACTION_STAMP": "${VCS_ACTION_STAMP}",
"VCS_FULL_HASH": "${VCS_FULL_HASH}",
"VCS_COMMIT_OPENPGP": "${VCS_COMMIT_OPENPGP}",
"VCS_SHORT_HASH": "${VCS_SHORT_HASH}",
"VCS_WC_MODIFIED": ${VCS_WC_MODIFIED}
}
EOF
}
# For Java output
javaOutput() {
case "${VCS_WC_MODIFIED}" in
1) VCS_WC_MODIFIED="true" ;;
0) VCS_WC_MODIFIED="false" ;;
esac
tee << EOF
/* ${GENERATED_HEADER} */
public class autorevision {
public static final String VCS_TYPE = "${VCS_TYPE}";
public static final String VCS_BASENAME = "${VCS_BASENAME}";
public static final String VCS_UUID = "${VCS_UUID}";
public static final long VCS_NUM = ${VCS_NUM};
public static final String VCS_DATE = "${VCS_DATE}";
public static final String VCS_BRANCH = "${VCS_BRANCH}";
public static final String VCS_TAG = "${VCS_TAG}";
public static final String VCS_TAG_OPENPGP = "${VCS_TAG_OPENPGP}";
public static final long VCS_TICK = ${VCS_TICK};
public static final String ${EXTRA_NAME} = "${VCS_EXTRA}";
public static final String VCS_ACTION_STAMP = "${VCS_ACTION_STAMP}";
public static final String VCS_FULL_HASH = "${VCS_FULL_HASH}";
public static final String VCS_COMMIT_OPENPGP = "${VCS_COMMIT_OPENPGP}";
public static final String VCS_SHORT_HASH = "${VCS_SHORT_HASH}";
public static final boolean VCS_WC_MODIFIED = ${VCS_WC_MODIFIED};
}
EOF
}
csharpOutput() {
case "${VCS_WC_MODIFIED}" in
1) VCS_WC_MODIFIED="true" ;;
0) VCS_WC_MODIFIED="false" ;;
esac
if [ "${EXTRA_NAME}" = "VCS_EXTRA" ]; then
EXTRA_NAME="VcsExtra"
fi
tee << EOF
/* ${GENERATED_HEADER} */
namespace AutoRevision
{
public class VersionInfo
{
public static string VcsType = "${VCS_TYPE}";
public static string VcsBasename = "${VCS_BASENAME}";
public static string VcsUuid = "${VCS_UUID}";
public static string VcsNum = "${VCS_NUM}";
public static string VcsDate = "${VCS_DATE}";
public static string VcsBranch = "${VCS_DATE}";
public static string VcsTag = "${VCS_TAG}";
public static string VcsTagOpenpgp = "${VCS_TAG_OPENPGP}";
public static string VcsTick = "${VCS_TICK}";
public static string ${EXTRA_NAME} = "${VCS_EXTRA}";
public static string VcsActionStamp = "${VCS_ACTION_STAMP}";
public static string VcsFullHash = "${VCS_FULL_HASH}";
public static string VcsCommitOpenpgp = "${VCS_COMMIT_OPENPGP}";
public static string VcsShortHash = "${VCS_SHORT_HASH}";
public static string VcsWcModified = "${VCS_WC_MODIFIED}";
}
}
EOF
}
# For Java properties output
javapropOutput() {
case "${VCS_WC_MODIFIED}" in
1) VCS_WC_MODIFIED="true" ;;
0) VCS_WC_MODIFIED="false" ;;
esac
tee << EOF
# ${GENERATED_HEADER}
VCS_TYPE=${VCS_TYPE}
VCS_BASENAME=${VCS_BASENAME}
VCS_UUID=${VCS_UUID}
VCS_NUM=${VCS_NUM}
VCS_DATE=${VCS_DATE}
VCS_BRANCH=${VCS_BRANCH}
VCS_TAG=${VCS_TAG}
VCS_TAG_OPENPGP=${VCS_TAG_OPENPGP}
VCS_TICK=${VCS_TICK}
${EXTRA_NAME}=${VCS_EXTRA}
VCS_ACTION_STAMP=${VCS_ACTION_STAMP}
VCS_FULL_HASH=${VCS_FULL_HASH}
VCS_COMMIT_OPENPGP=${VCS_COMMIT_OPENPGP}
VCS_SHORT_HASH=${VCS_SHORT_HASH}
VCS_WC_MODIFIED=${VCS_WC_MODIFIED}
EOF
}
# For m4 output
m4Output() {
tee << EOF
dnl ${GENERATED_HEADER}
define(\`VCS_TYPE', \`${VCS_TYPE}')dnl
define(\`VCS_BASENAME', \`${VCS_BASENAME}')dnl
define(\`VCS_UUID', \`${VCS_UUID}')dnl