| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# Use this script to update libexpat |
| 4 |
|
| 5 |
set -e |
| 6 |
set -o pipefail |
| 7 |
|
| 8 |
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then |
| 9 |
echo "A bash version >= 4 required. Got: $BASH_VERSION" >&2 |
| 10 |
exit 1 |
| 11 |
fi |
| 12 |
|
| 13 |
# Update this when updating to a new version after verifying that the changes |
| 14 |
# the update brings in are good. These values are used for verifying the SBOM, too. |
| 15 |
expected_libexpat_tag="R_2_7_3" |
| 16 |
expected_libexpat_version="2.7.3" |
| 17 |
expected_libexpat_sha256="821ac9710d2c073eaf13e1b1895a9c9aa66c1157a99635c639fbff65cdbdd732" |
| 18 |
|
| 19 |
expat_dir="$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")" |
| 20 |
cd ${expat_dir} |
| 21 |
|
| 22 |
# Step 1: download and copy files |
| 23 |
curl --location "https://github.com/libexpat/libexpat/releases/download/${expected_libexpat_tag}/expat-${expected_libexpat_version}.tar.gz" > libexpat.tar.gz |
| 24 |
echo "${expected_libexpat_sha256} libexpat.tar.gz" | sha256sum --check |
| 25 |
|
| 26 |
# Step 2: Pull files from the libexpat distribution |
| 27 |
declare -a lib_files |
| 28 |
lib_files=( |
| 29 |
ascii.h |
| 30 |
asciitab.h |
| 31 |
expat.h |
| 32 |
expat_external.h |
| 33 |
iasciitab.h |
| 34 |
internal.h |
| 35 |
latin1tab.h |
| 36 |
nametab.h |
| 37 |
siphash.h |
| 38 |
utf8tab.h |
| 39 |
winconfig.h |
| 40 |
xmlparse.c |
| 41 |
xmlrole.c |
| 42 |
xmlrole.h |
| 43 |
xmltok.c |
| 44 |
xmltok.h |
| 45 |
xmltok_impl.c |
| 46 |
xmltok_impl.h |
| 47 |
xmltok_ns.c |
| 48 |
) |
| 49 |
for f in "${lib_files[@]}"; do |
| 50 |
tar xzvf libexpat.tar.gz "expat-${expected_libexpat_version}/lib/${f}" --strip-components 2 |
| 51 |
done |
| 52 |
rm libexpat.tar.gz |
| 53 |
|
| 54 |
# Step 3: Add the namespacing include to expat_external.h |
| 55 |
sed -i 's/# define Expat_External_INCLUDED 1/&\n\/* Namespace external symbols to allow multiple libexpat version to\n co-exist. \*\/\n#include "pyexpatns.h"/' expat_external.h |
| 56 |
|
| 57 |
echo "Updated; verify all is okay using git diff and git status." |