aboutsummaryrefslogtreecommitdiffstats
path: root/devel/llvm-cheriot/files/gen-Makefile.snapshot.sh
blob: 1928b5fd3236d9f380227d64d3c9ab86d8b0bf17 (plain) (blame)
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
#!/bin/sh
#
# Simple script to fetch the latest commits via the github API.  Requires
# curl and jq.  Uses unauthenticated access which is ratelimited to 60
# queries per hour.

REPOS_URL=https://api.github.com/repos/CHERIoT-Platform
MAX_DATE=1970101

tmpfile=`mktemp -t gen-Makefile.snapshot`

query_repo()
{
	curl ${REPOS_URL}/$1/branches/cheriot > $tmpfile

	# Accumulate the dates of the last commits to find the snapshot date
	committime=`jq -r '.commit.commit.committer.date' $tmpfile`
	committime=${committime%%T*}
	year=${committime%%-*}
	month=${committime%-*}
	month=${month#*-}
	day=${committime##*-}
	dateint=${year}${month}${day}
	if [ $dateint -gt $MAX_DATE ]; then
		export MAX_DATE=$dateint
	fi

	SHA=`jq -r '.commit.sha' $tmpfile`
}

query_repo llvm-project
LLVM_COMMIT=$SHA

cat <<EOF > Makefile.snapshot
# Generated file!  Do not edit!
#
# Generated by: files/gen-Makefile.snapshot.sh.
#
LLVM_MAJOR=	21
LLVM_RELEASE=	\${LLVM_MAJOR}.1.1
SNAPDATE=	${MAX_DATE}

LLVM_COMMIT=		${LLVM_COMMIT}
EOF

rm -f $tmpfile