• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2#
3# Use this script to update libexpat
4
5set -e
6set -o pipefail
7
8if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
9  echo "A bash version >= 4 required. Got: $BASH_VERSION" >&2
10  exit 1
11fi
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.
15expected_libexpat_tag="R_2_6_4"
16expected_libexpat_version="2.6.4"
17expected_libexpat_sha256="fd03b7172b3bd7427a3e7a812063f74754f24542429b634e0db6511b53fb2278"
18
19expat_dir="$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"
20cd ${expat_dir}
21
22# Step 1: download and copy files
23curl --location "https://github.com/libexpat/libexpat/releases/download/${expected_libexpat_tag}/expat-${expected_libexpat_version}.tar.gz" > libexpat.tar.gz
24echo "${expected_libexpat_sha256} libexpat.tar.gz" | sha256sum --check
25
26# Step 2: Pull files from the libexpat distribution
27declare -a lib_files
28lib_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)
49for f in "${lib_files[@]}"; do
50  tar xzvf libexpat.tar.gz "expat-${expected_libexpat_version}/lib/${f}" --strip-components 2
51done
52rm libexpat.tar.gz
53
54# Step 3: Add the namespacing include to expat_external.h
55sed -i 's/#define Expat_External_INCLUDED 1/&\n\n\/* Namespace external symbols to allow multiple libexpat version to\n   co-exist. \*\/\n#include "pyexpatns.h"/' expat_external.h
56
57echo "Updated; verify all is okay using git diff and git status."
58