forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamp.sh
executable file
·76 lines (59 loc) · 1.52 KB
/
stamp.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
#!/usr/bin/env bash
#
# Build stamp
#
# Usage:
# build/stamp.sh <function name>
REPO_ROOT=$(cd $(dirname $0)/..; pwd)
source build/common.sh
write-release-date() {
mkdir -p _build # Makefile makes this, but scripts/release.sh needs it too
# Write a readable, sortable date that is independent of time zone.
date --utc --rfc-3339 seconds > _build/release-date.txt
}
write-git-commit() {
### Write git commit only if we need to
# Ninja works on timestamps, so we don't want to cause rebuilds.
local out=_build/git-commit.txt
mkdir -p _build
# This check is not quite accurate, since you can modify a file, and then run
# Ninja without running build/py.sh all, which calls this function. But it's
# better than nothing.
if ! git diff --quiet; then
log 'Working tree is dirty'
#rm -f -v $out
echo '<unknown>' > $out
return
fi
local hash
hash=$(git log -n 1 --pretty='format:%H')
# Don't disturb the timestamp if it exists!
if test -f $out; then
local old
read -r old < $out
if test "$old" = "$hash"; then
log "Unchanged git commit $hash, skipping $out"
return
else
log "Overwriting $out with $hash"
fi
fi
echo $hash > $out
#log "Wrote $out ($hash)"
}
gen-cpp() {
### For printing out in --version
local in=$1 # stamp from Ninja
local h_out=$2
local cc_out=$3
local hash
read -r hash < $in
#log hash=$hash
cat >$h_out <<EOF
extern const char* gCommitHash;
EOF
cat >$cc_out <<EOF
const char* gCommitHash = "$hash";
EOF
}
"$@"