Debian Codegraph @

Modules/expat/refresh.sh

raw
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_8_0"
16 expected_libexpat_version="2.8.0"
17 expected_libexpat_sha256="c7cec5f60ea3a42e7780781c6745255c19aa3dbfeeae58646b7132f88dc24780"
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
28 tar xzvf libexpat.tar.gz "expat-${expected_libexpat_version}/COPYING" --strip-components 2
29
30 declare -a lib_files
31 lib_files=(
32 ascii.h
33 asciitab.h
34 expat.h
35 expat_external.h
36 iasciitab.h
37 internal.h
38 latin1tab.h
39 nametab.h
40 siphash.h
41 utf8tab.h
42 winconfig.h
43 xmlparse.c
44 xmlrole.c
45 xmlrole.h
46 xmltok.c
47 xmltok.h
48 xmltok_impl.c
49 xmltok_impl.h
50 xmltok_ns.c
51 )
52 for f in "${lib_files[@]}"; do
53 tar xzvf libexpat.tar.gz "expat-${expected_libexpat_version}/lib/${f}" --strip-components 2
54 done
55 rm libexpat.tar.gz
56
57 # Step 3: Add the namespacing include to expat_external.h
58 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
59
60 # Step 4: Skip the Windows rand_s entropy path in xmlparse.c when
61 # XML_POOR_ENTROPY is set.
62 sed -z -i 's|#if defined(_WIN32)\n# include "random_rand_s\.h"\n#endif /\* defined(_WIN32) \*/|#if defined(_WIN32) \&\& ! defined(XML_POOR_ENTROPY)\n# include "random_rand_s.h"\n#endif /* defined(_WIN32) \&\& ! defined(XML_POOR_ENTROPY) */|' xmlparse.c
63 sed -z -i 's|# ifdef _WIN32\n if (writeRandomBytes_rand_s|# if defined(_WIN32) \&\& ! defined(XML_POOR_ENTROPY)\n if (writeRandomBytes_rand_s|' xmlparse.c
64
65 if ! grep -q '#if defined(_WIN32) && ! defined(XML_POOR_ENTROPY)' xmlparse.c; then
66 echo "
67 Error: rand_s gate not patched in xmlparse.c;
68 This may be due to source changes and will require updating this script" >&2
69 exit 1
70 fi
71
72 echo "
73 Updated! next steps:
74 - Verify all is okay:
75 git diff
76 git status
77 - Regenerate the sbom file
78 make regen-sbom
79 - Update warning count in Tools/build/.warningignore_macos
80 (use info from CI if not on a Mac)
81 "