Skip to content

Commit 245a5cd

Browse files
committed
Improvements to patch testing
1 parent 96f1fdb commit 245a5cd

4 files changed

Lines changed: 225 additions & 53 deletions

File tree

.github/workflows/jni-patched-ci.yml

Lines changed: 127 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,154 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424

25-
- name: Resolve wolfSSL ref from patch defines
26-
id: resolve
25+
- name: Install prerequisites
2726
run: |
28-
set -euo pipefail
27+
sudo apt-get update
28+
sudo apt-get install -y jq curl
2929
30-
# Find WOLFSSL_PR*_PATCH_APPLIED defines in wolfssl source.
31-
defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"
30+
- name: Find patch defines
31+
id: find_defines
32+
run: |
33+
set -euo pipefail
34+
defines=""
35+
if ! defines="$(./scripts/find-wolfssl-pr-patch-defines.sh)"; then
36+
echo "::warning::find-wolfssl-pr-patch-defines.sh failed; skipping patched CI."
37+
echo "should_run=false" >> "$GITHUB_OUTPUT"
38+
exit 0
39+
fi
3240
if [ -z "$defines" ]; then
3341
echo "::warning::No WOLFSSL_PR*_PATCH_APPLIED defines found; skipping patched CI."
3442
echo "should_run=false" >> "$GITHUB_OUTPUT"
3543
exit 0
3644
fi
3745
echo "Found patch defines:"
3846
printf "%s\n" "$defines"
47+
{
48+
echo "should_run=true"
49+
echo "defines<<EOF"
50+
printf "%s\n" "$defines"
51+
echo "EOF"
52+
} >> "$GITHUB_OUTPUT"
53+
54+
- name: Evaluate PR statuses
55+
id: eval_prs
56+
if: steps.find_defines.outputs.should_run == 'true'
57+
run: |
58+
set -euo pipefail
3959
40-
# Find the highest PR number from the defines.
41-
pr_number="$(printf "%s\n" "$defines" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\1/' | sort -n | tail -1)"
42-
if [ -z "$pr_number" ]; then
43-
echo "::warning::Failed to derive PR number from patch defines; skipping patched CI."
44-
echo "should_run=false" >> "$GITHUB_OUTPUT"
45-
exit 0
46-
fi
47-
echo "Highest PR number from defines: $pr_number"
60+
defines="${{ steps.find_defines.outputs.defines }}"
61+
merged_all=true
62+
open_count=0
63+
open_repo=""
64+
open_ref=""
65+
open_pr=""
66+
has_invalid=false
4867
49-
# Check PR status via GitHub API.
50-
pr_json="$(curl -fsSL "https://api.github.com/repos/wolfSSL/wolfssl/pulls/$pr_number" || true)"
51-
if [ -z "$pr_json" ]; then
52-
echo "::warning::Unable to fetch PR #$pr_number from GitHub API; skipping patched CI."
53-
echo "should_run=false" >> "$GITHUB_OUTPUT"
54-
exit 0
55-
fi
56-
echo "Fetched PR #$pr_number info from GitHub API."
68+
echo "Evaluating patch defines:"
69+
printf "%s\n" "$defines"
5770
58-
state="$(printf "%s" "$pr_json" | jq -r '.state // empty')"
59-
merged_at="$(printf "%s" "$pr_json" | jq -r '.merged_at // empty')"
60-
head_repo="$(printf "%s" "$pr_json" | jq -r '.head.repo.full_name // empty')"
61-
head_ref="$(printf "%s" "$pr_json" | jq -r '.head.ref // empty')"
71+
while read -r define; do
72+
define="$(printf "%s" "$define" | tr -d '\r' | xargs)"
73+
[ -z "$define" ] && continue
74+
pr_number="$(printf "%s" "$define" | sed -E 's/^WOLFSSL_PR([0-9]+)_PATCH_APPLIED$/\1/')"
75+
if [ -z "$pr_number" ] || [ "$pr_number" = "$define" ]; then
76+
echo "::warning::Failed to derive PR number from define $define; skipping patched CI."
77+
echo "should_run=false" >> "$GITHUB_OUTPUT"
78+
exit 0
79+
fi
80+
81+
fork_ref_status=""
82+
if ! fork_ref_status="$(./scripts/find-pr-fork-branch.sh "$pr_number" --repo wolfSSL/wolfssl)"; then
83+
echo "::warning::find-pr-fork-branch.sh failed for PR #$pr_number; skipping patched CI."
84+
echo "should_run=false" >> "$GITHUB_OUTPUT"
85+
exit 0
86+
fi
87+
echo "PR #$pr_number raw status: [$fork_ref_status]"
88+
if [ -z "$fork_ref_status" ]; then
89+
echo "::warning::Unable to resolve PR #$pr_number fork/branch; skipping patched CI."
90+
echo "should_run=false" >> "$GITHUB_OUTPUT"
91+
exit 0
92+
fi
93+
94+
fork_ref="$(printf "%s" "$fork_ref_status" | sed -E 's/ \\([^)]*\\)$//')"
95+
pr_status_raw="$(printf "%s" "$fork_ref_status" | sed -E 's/^.* \\(([^)]*)\\)$/\\1/')"
96+
pr_status="$(printf "%s" "$pr_status_raw" | tr -d '\r' | tr '[:upper:]' '[:lower:]' | xargs)"
97+
echo "PR #$pr_number parsed status: [$pr_status]"
98+
99+
head_repo="${fork_ref%/*}"
100+
head_ref="${fork_ref#*/}"
101+
if [ -z "$head_repo" ] || [ -z "$head_ref" ] || [ "$head_repo" = "$head_ref" ]; then
102+
echo "::warning::Malformed fork/branch from helper script; skipping patched CI."
103+
echo "should_run=false" >> "$GITHUB_OUTPUT"
104+
exit 0
105+
fi
106+
107+
case "$pr_status" in
108+
merged|closed)
109+
if [ "$pr_status" = "closed" ]; then
110+
echo "::warning::PR #$pr_number reports status 'closed'; treating as merged since a patch define exists."
111+
fi
112+
continue
113+
;;
114+
open)
115+
merged_all=false
116+
open_count=$((open_count + 1))
117+
open_repo="$head_repo"
118+
open_ref="$head_ref"
119+
open_pr="$pr_number"
120+
;;
121+
*)
122+
echo "::warning::Unknown PR status '$pr_status' for #$pr_number (raw: $fork_ref_status); skipping patched CI."
123+
merged_all=false
124+
has_invalid=true
125+
;;
126+
esac
127+
done <<EOF
128+
$defines
129+
EOF
130+
131+
{
132+
echo "MERGED_ALL=$merged_all"
133+
echo "OPEN_COUNT=$open_count"
134+
echo "OPEN_REPO=$open_repo"
135+
echo "OPEN_REF=$open_ref"
136+
echo "OPEN_PR=$open_pr"
137+
echo "HAS_INVALID=$has_invalid"
138+
} >> "$GITHUB_ENV"
139+
140+
echo "should_run=true" >> "$GITHUB_OUTPUT"
62141
63-
if [ -n "$merged_at" ]; then
64-
echo "PR #$pr_number is merged; using wolfSSL master branch."
142+
- name: Resolve wolfSSL ref from patch defines
143+
id: resolve
144+
if: steps.find_defines.outputs.should_run == 'true' && steps.eval_prs.outputs.should_run == 'true'
145+
run: |
146+
set -euo pipefail
147+
148+
if [ "${MERGED_ALL}" = "true" ]; then
149+
echo "All PRs are merged; using wolfSSL master branch."
65150
echo "should_run=true" >> "$GITHUB_OUTPUT"
66151
echo "wolfssl_repo=wolfSSL/wolfssl" >> "$GITHUB_OUTPUT"
67152
echo "wolfssl_ref=master" >> "$GITHUB_OUTPUT"
68-
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
153+
echo "pr_number=all" >> "$GITHUB_OUTPUT"
154+
exit 0
155+
fi
156+
157+
if [ "${HAS_INVALID}" = "true" ]; then
158+
echo "::warning::One or more PRs are not merged or open; skipping patched CI."
159+
echo "should_run=false" >> "$GITHUB_OUTPUT"
69160
exit 0
70161
fi
71162
72-
if [ "$state" = "open" ] && [ -n "$head_repo" ] && [ -n "$head_ref" ]; then
163+
if [ "${OPEN_COUNT}" -eq 1 ]; then
73164
echo "should_run=true" >> "$GITHUB_OUTPUT"
74-
echo "wolfssl_repo=$head_repo" >> "$GITHUB_OUTPUT"
75-
echo "wolfssl_ref=$head_ref" >> "$GITHUB_OUTPUT"
76-
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
77-
echo "PR #$pr_number is open; using branch $head_ref from repo $head_repo."
165+
echo "wolfssl_repo=${OPEN_REPO}" >> "$GITHUB_OUTPUT"
166+
echo "wolfssl_ref=${OPEN_REF}" >> "$GITHUB_OUTPUT"
167+
echo "pr_number=${OPEN_PR}" >> "$GITHUB_OUTPUT"
168+
echo "Exactly one PR is open (#${OPEN_PR}); using branch ${OPEN_REF} from repo ${OPEN_REPO}."
78169
exit 0
79170
fi
80171
81-
echo "::warning::PR #$pr_number is not merged or has no accessible branch; skipping patched CI."
172+
echo "::warning::Multiple open PRs found; skipping patched CI."
82173
echo "should_run=false" >> "$GITHUB_OUTPUT"
83174
84175
patched_jni_build:
@@ -126,10 +217,9 @@ jobs:
126217
run: |
127218
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib" >> "$GITHUB_ENV"
128219
129-
- name: Build and test JNI library with all patches
220+
- name: Build and test JNI library with all patches enabled
130221
run: |
131-
make all-patched PREFIX=$GITHUB_WORKSPACE/build-dir
132-
make check
222+
make build check PREFIX=$GITHUB_WORKSPACE/build-dir ENABLE_PATCHES=1
133223
134224
- name: Show logs on failure
135225
if: failure() || cancelled()

IDE/Android/app/src/main/cpp/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,14 @@ aux_source_directory(${wolfssl_DIR}/src TLS_SOURCES)
252252
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/bio.c)
253253
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/conf.c)
254254
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/pk.c)
255+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/pk_ec.c)
256+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/pk_rsa.c)
255257
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_bn.c)
258+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_api_cert.c)
259+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_api_crl_ocsp.c)
260+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_api_pk.c)
256261
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_asn1.c)
262+
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_ech.c)
257263
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_certman.c)
258264
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_crypto.c)
259265
list(REMOVE_ITEM TLS_SOURCES ${wolfssl_DIR}/src/ssl_load.c)
@@ -268,6 +274,7 @@ if ("${WOLFSSL_PKG_TYPE}" MATCHES "normal")
268274
# Add crypto sources to CRYPTO_SOURCES, remove files that are included inline by other files
269275
aux_source_directory(${wolfssl_DIR}/wolfcrypt/src CRYPTO_SOURCES)
270276
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/evp.c)
277+
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/evp_pk.c)
271278
list(REMOVE_ITEM CRYPTO_SOURCES ${wolfssl_DIR}/wolfcrypt/src/misc.c)
272279

273280
elseif("${WOLFSSL_PKG_TYPE}" MATCHES "fipsready")

Makefile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ endif
2121
all: build
2222

2323
build: java.sh build.xml
24-
./java.sh $(INSTALL_DIR)
24+
@cflags=""; \
25+
if [ "$(ENABLE_PATCHES)" = "1" ]; then \
26+
defines="$$(./scripts/find-wolfssl-pr-patch-defines.sh)"; \
27+
if [ -z "$$defines" ]; then \
28+
echo "warning: no WOLFSSL_PR*_PATCH_APPLIED defines found; building without patches"; \
29+
else \
30+
for define in $$defines; do \
31+
cflags="$$cflags -D$$define"; \
32+
done; \
33+
fi; \
34+
fi; \
35+
CFLAGS="$$cflags" ./java.sh $(INSTALL_DIR); \
2536
ant
2637

2738
check: build
@@ -30,21 +41,6 @@ check: build
3041
clean:
3142
ant clean cleanjni
3243

33-
# Enable all WOLFSSL_PR*_PATCH_APPLIED defines when building JNI.
34-
# Requires latest/recent wolfssl source with patches applied. This is not
35-
# detected automatically.
36-
all-patched:
37-
@defines="$$(./scripts/find-wolfssl-pr-patch-defines.sh)"; \
38-
if [ -z "$$defines" ]; then \
39-
echo "warning: no WOLFSSL_PR*_PATCH_APPLIED defines found; skipping all-patched"; \
40-
exit 0; \
41-
fi; \
42-
cflags=""; \
43-
for define in $$defines; do \
44-
cflags="$$cflags -D$$define"; \
45-
done; \
46-
CFLAGS="$$cflags" ./java.sh $(INSTALL_DIR); \
47-
ant
4844

4945
install:
5046
$(INSTALL) -d $(INSTALL_DIR)/$(LIBDIR)

scripts/find-pr-fork-branch.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
3+
# Given a PR number, print the originating fork (repo full_name) and branch.
4+
# Default repo is wolfSSL/wolfssl. Override with --repo owner/name.
5+
6+
set -euo pipefail
7+
8+
usage() {
9+
cat <<'EOF'
10+
Usage: scripts/find-pr-fork-branch.sh <pr_number> [--repo owner/name]
11+
12+
Outputs:
13+
<fork_full_name>/<branch_name> (<open|closed|merged|unknown>)
14+
15+
Example:
16+
scripts/find-pr-fork-branch.sh 9631
17+
scripts/find-pr-fork-branch.sh 9631 --repo wolfSSL/wolfssl
18+
EOF
19+
}
20+
21+
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
22+
usage
23+
exit 0
24+
fi
25+
26+
if [ -z "${1:-}" ]; then
27+
usage
28+
exit 2
29+
fi
30+
31+
pr_number="$1"
32+
shift
33+
34+
repo="wolfSSL/wolfssl"
35+
if [ "${1:-}" = "--repo" ]; then
36+
if [ -z "${2:-}" ]; then
37+
echo "error: --repo requires owner/name" >&2
38+
exit 2
39+
fi
40+
repo="$2"
41+
shift 2
42+
fi
43+
44+
if [ -n "${1:-}" ]; then
45+
echo "error: unexpected argument: $1" >&2
46+
exit 2
47+
fi
48+
49+
if ! command -v jq >/dev/null 2>&1; then
50+
echo "error: jq is required but not installed" >&2
51+
exit 127
52+
fi
53+
54+
pr_json="$(curl -fsSL "https://api.github.com/repos/${repo}/pulls/${pr_number}" || true)"
55+
if [ -z "$pr_json" ]; then
56+
echo "error: failed to fetch PR #${pr_number} from ${repo}" >&2
57+
exit 1
58+
fi
59+
60+
head_repo="$(printf "%s" "$pr_json" | jq -r '.head.repo.full_name // empty')"
61+
head_ref="$(printf "%s" "$pr_json" | jq -r '.head.ref // empty')"
62+
state="$(printf "%s" "$pr_json" | jq -r '.state // empty')"
63+
merged_at="$(printf "%s" "$pr_json" | jq -r '.merged_at // empty')"
64+
65+
if [ -z "$head_repo" ] || [ -z "$head_ref" ]; then
66+
echo "error: PR #${pr_number} missing head repo/ref data" >&2
67+
exit 1
68+
fi
69+
70+
status="$state"
71+
if [ -n "$merged_at" ]; then
72+
status="merged"
73+
fi
74+
75+
if [ -z "$status" ]; then
76+
status="unknown"
77+
fi
78+
79+
echo "${head_repo}/${head_ref} (${status})"

0 commit comments

Comments
 (0)