1 #!/usr/bin/env bash
2 #
3 # Build stamp
4 #
5 # Usage:
6 # build/stamp.sh <function name>
7
8 REPO_ROOT=$(cd $(dirname $0)/..; pwd)
9 source build/common.sh
10
11 write-release-date() {
12 mkdir -p _build # Makefile makes this, but scripts/release.sh needs it too
13
14 # Write a readable, sortable date that is independent of time zone.
15 date --utc --rfc-3339 seconds > _build/release-date.txt
16 }
17
18 write-git-commit() {
19 ### Write git commit only if we need to
20 # Ninja works on timestamps, so we don't want to cause rebuilds.
21
22 local out=_build/git-commit.txt
23 mkdir -p _build
24
25 # This check is not quite accurate, since you can modify a file, and then run
26 # Ninja without running build/py.sh all, which calls this function. But it's
27 # better than nothing.
28 if ! git diff --quiet; then
29 log 'Working tree is dirty'
30
31 #rm -f -v $out
32 echo '<unknown>' > $out
33 return
34 fi
35
36 local hash
37 hash=$(git log -n 1 --pretty='format:%H')
38
39 # Don't disturb the timestamp if it exists!
40 if test -f $out; then
41 local old
42 read -r old < $out
43
44 if test "$old" = "$hash"; then
45 log "Unchanged git commit $hash, skipping $out"
46 return
47 else
48 log "Overwriting $out with $hash"
49 fi
50 fi
51
52 echo $hash > $out
53 #log "Wrote $out ($hash)"
54 }
55
56 gen-cpp() {
57 ### For printing out in --version
58
59 local in=$1 # stamp from Ninja
60 local h_out=$2
61 local cc_out=$3
62
63 local hash
64 read -r hash < $in
65 #log hash=$hash
66
67 cat >$h_out <<EOF
68 extern const char* gCommitHash;
69 EOF
70
71 cat >$cc_out <<EOF
72 const char* gCommitHash = "$hash";
73 EOF
74 }
75
76 "$@"