Extend bitcoin re-export script to check against units
What changed, and why it matters
This commit updates an internal shell script used to generate a Rust test file. The script now also checks that types from a secondary crate (`bitcoin_units`) are correctly re-exported by the main `bitcoin` crate. It is a build/test tooling improvement with no runtime code changes and no security relevance.
No security action needed; review as normal build-tooling maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extends contrib/generate-bitcoin-re-export-test.sh to parse units/api/all-features.txt in addition to primitives/api/all-features.txt. It generates use statements for pub enum, pub struct, pub mod, and pub use declarations so missing re-exports from bitcoin_units into the bitcoin crate are caught at compile time. No library code, cryptographic logic, parsing, or network handling is modified.
Changed components
contrib/generate-bitcoin-re-export-test.shInspect captured patch +43 / −4
diff --git a/contrib/generate-bitcoin-re-export-test.sh b/contrib/generate-bitcoin-re-export-test.sh
index 0df2b037..2c5cc978 100755
--- a/contrib/generate-bitcoin-re-export-test.sh
+++ b/contrib/generate-bitcoin-re-export-test.sh
@@ -3,12 +3,13 @@
# Script for generating a Rust test file that verifies all bitcoin_primitives
# items are re-exported in the `bitcoin` crate.
#
-# The script parses primitives/api/all-features.txt and generates use statements
-# that will fail to compile if any re-exports are missing.
+# The script parses primitives/api/all-features.txt and units/api/all-features.txt
+# to generate use statements that will fail to compile if any re-exports are missing.
set -euo pipefail
api_file="./primitives/api/all-features.txt"
+units_api_file="./units/api/all-features.txt"
output_file="./bitcoin/tests/check-re-exports.rs"
usage() {
@@ -21,8 +22,9 @@ DESCRIPTION
Generates a Rust test file that verifies all public types and modules from
bitcoin_primitives are re-exported in the bitcoin crate;
- The script parses primitives/api/all-features.txt and creates use statements for
- every 'pub enum', 'pub struct', and 'pub mod' declaration.
+ The script parses primitives/api/all-features.txt and units/api/all-features.txt
+ to creates use statements for every 'pub enum', 'pub struct', and 'pub mod'
+ declaration.
Output file: bitcoin/tests/check-re-exports.rs
EOF
@@ -83,6 +85,7 @@ EOF
local use_statements=()
local seen_items=()
+ # Process primitives API: types declared in or re-exported by primitives
while IFS= read -r line; do
local path=""
@@ -115,6 +118,38 @@ EOF
fi
done < "$api_file"
+ # Also process units API: individual types inside modules that primitives re-exports
+ # wholesale (e.g. `pub use units::locktime::absolute`) are not enumerated in the
+ # primitives API surface, so we must check them against bitcoin directly.
+ while IFS= read -r line; do
+ local path=""
+
+ # Extract pub enum
+ if [[ "$line" =~ pub\ enum\ (bitcoin_units::[^[:space:]]+) ]]; then
+ path="${BASH_REMATCH[1]}"
+ # Extract pub struct
+ elif [[ "$line" =~ pub\ struct\ (bitcoin_units::[^[:space:]\(]+) ]]; then
+ path="${BASH_REMATCH[1]}"
+ # Extract pub mod
+ elif [[ "$line" =~ ^pub\ mod\ (bitcoin_units::[^[:space:]]+)$ ]]; then
+ path="${BASH_REMATCH[1]}"
+ # Extract pub use (re-exports)
+ elif [[ "$line" =~ ^pub\ use\ (bitcoin_units::[^[:space:]]+)$ ]]; then
+ path="${BASH_REMATCH[1]}"
+ fi
+
+ if [[ -n "$path" ]]; then
+ # Remove generic type parameters (e.g., <T>)
+ path="${path%%<*}"
+
+ local bitcoin_path="${path//bitcoin_units::/bitcoin::}"
+ if [[ " ${seen_items[*]} " != *" $bitcoin_path "* ]]; then
+ seen_items+=("$bitcoin_path")
+ use_statements+=(" use $bitcoin_path as _;")
+ fi
+ fi
+ done < "$units_api_file"
+
# Sort use statements and add to file
printf '%s\n' "${use_statements[@]}" | sort >> "$temp_file"
@@ -130,6 +165,10 @@ check_required_files() {
err "Required file not found: $api_file"
fi
+ if [[ ! -f "$units_api_file" ]]; then
+ err "Required file not found: $units_api_file"
+ fi
+
local output_dir
output_dir=$(dirname "$output_file")
if [[ ! -d "$output_dir" ]]; then
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.