xref: /aosp_15_r20/external/libchrome/third_party/jinja2/get_jinja2.sh (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker#!/bin/bash
2*635a8641SAndroid Build Coastguard Worker# Download and extract Jinja2
3*635a8641SAndroid Build Coastguard Worker# Homepage:
4*635a8641SAndroid Build Coastguard Worker# http://jinja.pocoo.org/
5*635a8641SAndroid Build Coastguard Worker# Installation instructions:
6*635a8641SAndroid Build Coastguard Worker# http://jinja.pocoo.org/docs/intro/#from-the-tarball-release
7*635a8641SAndroid Build Coastguard Worker# Download page:
8*635a8641SAndroid Build Coastguard Worker# https://pypi.python.org/pypi/Jinja2
9*635a8641SAndroid Build Coastguard WorkerPACKAGE='Jinja2'
10*635a8641SAndroid Build Coastguard WorkerVERSION='2.10'
11*635a8641SAndroid Build Coastguard WorkerSRC_URL='https://pypi.python.org/packages/56/e6/332789f295cf22308386cf5bbd1f4e00ed11484299c5d7383378cf48ba47/Jinja2-2.10.tar.gz'
12*635a8641SAndroid Build Coastguard WorkerPACKAGE_DIR='jinja2'
13*635a8641SAndroid Build Coastguard Worker
14*635a8641SAndroid Build Coastguard WorkerCHROMIUM_FILES="README.chromium OWNERS get_jinja2.sh"
15*635a8641SAndroid Build Coastguard WorkerEXTRA_FILES='LICENSE AUTHORS'
16*635a8641SAndroid Build Coastguard WorkerREMOVE_FILES='testsuite'
17*635a8641SAndroid Build Coastguard Worker
18*635a8641SAndroid Build Coastguard WorkerFILENAME="$(basename $SRC_URL)"
19*635a8641SAndroid Build Coastguard WorkerMD5_FILENAME="$FILENAME.md5"
20*635a8641SAndroid Build Coastguard WorkerSHA512_FILENAME="$FILENAME.sha512"
21*635a8641SAndroid Build Coastguard WorkerCHROMIUM_FILES+=" $MD5_FILENAME $SHA512_FILENAME"
22*635a8641SAndroid Build Coastguard Worker
23*635a8641SAndroid Build Coastguard WorkerBUILD_DIR="$PACKAGE-$VERSION"
24*635a8641SAndroid Build Coastguard WorkerTHIRD_PARTY="$(dirname $(realpath $(dirname "${BASH_SOURCE[0]}")))"
25*635a8641SAndroid Build Coastguard WorkerINSTALL_DIR="$THIRD_PARTY/$PACKAGE_DIR"
26*635a8641SAndroid Build Coastguard WorkerOUT_DIR="$INSTALL_DIR/$BUILD_DIR/$PACKAGE_DIR"
27*635a8641SAndroid Build Coastguard WorkerOLD_DIR="$THIRD_PARTY/$PACKAGE_DIR.old"
28*635a8641SAndroid Build Coastguard Worker
29*635a8641SAndroid Build Coastguard Workerfunction check_hashes {
30*635a8641SAndroid Build Coastguard Worker  # Hashes generated via:
31*635a8641SAndroid Build Coastguard Worker  # FILENAME=Jinja2-2.8.tar.gz
32*635a8641SAndroid Build Coastguard Worker  # md5sum "$FILENAME" > "$FILENAME.md5"
33*635a8641SAndroid Build Coastguard Worker  # sha512sum "$FILENAME" > "$FILENAME.sha512"
34*635a8641SAndroid Build Coastguard Worker  # unset FILENAME
35*635a8641SAndroid Build Coastguard Worker
36*635a8641SAndroid Build Coastguard Worker  # MD5
37*635a8641SAndroid Build Coastguard Worker  if ! [ -f "$MD5_FILENAME" ]
38*635a8641SAndroid Build Coastguard Worker  then
39*635a8641SAndroid Build Coastguard Worker    echo "MD5 hash file $MD5_FILENAME not found, could not verify archive"
40*635a8641SAndroid Build Coastguard Worker    exit 1
41*635a8641SAndroid Build Coastguard Worker  fi
42*635a8641SAndroid Build Coastguard Worker
43*635a8641SAndroid Build Coastguard Worker  # 32-digit hash, followed by filename
44*635a8641SAndroid Build Coastguard Worker  MD5_HASHFILE_REGEX="^[0-9a-f]{32}  $FILENAME"
45*635a8641SAndroid Build Coastguard Worker  if ! grep --extended-regex --line-regex --silent \
46*635a8641SAndroid Build Coastguard Worker    "$MD5_HASHFILE_REGEX" "$MD5_FILENAME"
47*635a8641SAndroid Build Coastguard Worker  then
48*635a8641SAndroid Build Coastguard Worker    echo "MD5 hash file $MD5_FILENAME does not contain hash for $FILENAME," \
49*635a8641SAndroid Build Coastguard Worker         'could not verify archive'
50*635a8641SAndroid Build Coastguard Worker    echo 'Hash file contents are:'
51*635a8641SAndroid Build Coastguard Worker    cat "$MD5_FILENAME"
52*635a8641SAndroid Build Coastguard Worker    exit 1
53*635a8641SAndroid Build Coastguard Worker  fi
54*635a8641SAndroid Build Coastguard Worker
55*635a8641SAndroid Build Coastguard Worker  if ! md5sum --check "$MD5_FILENAME"
56*635a8641SAndroid Build Coastguard Worker  then
57*635a8641SAndroid Build Coastguard Worker    echo 'MD5 hash does not match,' \
58*635a8641SAndroid Build Coastguard Worker         "archive file $FILENAME corrupt or compromised!"
59*635a8641SAndroid Build Coastguard Worker    exit 1
60*635a8641SAndroid Build Coastguard Worker  fi
61*635a8641SAndroid Build Coastguard Worker
62*635a8641SAndroid Build Coastguard Worker  # SHA-512
63*635a8641SAndroid Build Coastguard Worker  if ! [ -f "$SHA512_FILENAME" ]
64*635a8641SAndroid Build Coastguard Worker  then
65*635a8641SAndroid Build Coastguard Worker    echo "SHA-512 hash file $SHA512_FILENAME not found," \
66*635a8641SAndroid Build Coastguard Worker         'could not verify archive'
67*635a8641SAndroid Build Coastguard Worker    exit 1
68*635a8641SAndroid Build Coastguard Worker  fi
69*635a8641SAndroid Build Coastguard Worker
70*635a8641SAndroid Build Coastguard Worker  # 128-digit hash, followed by filename
71*635a8641SAndroid Build Coastguard Worker  SHA512_HASHFILE_REGEX="^[0-9a-f]{128}  $FILENAME"
72*635a8641SAndroid Build Coastguard Worker  if ! grep --extended-regex --line-regex --silent \
73*635a8641SAndroid Build Coastguard Worker    "$SHA512_HASHFILE_REGEX" "$SHA512_FILENAME"
74*635a8641SAndroid Build Coastguard Worker  then
75*635a8641SAndroid Build Coastguard Worker    echo "SHA-512 hash file $SHA512_FILENAME does not contain hash for" \
76*635a8641SAndroid Build Coastguard Worker         "$FILENAME, could not verify archive"
77*635a8641SAndroid Build Coastguard Worker    echo 'Hash file contents are:'
78*635a8641SAndroid Build Coastguard Worker    cat "$SHA512_FILENAME"
79*635a8641SAndroid Build Coastguard Worker    exit 1
80*635a8641SAndroid Build Coastguard Worker  fi
81*635a8641SAndroid Build Coastguard Worker
82*635a8641SAndroid Build Coastguard Worker  if ! sha512sum --check "$SHA512_FILENAME"
83*635a8641SAndroid Build Coastguard Worker  then
84*635a8641SAndroid Build Coastguard Worker    echo 'SHA-512 hash does not match,' \
85*635a8641SAndroid Build Coastguard Worker         "archive file $FILENAME corrupt or compromised!"
86*635a8641SAndroid Build Coastguard Worker    exit 1
87*635a8641SAndroid Build Coastguard Worker  fi
88*635a8641SAndroid Build Coastguard Worker}
89*635a8641SAndroid Build Coastguard Worker
90*635a8641SAndroid Build Coastguard Worker
91*635a8641SAndroid Build Coastguard Worker################################################################################
92*635a8641SAndroid Build Coastguard Worker# Body
93*635a8641SAndroid Build Coastguard Worker
94*635a8641SAndroid Build Coastguard Workercd "$INSTALL_DIR"
95*635a8641SAndroid Build Coastguard Workerecho "Downloading $SRC_URL"
96*635a8641SAndroid Build Coastguard Workercurl --remote-name "$SRC_URL"
97*635a8641SAndroid Build Coastguard Workercheck_hashes
98*635a8641SAndroid Build Coastguard Workertar xvzf "$FILENAME"
99*635a8641SAndroid Build Coastguard Worker# Copy extra files over
100*635a8641SAndroid Build Coastguard Workerfor FILE in $CHROMIUM_FILES
101*635a8641SAndroid Build Coastguard Workerdo
102*635a8641SAndroid Build Coastguard Worker  cp "$FILE" "$OUT_DIR"
103*635a8641SAndroid Build Coastguard Workerdone
104*635a8641SAndroid Build Coastguard Worker
105*635a8641SAndroid Build Coastguard Workercd "$BUILD_DIR"
106*635a8641SAndroid Build Coastguard Workerfor FILE in $EXTRA_FILES
107*635a8641SAndroid Build Coastguard Workerdo
108*635a8641SAndroid Build Coastguard Worker  cp "$FILE" "$OUT_DIR"
109*635a8641SAndroid Build Coastguard Workerdone
110*635a8641SAndroid Build Coastguard Worker
111*635a8641SAndroid Build Coastguard Workercd "$OUT_DIR"
112*635a8641SAndroid Build Coastguard Workerfor FILE in $REMOVE_FILES
113*635a8641SAndroid Build Coastguard Workerdo
114*635a8641SAndroid Build Coastguard Worker  rm -fr "$FILE"
115*635a8641SAndroid Build Coastguard Workerdone
116*635a8641SAndroid Build Coastguard Worker
117*635a8641SAndroid Build Coastguard Worker# Replace with new directory
118*635a8641SAndroid Build Coastguard Workercd ..
119*635a8641SAndroid Build Coastguard Workermv "$INSTALL_DIR" "$OLD_DIR"
120*635a8641SAndroid Build Coastguard Workermv "$PACKAGE_DIR" "$INSTALL_DIR"
121*635a8641SAndroid Build Coastguard Workercd "$INSTALL_DIR"
122*635a8641SAndroid Build Coastguard Workerrm -fr "$OLD_DIR"
123*635a8641SAndroid Build Coastguard Worker
124*635a8641SAndroid Build Coastguard Worker# Generating jinja2.gni
125*635a8641SAndroid Build Coastguard Workercat > jinja2.gni <<EOF
126*635a8641SAndroid Build Coastguard Worker# DO NOT EDIT
127*635a8641SAndroid Build Coastguard Worker# This is generated from get_jinja2.sh.
128*635a8641SAndroid Build Coastguard Workerjinja2_sources = [
129*635a8641SAndroid Build Coastguard WorkerEOF
130*635a8641SAndroid Build Coastguard Worker
131*635a8641SAndroid Build Coastguard Workerfor i in $(LC_COLLATE=C ls *.py)
132*635a8641SAndroid Build Coastguard Workerdo
133*635a8641SAndroid Build Coastguard Worker  echo "  \"//third_party/jinja2/${i}\"," >> jinja2.gni
134*635a8641SAndroid Build Coastguard Workerdone
135*635a8641SAndroid Build Coastguard Worker
136*635a8641SAndroid Build Coastguard Workerecho "]" >> jinja2.gni
137