Repository navigation
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·1025 lines (978 loc) · 49.1 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·1025 lines (978 loc) · 49.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# shellcheck disable=SC2016
# (backticks in the printf formats below are markdown, not command substitution)
# sync.sh - maintain the freebsd/<target> branches of azsupport/php-src.
#
# For every target in freebsd/targets.conf:
# 1. resolve the upstream commit (Remi Collet's backport branch, or the newest
# official php-src release tag of that minor version);
# 2. skip the target if freebsd/<target> already carries that upstream commit
# and the same patch set (unless --force) - checked before any big fetch;
# a tip that no release points at (a run stopped between the push and the
# release) is built and released again;
# 3. rebuild freebsd/<target> = upstream
# + one commit applying the curated FreeBSD ports patches
# + commits for our build compatibility patches, interim security
# backports, bundled PECL extensions, curl and PCRE, and the build
# options of this fork (freebsd/patches/<target>/feature-*.patch)
# + one commit adding the build id to the php -v banner (PHP_VERSION is
# left untouched; php -v shows "... (fork: 20261021-fbsd-802c2107)")
# + one commit prepending FreeBSD notes to README.md;
# 4. push the branch and mirror the upstream ref under its original name;
# 5. build a release tarball (tools/makedist.sh) and publish it as a GitHub
# release, plus a moving "freebsd-<target>-latest" release.
#
# The branch README and the dated release notes list the ports patches that are
# applied and, with the reason from freebsd/patches/<target>/SKIPPED, the ones that
# are not. Regular runs also bring the notes of up-to-date targets in step with
# this script (only releases whose notes differ are edited).
#
# Usage: run inside a git clone of azsupport/php-src (remote 'origin'):
# tools/sync.sh [--local] [--force] [--no-release] [--check] [--notes] [target ...]
# --local build branches locally only: no push, no releases
# --force rebuild even if nothing changed upstream
# --no-release push branches but do not build tarballs or releases
# --check only report which targets are up to date (no fetch, no push);
# with --notes, print the notes instead of updating the releases
# --notes only rewrite the notes of the releases of the current branch
# tips (no rebuild); the tips must carry the current patch set
#
# Environment:
# FETCH_DEPTH limit the upstream fetch depth (default: full history, which
# keeps pushes valid when the fork lacks new upstream history)
# GH_REPO repository for releases and API calls (default:
# $GITHUB_REPOSITORY or azsupport/php-src); needs gh + GH_TOKEN
# GIT_AUTHOR_NAME / GIT_AUTHOR_EMAIL commit identity (default: aZ)
# EXTRA_TRAILERS extra lines appended to generated commit messages
# DIST_DIR where tarballs are built (default: ./.sync-dist)
set -eu
# Bump when the generated branch content changes (commit layout, README block),
# so that every branch is rebuilt once. Tooling-only changes must not bump it;
# wording changes of the README block reach a branch with its next rebuild.
layout_version=8
main_dir="$(cd "$(dirname "$0")/.." && pwd)"
conf="$main_dir/freebsd/targets.conf"
# PECL extensions bundled into ext/<name>, and fixes for their sources.
pecl_conf="$main_dir/freebsd/pecl.conf"
pecl_patches="$main_dir/freebsd/pecl"
# curl for --with-curl=bundled (ext/curl/libcurl, the libraries it needs in
# ext/curl/deps): releases, patch, build script, hook; tools/curl-sources.sh puts
# the sources into the tree.
curl_conf="$main_dir/freebsd/curl.conf"
curl_deps_conf="$main_dir/freebsd/curl-deps.conf"
curl_dir="$main_dir/freebsd/curl"
# PCRE instead of the copy upstream bundles: release, import scripts, test fixes.
pcre_conf="$main_dir/freebsd/pcre.conf"
pcre_dir="$main_dir/freebsd/pcre"
gh_repo="${GH_REPO:-${GITHUB_REPOSITORY:-azsupport/php-src}}"
dist_dir="${DIST_DIR:-$(pwd)/.sync-dist}"
local_only=0 force=0 release=1 check_only=0 notes_only=0
while [ $# -gt 0 ]; do
case "$1" in
--local) local_only=1; release=0 ;;
--check) check_only=1; release=0 ;;
--force) force=1 ;;
--no-release) release=0 ;;
--notes) notes_only=1; release=0 ;;
-*) echo "sync: unknown option $1" >&2; exit 2 ;;
*) break ;;
esac
shift
done
want="$*"
export GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-aZ}"
export GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-github@azsupport.com}"
export GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-$GIT_AUTHOR_NAME}"
export GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-$GIT_AUTHOR_EMAIL}"
today="$(date -u +%Y%m%d)"
today_human="$(date -u +%d.%m.%Y)"
# Interim backports applied to the target being processed (one path per line).
bp_list="$(mktemp)"
# PECL extensions of the target being processed ("name version url commit" lines).
pecl_list="$(mktemp)"
trap 'rm -f "$bp_list" "$pecl_list"' EXIT
log() { printf '[sync] %s\n' "$*"; }
short() { printf '%s' "$1" | cut -c1-"${2:-12}"; }
sha256_of() { # SHA-256 of stdin
if command -v sha256sum >/dev/null 2>&1; then sha256sum | cut -c1-64; else sha256 -q; fi
}
# Hash of everything a branch build is made of. SKIPPED is documentation only and
# deliberately not part of it.
patchset_of() {
{
cat "$patch_dir"/patch-*
for c in "$patch_dir"/compat-*.patch; do if [ -f "$c" ]; then cat "$c"; fi; done
for b in "$patch_dir"/backport-*.patch; do if [ -f "$b" ]; then cat "$b"; fi; done
for f in "$patch_dir"/feature-*.patch; do if [ -f "$f" ]; then cat "$f"; fi; done
pecl_entries
pecl_entries | while read -r n v u c; do
pp="$(pecl_patch "$n" "$v")"
if [ -f "$pp" ]; then cat "$pp"; fi
done
curl_entry
if has_curl; then
for f in "$curl_dir"/* "$curl_deps_conf" "$main_dir/tools/curl-sources.sh"; do if [ -f "$f" ]; then cat "$f"; fi; done
fi
pcre_entry
if has_pcre; then
for f in "$pcre_dir"/*; do if [ -f "$f" ]; then cat "$f"; fi; done
fi
echo "$target $url $ref $port $portrev layout=$layout_version"
} | sha256_of
}
# Print "<commit-sha> <full-ref>" for a target's upstream (tags are peeled).
resolve_upstream() {
url="$1" ref="$2"
case "$ref" in
latest-tag:*)
prefix="${ref#latest-tag:}"
tag="$(git ls-remote --tags --refs "$url" "refs/tags/${prefix}*" \
| awk '{print $2}' | sed 's#^refs/tags/##' \
| grep -E "^${prefix}[0-9]+\$" | sort -t. -k3,3n | tail -1)"
[ -n "$tag" ] || return 1
lines="$(git ls-remote --tags "$url" "refs/tags/$tag" "refs/tags/$tag^{}")"
sha="$(printf '%s\n' "$lines" | awk '$2 ~ /\^\{\}$/ {print $1}')"
[ -n "$sha" ] || sha="$(printf '%s\n' "$lines" | awk 'NR == 1 {print $1}')"
printf '%s refs/tags/%s\n' "$sha" "$tag"
;;
refs/heads/*)
printf '%s %s\n' "$(git ls-remote "$url" "$ref" | awk 'NR == 1 {print $1}')" "$ref"
;;
*) return 1 ;;
esac
}
# Commit message of the current freebsd/<target> tip on GitHub, without fetching trees.
current_message() {
tip="$(git ls-remote origin "refs/heads/$1" | awk 'NR == 1 {print $1}')"
[ -n "$tip" ] || return 1
gh api "repos/$gh_repo/git/commits/$tip" --jq .message
}
# Upstream description for the README and the release notes.
upstream_info() {
up_web="${url%.git}"
case "$up_ref" in
refs/tags/*)
up_name="${up_ref#refs/tags/}"
summary="Official PHP $php_ver release ([php/php-src](https://github.com/php/php-src), tag \`$up_name\`) plus a few FreeBSD ports patches, for building PHP by hand on FreeBSD."
;;
*)
up_name="${up_ref#refs/heads/}"
summary="PHP $target is end-of-life upstream. This branch follows Remi Collet's community security backports ([remicollet/php-src-security](https://github.com/remicollet/php-src-security), branch \`$up_name\`) and adds a few FreeBSD ports patches, for building PHP $target by hand on FreeBSD."
;;
esac
up_link="[${up_web#https://github.com/} \`$up_name\`]($up_web/tree/$up_name)"
}
port_url() { printf 'https://github.com/freebsd/freebsd-ports/tree/%s/lang/%s/files' "$portrev" "$port"; }
# Applied and not applied ports files as markdown lists. $1 is a line prefix
# ("> " inside the README block); the reasons come from SKIPPED, and files that
# share a reason are listed on one line.
ports_notes() {
printf '%s**Applied** (commit "Apply curated FreeBSD ports patches"):\n%s\n' "$1" "${1% }"
for p in "$patch_dir"/patch-*; do
printf '%s- `%s` (`%s`): %s\n' "$1" "${p##*/}" \
"$(grep -m1 '^+++ ' "$p" | awk '{print $2}')" \
"$(sed -n 's/^Description: //p' "$p" | head -1)"
done
if [ -f "$patch_dir/SKIPPED" ]; then
printf '%s\n%s**Not applied:**\n%s\n' "${1% }" "$1" "${1% }"
grep -vE '^[[:space:]]*(#|$)' "$patch_dir/SKIPPED" | awk -v pfx="$1" '
{
i = index($0, ": ")
f = "`" substr($0, 1, i - 1) "`"
r = substr($0, i + 2)
if (r in files) files[r] = files[r] ", " f
else { order[++n] = r; files[r] = f }
}
END { for (k = 1; k <= n; k++) printf "%s- %s: %s\n", pfx, files[order[k]], order[k] }'
fi
}
compat_notes() { # $1: line prefix; build compatibility patches of the target
for p in "$patch_dir"/compat-*.patch; do
[ -f "$p" ] || continue
printf '%s- `%s`: %s (%s)\n' "$1" "${p##*/}" \
"$(sed -n 's/^Description: //p' "$p" | head -1)" "$(sed -n 's/^Origin: //p' "$p" | head -1)"
done
}
has_compat() { for p in "$patch_dir"/compat-*.patch; do [ -f "$p" ] && return 0; done; return 1; }
feature_notes() { # $1: line prefix; build options of this fork for the target
for p in "$patch_dir"/feature-*.patch; do
[ -f "$p" ] || continue
printf '%s- `%s`: %s\n' "$1" "$(sed -n 's/^Option: //p' "$p" | head -1)" \
"$(sed -n 's/^Description: //p' "$p" | head -1)"
done
}
has_features() { for p in "$patch_dir"/feature-*.patch; do [ -f "$p" ] && return 0; done; return 1; }
backports_notes() { # $1: line prefix
while IFS= read -r p; do
printf '%s- %s (%s)\n' "$1" \
"$(sed -n 's/^Description: //p' "$p" | head -1)" "$(sed -n 's/^Origin: //p' "$p" | head -1)"
done < "$bp_list"
}
# The fix of a PECL extension for its sources: freebsd/pecl/<name>-<version>-<target>.patch
# when the target alone needs one (a newer PHP), else freebsd/pecl/<name>-<version>.patch.
pecl_patch() { # name version
if [ -f "$pecl_patches/$1-$2-$target.patch" ]; then
echo "$pecl_patches/$1-$2-$target.patch"
else
echo "$pecl_patches/$1-$2.patch"
fi
}
# PECL extensions bundled into ext/<name> for the target (freebsd/pecl.conf).
pecl_entries() {
if [ -f "$pecl_conf" ]; then awk -v t="$target" '$1 == t { print $2, $3, $4, $5 }' "$pecl_conf"; fi
}
has_pecl() { [ -n "$(pecl_entries)" ]; }
pecl_option() { # configure option (markdown) of a bundled extension
case "$1" in
redis) echo '`--enable-redis`' ;;
memcached) echo '`--enable-memcached --with-libmemcached-dir=/usr/local --disable-memcached-sasl` (package `libmemcached`)' ;;
memcache) echo '`--enable-memcache`' ;;
imagick) echo '`--with-imagick=/usr/local` (package `ImageMagick7` or `ImageMagick7-nox11`; not together with gmagick)' ;;
igbinary) echo '`--enable-igbinary`; the igbinary serializer of redis and memcached: `--enable-redis-igbinary`, `--enable-memcached-igbinary`' ;;
swoole) echo '`--enable-swoole` (OpenSSL when PHP is built `--with-openssl`; brotli compression with the package `brotli`)' ;;
openswoole) echo '`--enable-openswoole` (OpenSSL when PHP is built `--with-openssl`; not together with swoole)' ;;
excimer) echo '`--enable-excimer`' ;;
gmagick) echo '`--with-gmagick=/usr/local` (package `GraphicsMagick`; not together with imagick)' ;;
mcrypt) echo '`--with-mcrypt=/usr/local` (package `libmcrypt`)' ;;
ssh2) echo '`--with-ssh2=/usr/local` (package `libssh2`)' ;;
gearman) echo '`--with-gearman=/usr/local` (package `gearmand` or `gearmand-openssl` of azsupport/ports)' ;;
*) echo "\`--enable-$1\`" ;;
esac
}
pecl_notes() { # $1: line prefix
pecl_entries | while read -r n v u c; do
pp="$(pecl_patch "$n" "$v")"
extra=""
if [ -f "$pp" ]; then extra="; patch \`${pp##*/}\`: $(sed -n 's/^Description: //p' "$pp" | head -1)"; fi
printf '%s- %s %s ([%s @ `%s`](%s/tree/%s)): %s%s\n' "$1" "$n" "$v" "${u#https://github.com/}" \
"$(short "$c")" "$u" "$c" "$(pecl_option "$n")" "$extra"
done
}
# Copy one PECL extension (name version url commit) into ext/<name> of the worktree.
pecl_fetch() {
if [ -e "ext/$1" ]; then echo "sync: $target: ext/$1 exists upstream" >&2; return 1; fi
pd="$(mktemp -d)"
git -C "$pd" init -q
if ! git -C "$pd" fetch -q --depth 1 "$3" "$4" || [ "$(git -C "$pd" rev-parse FETCH_HEAD)" != "$4" ]; then
echo "sync: $target: cannot fetch $1 $2 ($3 @ $4)" >&2
rm -rf "$pd"
return 1
fi
mkdir -p "ext/$1"
git -C "$pd" archive FETCH_HEAD | tar -x -C "ext/$1"
rm -rf "$pd"
(cd "ext/$1" && rm -rf .github .circleci .travis.yml .cirrus.yml .appveyor.yml appveyor.yml .gitmodules .gitignore)
pp="$(pecl_patch "$1" "$2")"
if [ -f "$pp" ] && ! (cd "ext/$1" && patch -p1 -N -s -f < "$pp"); then
echo "sync: $target: ${pp##*/} does not apply" >&2
return 1
fi
}
# curl for --with-curl=bundled (freebsd/curl.conf): "version url sha256" of the target.
curl_entry() {
if [ -f "$curl_conf" ]; then awk -v t="$target" '$1 == t { print $2, $3, $4 }' "$curl_conf"; fi
}
has_curl() { [ -n "$(curl_entry)" ]; }
curl_notes() { # $1: line prefix
curl_entry | while read -r v u s; do
cpatch="$curl_dir/curl-$v.patch"
extra=""
if [ -f "$cpatch" ]; then extra="; patch \`${cpatch##*/}\` (freebsd-ports): $(sed -n 's/^Description: //p' "$cpatch" | head -1)"; fi
libs="$(awk '!/^#/ && NF >= 7 && $1 != "psl-list" { printf "%s%s %s", (n++ ? ", " : ""), $1, $2 }' "$curl_deps_conf")"
psl="$(awk '!/^#/ && $1 == "psl-list" { print substr($2, 7, 2) "." substr($2, 5, 2) "." substr($2, 1, 4) }' "$curl_deps_conf")"
printf '%s- curl %s ([release tarball](%s), SHA-256 `%s`) in `ext/curl/libcurl`%s, and the libraries it needs in `ext/curl/deps`: %s, with the public suffix list of %s (their upstream release files, [`freebsd/curl-deps.conf`](https://github.com/%s/blob/HEAD/freebsd/curl-deps.conf)). `--with-curl=bundled` builds all of it into PHP, static, with the OpenSSL of the build (3.0 or later, so not FreeBSD 13.x base): no package needed. c-ares resolves names (a lookup that runs into the timeout ends at once); left out: IMAP, POP3, SMTP, WebSocket, NTLM, DICT, Gopher, IPFS, MQTT, RTSP, Telnet, TFTP, LDAP, GSSAPI; SCP and SFTP with libssh2. Plain `--with-curl` still takes the libcurl of the system.\n' \
"$1" "$v" "$u" "$(short "$s" 16)" "$extra" "$libs" "$psl" "$gh_repo"
done
}
# The curl release and the libraries it needs into ext/curl of the worktree
# (tools/curl-sources.sh), wired into ext/curl/config.m4 (the hook goes right
# after 'if test "$PHP_CURL" != "no"; then').
curl_bundle() {
if [ -e ext/curl/libcurl ] || [ -e ext/curl/deps ] || [ ! -f ext/curl/config.m4 ]; then
echo "sync: $target: ext/curl/libcurl or ext/curl/deps exists or ext/curl/config.m4 is missing" >&2
return 1
fi
if ! sh "$main_dir/tools/curl-sources.sh" "$target" ext/curl; then
echo "sync: $target: tools/curl-sources.sh failed" >&2
return 1
fi
cp "$curl_dir/build-libcurl.sh" ext/curl/build-libcurl.sh
if ! awk -v hook="$curl_dir/config-hook.m4" '
{ print }
!done && $0 == "if test \"$PHP_CURL\" != \"no\"; then" {
while ((getline l < hook) > 0) print l
done = 1
}
END { exit !done }' ext/curl/config.m4 > ext/curl/config.m4.new; then
echo "sync: $target: no place for the curl hook in ext/curl/config.m4" >&2
return 1
fi
# PHP 5.6 adds -L and a run path for the library dir of curl: not for the
# bundled one, whose -L the hook puts into LDFLAGS.
awk '
$0 == " PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, CURL_SHARED_LIBADD)" {
print " if test \"$PHP_CURL\" = \"$php_curl_bundled\"; then"
print " PHP_ADD_LIBRARY(curl,, CURL_SHARED_LIBADD)"
print " else"
print " " $0
print " fi"
next
}
{ sub(/Include cURL support/, "Include cURL support (=bundled: ext/curl/libcurl, built into PHP)"); print }
' ext/curl/config.m4.new > ext/curl/config.m4
rm -f ext/curl/config.m4.new
}
# PCRE instead of the copy upstream bundles (freebsd/pcre.conf): "version url
# sha256" of the target. 8.x is PCRE (5.6), 10.x PCRE2.
pcre_entry() {
if [ -f "$pcre_conf" ]; then awk -v t="$target" '$1 == t { print $2, $3, $4 }' "$pcre_conf"; fi
}
has_pcre() { [ -n "$(pcre_entry)" ]; }
# "PCRE 8.45 ext/pcre/pcrelib devel/pcre --with-pcre-regex=DIR import-pcre1.sh" for a version
pcre_kind() {
case "$1" in
8.*) echo "PCRE ext/pcre/pcrelib devel/pcre --with-pcre-regex=DIR import-pcre1.sh" ;;
*) echo "PCRE2 ext/pcre/pcre2lib devel/pcre2 --with-external-pcre import-pcre2.sh" ;;
esac
}
pcre_notes() { # $1: line prefix
pcre_entry | while read -r v u s; do
set -- "$1" $(pcre_kind "$v")
tp="$pcre_dir/tests-$target.patch"
extra=""
if [ -f "$tp" ]; then extra="; \`${tp##*/}\`: $(sed -n 's/^Description: //p' "$tp" | head -1 | sed 's/\.$//')"; fi
printf '%s- %s %s ([release tarball](%s), SHA-256 `%s`, the same as in freebsd-ports `%s`) in `%s` instead of the copy upstream bundles; every function of it is renamed to `php_pcre*` (`main/php_compat.h`), so a PCRE library that another module loads into the same process (the libpcre2 of Apache) stays separate%s. `%s` still takes the library of the system.\n' \
"$1" "$2" "$v" "$u" "$(short "$s" 16)" "$4" "$3" "$extra" "$5"
done
}
# Replace the bundled PCRE of the worktree with the release of freebsd/pcre.conf
# (freebsd/pcre/import-pcre2.sh, 5.6: import-pcre1.sh) and apply
# freebsd/pcre/tests-<target>.patch. Sets pcre_old (the version replaced).
pcre_bundle() {
set -- $(pcre_entry)
pv="$1" pu="$2" ps="$3"
set -- $(pcre_kind "$pv")
pdir="$2" pimp="$pcre_dir/$5"
tb="${TMPDIR:-/tmp}/sync-${pu##*/}"
if [ ! -f "$tb" ] || [ "$(sha256_of < "$tb")" != "$ps" ]; then
# the distfiles cache of FreeBSD has the same file (the same SHA-256);
# plain HTTP last (its HTTPS answered with a certificate of another
# name, 09.11.2026): the SHA-256 below checks the file
if ! curl -fsSL --retry 3 -o "$tb" "$pu" &&
! curl -fsSL --retry 3 -o "$tb" "https://distcache.freebsd.org/ports-distfiles/${pu##*/}" &&
! curl -fsSL --retry 3 -o "$tb" "http://distcache.freebsd.org/ports-distfiles/${pu##*/}"; then
echo "sync: $target: cannot download PCRE $pv ($pu)" >&2
return 1
fi
fi
if [ "$(sha256_of < "$tb")" != "$ps" ]; then
echo "sync: $target: PCRE $pv: SHA-256 mismatch ($pu)" >&2
return 1
fi
if [ -f "$pdir/pcre2.h" ]; then
pcre_old="PCRE2 $(sed -n 's/^#define PCRE2_MAJOR *\([0-9]*\).*/\1/p; s/^#define PCRE2_MINOR *\([0-9]*\).*/.\1/p' "$pdir/pcre2.h" | tr -d '\n')"
else
pcre_old="PCRE $(sed -n 's/^#define PCRE_MAJOR *\([0-9]*\).*/\1/p; s/^#define PCRE_MINOR *\([0-9]*\).*/.\1/p' "$pdir/pcre.h" 2>/dev/null | tr -d '\n')"
fi
pt="$(mktemp -d)"
tar -xf "$tb" -C "$pt"
psrc="$(find "$pt" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
if ! sh "$pimp" . "$psrc" >&2; then
echo "sync: $target: ${pimp##*/} failed for PCRE $pv" >&2
rm -rf "$pt"
return 1
fi
rm -rf "$pt"
# fixes the release lacks (freebsd/pcre/pcre-<version>.patch, -p1 from the top of
# the tree): one that no longer applies fails the build, so that it gets reviewed
lp="$pcre_dir/pcre-$pv.patch"
if [ -f "$lp" ] && ! patch -p1 -N -s -f < "$lp"; then
echo "sync: $target: ${lp##*/} does not apply" >&2
return 1
fi
tp="$pcre_dir/tests-$target.patch"
if [ -f "$tp" ] && ! patch -p1 -N -s -f < "$tp"; then
echo "sync: $target: ${tp##*/} does not apply" >&2
return 1
fi
}
# README header for a target; uses the variables set in build_target().
readme_header() {
upstream_info
cat <<EOF
<!-- freebsd-notes:start -->
> [!IMPORTANT]
> **This is \`azsupport/php-src\`, branch \`freebsd/$target\`: not an official PHP release.**
>
> $summary
>
> | | |
> |---|---|
> | Upstream | $up_link @ \`$(short "$up_commit")\` |
> | PHP version | $php_ver (\`phpversion()\` unchanged); \`php -v\` adds \`(fork: $fork_build)\` |
> | FreeBSD patches | from freebsd-ports \`lang/$port\` @ \`$portrev\`: applied and not applied, below |
> | Ready-to-build tarball | [freebsd-$target-latest](https://github.com/$gh_repo/releases/tag/freebsd-$target-latest): \`configure\` and parsers are pre-generated, no autoconf/bison/re2c needed |
> | Updated | $today_human (UTC), automatically by [tools/sync.sh](https://github.com/$gh_repo/blob/HEAD/tools/sync.sh) |
>
> **FreeBSD ports patches** from freebsd-ports [\`lang/$port\` @ \`$portrev\`]($(port_url)):
>
EOF
ports_notes "> "
if has_compat; then
printf '>\n> **Build compatibility patches by azsupport** (commit "Apply build compatibility patches"):\n>\n'
compat_notes "> "
fi
if has_pecl; then
printf '>\n> **Bundled PECL extensions** (commit "Bundle PECL extensions"), built only when enabled with their option:\n>\n'
pecl_notes "> "
fi
if has_curl; then
printf '>\n> **Bundled curl** (commit "Bundle curl"), used only with `--with-curl=bundled`:\n>\n'
curl_notes "> "
fi
if has_pcre; then
printf '>\n> **Bundled PCRE** (commit "Bundle PCRE"):\n>\n'
pcre_notes "> "
fi
if has_features; then
printf '>\n> **Build options of this fork** (commit "Add the build options of this fork"), off unless given to configure:\n>\n'
feature_notes "> "
fi
cat <<EOF
>
> The upstream \`.github/\` CI configuration is removed so that php-src CI does not
> run in this fork. Provided as is, without warranty, by [aZsupport.com](https://azsupport.com).
EOF
if [ -s "$bp_list" ]; then
cat <<EOF
> [!WARNING]
> **Interim security backports by azsupport** (commit "Backport security fixes"),
> carried only until the upstream branch has its own fix; not reviewed upstream:
>
EOF
backports_notes "> "
fi
cat <<EOF
The original PHP README follows.
<!-- freebsd-notes:end -->
EOF
}
# "git add -u" stages changed files only: add the files a -p1 patch creates (the
# tests of a backport), every path of its "+++ b/" lines that exists now.
add_patch_files() {
sed -n 's#^+++ b/\([^ ]*\).*#\1#p' "$1" | while IFS= read -r f; do
if [ -e "$f" ]; then git add -f -- "$f"; fi
done
}
# Apply patches and create the commits in worktree $wt (runs with set -e).
make_commits() {
cd "$wt"
for p in "$patch_dir"/patch-*; do
if ! patch -p0 -N -s -f < "$p"; then
echo "sync: $target: ${p##*/} does not apply" >&2
return 1
fi
done
# php-src's own CI configuration would run in this fork on every push; drop it.
git rm -r -q --ignore-unmatch .github
git add -u
{
echo "Apply curated FreeBSD ports patches"
echo
echo "From freebsd-ports lang/$port at $portrev:"
for p in "$patch_dir"/patch-*; do echo "- ${p##*/}"; done
echo
echo "Also removes the upstream .github/ directory so that php-src CI does"
echo "not run in this fork."
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
# Build compatibility patches (-p1, git format): always applied; one that no
# longer applies fails the build, so that it gets reviewed.
if has_compat; then
for p in "$patch_dir"/compat-*.patch; do
[ -f "$p" ] || continue
if ! patch -p1 -N -s -f < "$p"; then
echo "sync: $target: ${p##*/} does not apply" >&2
return 1
fi
add_patch_files "$p"
done
git add -u
{
echo "Apply build compatibility patches"
echo
for p in "$patch_dir"/compat-*.patch; do
[ -f "$p" ] || continue
echo "- ${p##*/}: $(sed -n 's/^Description: //p' "$p" | head -1)"
echo " Origin: $(sed -n 's/^Origin: //p' "$p" | head -1)"
done
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
fi
# Optional interim backports (-p1, git format), skipped once upstream has them.
# -f (not -t): -t guesses "reversed" patches and would fake the -R check.
: > "$bp_list"
for p in "$patch_dir"/backport-*.patch; do
[ -f "$p" ] || continue
if patch -p1 -R --dry-run -s -f < "$p" >/dev/null 2>&1; then
echo "sync: $target: ${p##*/} is already upstream, skipped" >&2
continue
fi
if ! patch -p1 -N -s -f < "$p"; then
echo "sync: $target: ${p##*/} does not apply" >&2
return 1
fi
add_patch_files "$p"
echo "$p" >> "$bp_list"
done
if [ -s "$bp_list" ]; then
git add -u
{
echo "Backport security fixes"
echo
echo "Interim backports carried until the upstream branch has its own fix:"
while IFS= read -r p; do
echo "- ${p##*/}: $(sed -n 's/^Description: //p' "$p" | head -1)"
echo " Origin: $(sed -n 's/^Origin: //p' "$p" | head -1)"
done < "$bp_list"
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
fi
# PECL extensions (freebsd/pecl.conf), copied into ext/<name> at the commit of
# their release tag: built only when enabled with their configure option.
pecl_entries > "$pecl_list"
if [ -s "$pecl_list" ]; then
while read -r n v u c; do pecl_fetch "$n" "$v" "$u" "$c" || return 1; done < "$pecl_list"
# -f: the .gitignore of php-src would drop files the extensions need (its
# unanchored "php" and "include" match swoole's thirdparty/php/ and include/).
while read -r n v u c; do git add -A -f "ext/$n"; done < "$pecl_list"
{
echo "Bundle PECL extensions"
echo
echo "Sources in ext/<name> at the commit of the release tag; built only when"
echo "enabled with their configure option:"
while read -r n v u c; do
echo "- $n $v: $u @ $c"
pp="$(pecl_patch "$n" "$v")"
if [ -f "$pp" ]; then
echo " Patch: ${pp##*/}: $(sed -n 's/^Description: //p' "$pp" | head -1)"
fi
done < "$pecl_list"
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
fi
# curl (freebsd/curl.conf) in ext/curl/libcurl, built into PHP only with
# --with-curl=bundled; -f for the same .gitignore reasons as above.
if has_curl; then
curl_bundle || return 1
git add -A -f ext/curl
curl_entry | while read -r v u s; do
echo "Bundle curl $v for --with-curl=bundled"
echo
echo "ext/curl/libcurl: the curl $v release tarball, $u"
echo "(SHA-256 $s)."
if [ -f "$curl_dir/curl-$v.patch" ]; then
echo "Patch curl-$v.patch: $(sed -n 's/^Description: //p' "$curl_dir/curl-$v.patch" | head -1)"
echo " Origin: $(sed -n 's/^Origin: //p' "$curl_dir/curl-$v.patch" | head -1)"
fi
echo
echo "ext/curl/deps: the libraries curl needs, their upstream release files"
echo "(freebsd/curl-deps.conf, with their SHA-256):"
awk '!/^#/ && NF >= 7 { printf " %s %s (%s): %s\n", $1, $2, $3, $7 }' "$curl_deps_conf"
echo "libpsl/src/suffixes_dafsa.h is made from psl-list (its built-in list, no"
echo "file looked for at run time), libpsl/fuzz is left out (tools/curl-sources.sh)."
echo
echo "ext/curl/build-libcurl.sh builds them and curl static and position"
echo "independent, with only cc and make, curl with the OpenSSL of the PHP build;"
echo "libcurl.a takes the libraries in with their symbols local. ext/curl/config.m4"
echo "runs it for --with-curl=bundled and links the result into PHP without"
echo "exporting its symbols. Plain --with-curl still uses the libcurl of the system."
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
done | git commit -q -F -
fi
# PCRE (freebsd/pcre.conf) in ext/pcre/pcre2lib (5.6: ext/pcre/pcrelib) instead
# of the copy upstream bundles; -f for the same .gitignore reasons as above.
if has_pcre; then
pcre_old=""
pcre_bundle || return 1
git add -A -f ext/pcre main/php_compat.h
pcre_entry | while read -r v u s; do
set -- $(pcre_kind "$v")
echo "Bundle PCRE: $1 $v instead of $pcre_old"
echo
echo "$2: the $1 $v release tarball, $u"
echo "(SHA-256 $s, the same as in freebsd-ports $3), imported with"
echo "freebsd/pcre/$5 of azsupport/php-src: the library sources as php-src"
echo "imports them, PHP's own config.h (plus the defaults of the release it"
echo "lacks) and the list of compilation units in ext/pcre/config0.m4."
echo "main/php_compat.h renames every function of the library to php_pcre*,"
echo "so a PCRE library that another module loads into the same process (the"
echo "libpcre2 of Apache, for mod_php) stays separate. $4 still"
echo "takes the library of the system."
if [ -f "$pcre_dir/pcre-$v.patch" ]; then
echo
echo "pcre-$v.patch: $(sed -n 's/^Description: //p' "$pcre_dir/pcre-$v.patch" | head -1)"
echo " Origin: $(sed -n 's/^Origin: //p' "$pcre_dir/pcre-$v.patch" | head -1)"
fi
if [ -f "$pcre_dir/tests-$target.patch" ]; then
echo
echo "tests-$target.patch: $(sed -n 's/^Description: //p' "$pcre_dir/tests-$target.patch" | head -1)"
echo " Origin: $(sed -n 's/^Origin: //p' "$pcre_dir/tests-$target.patch" | head -1)"
fi
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
done | git commit -q -F -
fi
# Build options of this fork (-p1, git format), each off unless its configure
# option is given; applied last, in name order. One that no longer applies
# fails the build, so that it gets reviewed.
if has_features; then
for p in "$patch_dir"/feature-*.patch; do
[ -f "$p" ] || continue
if ! patch -p1 -N -s -f < "$p"; then
echo "sync: $target: ${p##*/} does not apply" >&2
return 1
fi
add_patch_files "$p"
done
git add -u
{
echo "Add the build options of this fork"
echo
echo "Off unless their configure option is given:"
for p in "$patch_dir"/feature-*.patch; do
[ -f "$p" ] || continue
echo "- $(sed -n 's/^Option: //p' "$p" | head -1) (${p##*/}):"
echo " $(sed -n 's/^Description: //p' "$p" | head -1)"
done
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
fi
# Build id in the `php -v` banner only. PHP_VERSION is left at the upstream
# value, so phpversion(), version_compare() and "PHP x.y.z" parsers are not
# disturbed. configure regenerates main/php_version.h from configure.ac/.in, so
# the PHP_FORK_BUILD macro is emitted there (right after PHP_VERSION_ID). The
# banner format string then appends it by C string-literal concatenation, so no
# printf argument changes. (This step runs on the CI runner / a Linux clone with
# GNU sed, never on the FreeBSD servers.)
[ -f configure.ac ] && vfile=configure.ac || vfile=configure.in
sed -i "/^echo \"#define PHP_VERSION_ID /a echo '#define PHP_FORK_BUILD \"$fork_build\"' >> php_version.h.new" "$vfile"
[ "$(grep -c 'PHP_FORK_BUILD' "$vfile")" = 1 ] || { echo "sync: $target: could not add PHP_FORK_BUILD to $vfile" >&2; return 1; }
# The banner lives in main/main.c (8.2+, shared by every SAPI) or, before that,
# in sapi/cli/php_cli.c; 8.5 prints the build date with one %s ("(built: %s)").
# "$ver_banner" is empty if neither carries the string.
ver_banner=""
for f in main/main.c sapi/cli/php_cli.c; do
if grep -q '(built: %s %s)' "$f" 2>/dev/null; then
sed -i.orig 's/(built: %s %s)/(built: %s %s) (fork: " PHP_FORK_BUILD ")/' "$f"
rm -f "$f.orig"
ver_banner="$f"
break
elif grep -q '(built: %s)' "$f" 2>/dev/null; then
sed -i.orig 's/(built: %s)/(built: %s) (fork: " PHP_FORK_BUILD ")/' "$f"
rm -f "$f.orig"
ver_banner="$f"
break
fi
done
git add -u
{
if [ -n "$ver_banner" ]; then
echo "Show the build id in the php -v banner: $php_ver (fork: $fork_build)"
echo
echo "php -v prints e.g. 'PHP $php_ver (cli) (built: ...) (fork: $fork_build)'."
echo "PHP_VERSION stays $php_ver, so phpversion() and version checks are"
echo "unchanged; the id (build date and upstream commit) rides in the banner"
echo "via string-literal concatenation of the new PHP_FORK_BUILD macro"
echo "(emitted into main/php_version.h by $vfile) in $ver_banner."
else
echo "Emit the PHP_FORK_BUILD macro: $fork_build"
echo
echo "The banner string was not found, so php -v is left unchanged."
fi
if [ -n "${EXTRA_TRAILERS:-}" ]; then echo; printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
readme_header > README.md.new
cat README.md >> README.md.new
mv README.md.new README.md
git add README.md
{
echo "README: describe the freebsd/$target branch"
echo
echo "Upstream-Ref: $url $up_ref"
echo "Upstream-Commit: $up_commit"
echo "Patchset: $patchset"
echo "Fork-Build: $fork_build"
while IFS= read -r p; do echo "Backport: ${p##*/}"; done < "$bp_list"
if [ -n "${EXTRA_TRAILERS:-}" ]; then printf '%s\n' "$EXTRA_TRAILERS"; fi
} | git commit -q -F -
}
# The last line of the notes of a release: the copyright of aZsupport.com. GitHub draws
# the notes of a release as a comment, where a line break of the text is a break on the
# page: each paragraph of the notes is one line.
notes_footer() { printf '\n© [aZsupport.com](https://azsupport.com)\n'; }
# Release notes; $1 is the tarball file name. Needs php_ver, name, sha, new_tip.
release_notes() {
upstream_info
printf 'PHP %s for FreeBSD from branch [`%s`](https://github.com/%s/tree/%s), not an official PHP release.\n\n' \
"$php_ver" "$branch" "$gh_repo" "$branch"
printf '| | |\n|---|---|\n'
printf '| Upstream | %s @ [`%s`](%s/commit/%s) |\n' "$up_link" "$(short "$up_commit")" "$up_web" "$up_commit"
printf '| Branch commit | [`%s`](https://github.com/%s/commit/%s) |\n' "$(short "$new_tip")" "$gh_repo" "$new_tip"
if [ -n "${fork_build:-}" ]; then
printf '| `php -v` | `PHP %s (...) (fork: %s)` |\n' "$php_ver" "$fork_build"
fi
printf '| Tarball | `%s`, unpacks into `%s/` |\n' "$1" "$name"
printf '| SHA-256 | `%s` |\n\n' "$sha"
printf '### FreeBSD ports patches\n\nFrom freebsd-ports [`lang/%s` @ `%s`](%s).\n\n' "$port" "$portrev" "$(port_url)"
ports_notes ""
if has_compat; then
printf '\n### Build compatibility patches\n\nBy azsupport (commit "Apply build compatibility patches"):\n\n'
compat_notes ""
fi
if [ -s "$bp_list" ]; then
printf '\n### Interim security backports\n\nBy azsupport, carried only until the upstream branch has its own fix; not reviewed upstream:\n\n'
backports_notes ""
fi
if has_pecl; then
printf '\n### Bundled PECL extensions\n\nIn `ext/` (commit "Bundle PECL extensions"), built only when enabled with their option:\n\n'
pecl_notes ""
fi
if has_pcre; then
printf '\n### Bundled PCRE\n\nCommit "Bundle PCRE":\n\n'
pcre_notes ""
fi
if has_curl; then
printf '\n### Bundled curl\n\nIn `ext/curl/libcurl` (commit "Bundle curl"), used only with `--with-curl=bundled`:\n\n'
curl_notes ""
fi
if has_features; then
printf '\n### Build options of this fork\n\nCommit "Add the build options of this fork", off unless given to configure:\n\n'
feature_notes ""
fi
printf '\n### Build\n\nExtract, then in the new directory write the configure options of the installed PHP with [`tools/config-check.sh`](https://github.com/%s/blob/HEAD/tools/config-check.sh) (`sh config-check.sh /usr/local/phpXY`, or `sh config-check.sh --pkg` where PHP comes from packages), run `sh config.installed.sh` (extra options, such as those of the bundled PECL extensions, go after it), then `make` and `make install`. Copy-paste blocks per version are in the [README](https://github.com/%s#building-on-freebsd-from-a-release-tarball).\n' "$gh_repo" "$gh_repo"
notes_footer
}
# Notes of the moving release: a pointer to the dated release, which carries the
# full notes, so that the releases page does not show everything twice.
latest_notes() { # $1: tag of the dated release with the same tarball
printf 'Moving release: always the newest build of [`%s`](https://github.com/%s/tree/%s), now PHP %s.\n\n' \
"$branch" "$gh_repo" "$branch" "$php_ver"
printf '| | |\n|---|---|\n'
printf '| Tarball | `php-%s-fbsd-latest.tar.xz`, unpacks into `%s/` |\n' "$target" "$name"
printf '| SHA-256 | `%s` |\n' "$sha"
if [ -n "${fork_build:-}" ]; then
printf '| `php -v` | `PHP %s (...) (fork: %s)` |\n' "$php_ver" "$fork_build"
fi
printf '| Same tarball as | [`%s`](https://github.com/%s/releases/tag/%s): upstream commit and the FreeBSD ports patches, applied and not applied |\n' \
"$1" "$gh_repo" "$1"
notes_footer
}
# gh release create uploads into a draft and publishes it as the last step; when
# that step fails, the release stays a draft, whose downloads answer 404. Publish
# such drafts of this target that point at commit $1.
publish_drafts() {
gh api "repos/$gh_repo/releases?per_page=100" \
--jq ".[] | select(.draft and .target_commitish == \"$1\") | \"\(.id) \(.tag_name)\"" |
while read -r id t; do
case "$t" in "freebsd-$target-"*) ;; *) continue ;; esac
if gh api -X PATCH "repos/$gh_repo/releases/$id" -F draft=false -f make_latest=false >/dev/null; then
log "$target: published the draft release $t"
else
log "$target: warning: release $t is still a draft"
fi
done
}
publish_release() {
short8="$(short "$up_commit" 8)"
name="php-$php_ver-fbsd-$today-$short8"
tag="freebsd-$target-$today-$short8"
sh "$main_dir/tools/makedist.sh" "refs/heads/$branch" "$dist_dir" "$name"
sha="$(cut -c1-64 "$dist_dir/$name.tar.xz.sha256")"
# A second build of the same upstream commit on the same day (changed patch set
# or --force) replaces that day's dated release.
if gh api "repos/$gh_repo/releases/tags/$tag" >/dev/null 2>&1; then
log "$target: replacing release $tag"
gh release delete "$tag" --repo "$gh_repo" --yes --cleanup-tag
fi
gh release create "$tag" \
"$dist_dir/$name.tar.xz" "$dist_dir/$name.tar.xz.sha256" \
--repo "$gh_repo" --target "$new_tip" --latest=false \
--title "PHP $php_ver for FreeBSD ($target, $today_human)" --notes "$(release_notes "$name.tar.xz")"
latest="php-$target-fbsd-latest"
cp "$dist_dir/$name.tar.xz" "$dist_dir/$latest.tar.xz"
sed "s/ $name\\.tar\\.xz\$/ $latest.tar.xz/" "$dist_dir/$name.tar.xz.sha256" > "$dist_dir/$latest.tar.xz.sha256"
gh release delete "freebsd-$target-latest" --repo "$gh_repo" --yes --cleanup-tag >/dev/null 2>&1 || true
gh release create "freebsd-$target-latest" \
"$dist_dir/$latest.tar.xz" "$dist_dir/$latest.tar.xz.sha256" \
--repo "$gh_repo" --target "$new_tip" --latest=false \
--title "PHP $target for FreeBSD: latest ($php_ver, $today_human)" \
--notes "$(latest_notes "$tag")"
rm -f "$dist_dir/$latest.tar.xz" "$dist_dir/$latest.tar.xz.sha256"
publish_drafts "$new_tip"
log "$target: released $name"
}
# A run stopped between the push of a branch and its release (a cancelled job)
# leaves a tip that no release points at, and the up-to-date check alone would
# never release it. True only when GitHub answers for certain: the dated release
# of the tip (its tag from Fork-Build) is missing or points at another commit,
# and no draft points at the tip (refresh_notes publishes such a draft).
tip_unreleased() { # $1: commit message of the tip of $branch
fb="$(printf '%s\n' "$1" | sed -n 's/^Fork-Build: //p')"
[ -n "$fb" ] || return 1
tip="$(git ls-remote origin "refs/heads/$branch" | awk 'NR == 1 {print $1}')"
[ -n "$tip" ] || return 1
tip_tag="freebsd-$target-${fb%%-fbsd-*}-$(short "$up_commit" 8)"
if out="$(gh api "repos/$gh_repo/releases/tags/$tip_tag" --jq .target_commitish 2>&1)"; then
[ "$out" != "$tip" ] || return 1
else
case "$out" in *"(HTTP 404)"*) ;; *) return 1 ;; esac
fi
drafts="$(gh api "repos/$gh_repo/releases?per_page=100" \
--jq "[.[] | select(.draft and .target_commitish == \"$tip\")] | length")" || return 1
[ "$drafts" = 0 ]
}
build_target() {
target="$1" url="$2" ref="$3" port="$4" portrev="$5"
patch_dir="$main_dir/freebsd/patches/$target"
branch="freebsd/$target"
resolved="$(resolve_upstream "$url" "$ref")" || { log "$target: cannot resolve $ref"; return 1; }
up_commit="${resolved%% *}" up_ref="${resolved#* }"
[ -n "$up_commit" ] && [ "$up_commit" != "$resolved" ] || { log "$target: cannot resolve $ref"; return 1; }
patchset="$(patchset_of)"
# Up to date? Decided from ls-remote + API before any large fetch.
if [ "$force" = 0 ] && [ "$local_only" = 0 ] && msg="$(current_message "$branch" 2>/dev/null)"; then
if [ "$(printf '%s\n' "$msg" | sed -n 's/^Upstream-Commit: //p')" = "$up_commit" ] &&
[ "$(printf '%s\n' "$msg" | sed -n 's/^Patchset: //p')" = "$patchset" ]; then
if { [ "$release" = 1 ] || [ "$check_only" = 1 ]; } && tip_unreleased "$msg"; then
log "$target: $branch @ $(short "$tip") has no release $tip_tag: building it again"
else
log "$target: up to date ($up_ref @ $(short "$up_commit"))"
if [ "$release" = 1 ]; then
refresh_notes "$target" "$url" "$ref" "$port" "$portrev" ||
log "$target: warning: could not refresh the release notes"
fi
return 0
fi
fi
fi
if [ "$check_only" = 1 ]; then
log "$target: would rebuild ($up_ref @ $(short "$up_commit"))"
return 0
fi
git fetch -q --no-tags ${FETCH_DEPTH:+--depth="$FETCH_DEPTH"} "$url" "+$up_ref:refs/sync/upstream/$target"
[ "$(git rev-parse "refs/sync/upstream/$target^{commit}")" = "$up_commit" ] ||
{ log "$target: upstream moved during fetch, retry later"; return 1; }
php_ver="$(git show "$up_commit:main/php_version.h" | sed -n 's/^#define PHP_VERSION "\(.*\)"/\1/p')"
# php -v shows the build: build date and upstream commit, as in the tarball name.
# The suffix starts with a digit, so that version_compare() ranks the build above
# the plain upstream version (a leading letter would rank it below, like "-dev").
# No dots: configure splits the version at them.
fork_build="$today-fbsd-$(short "$up_commit" 8)"
log "$target: building $branch from $up_ref @ $(short "$up_commit") (PHP $php_ver)"
wt="$(mktemp -d)"
git worktree add -q --detach "$wt" "$up_commit"
set +e
(set -e; make_commits)
rc=$?
set -e
if [ "$rc" != 0 ]; then git worktree remove --force "$wt"; return 1; fi
new_tip="$(git -C "$wt" rev-parse HEAD)"
git worktree remove --force "$wt"
git update-ref "refs/heads/$branch" "$new_tip"
log "$target: $branch -> $(short "$new_tip")"
[ "$local_only" = 1 ] && return 0
# The old tip (one commit) shares most blobs with the new tree; having it locally
# keeps the push small even when the fork lacks the new upstream history.
git fetch -q --depth=1 origin "+refs/heads/$branch:refs/sync/current/$target" 2>/dev/null || true
git push -q -f origin "refs/heads/$branch:refs/heads/$branch"
log "$target: pushed $branch"
# Best effort: keep the mirror of Remi's branch under its original name. Official
# tags are not mirrored: pushing them would start php-src's tag-triggered CI here.
case "$up_ref" in
refs/heads/*)
if git push -q -f origin "refs/sync/upstream/$target:$up_ref"; then
log "$target: mirrored $up_ref"
else
log "$target: warning: could not mirror $up_ref (branch build is fine)"
fi ;;
esac
if [ "$release" = 1 ]; then publish_release; fi
}
# --notes: rewrite the notes of the releases built from the current branch tip.
refresh_notes() {
target="$1" url="$2" ref="$3" port="$4" portrev="$5"
patch_dir="$main_dir/freebsd/patches/$target"
branch="freebsd/$target"
new_tip="$(git ls-remote origin "refs/heads/$branch" | awk 'NR == 1 {print $1}')"
[ -n "$new_tip" ] || { log "$target: no branch $branch"; return 1; }
msg="$(gh api "repos/$gh_repo/git/commits/$new_tip" --jq .message)"
if [ "$(printf '%s\n' "$msg" | sed -n 's/^Patchset: //p')" != "$(patchset_of)" ]; then
# The next regular run rebuilds it, with fresh notes.
log "$target: $branch waits for a rebuild (patch set changed), notes left as they are"
return 0
fi
if [ "$check_only" = 0 ]; then publish_drafts "$new_tip"; fi
up_ref="$(printf '%s\n' "$msg" | sed -n 's/^Upstream-Ref: [^ ]* //p')"
up_commit="$(printf '%s\n' "$msg" | sed -n 's/^Upstream-Commit: //p')"
printf '%s\n' "$msg" | sed -n "s#^Backport: #$patch_dir/#p" > "$bp_list"
tags="$(gh api "repos/$gh_repo/releases?per_page=100" \
--jq ".[] | select(.target_commitish == \"$new_tip\") | .tag_name" | grep "^freebsd-$target-" || true)"
tag="$(printf '%s\n' "$tags" | grep -v -- '-latest$' | head -1)"
[ -n "$tag" ] || { log "$target: no release of $branch @ $(short "$new_tip")"; return 1; }
assets="$(gh api "repos/$gh_repo/releases/tags/$tag" --jq '.assets[] | "\(.id) \(.name)"')"
name="$(printf '%s\n' "$assets" | sed -n 's/^[0-9]* \(.*\)\.tar\.xz$/\1/p' | head -1)"
php_ver="${name#php-}"
php_ver="${php_ver%%-fbsd-*}"
fork_build="$(printf '%s\n' "$msg" | sed -n 's/^Fork-Build: //p')"
sha_id="$(printf '%s\n' "$assets" | awk -v f="$name.tar.xz.sha256" '$2 == f {print $1}')"
sha="$(gh api -H 'Accept: application/octet-stream' "repos/$gh_repo/releases/assets/$sha_id" | cut -c1-64)"
[ "${#sha}" = 64 ] || { log "$target: cannot read the SHA-256 of $tag"; return 1; }
notes="$(release_notes "$name.tar.xz")"
latest_tag="freebsd-$target-latest"
if [ "$check_only" = 1 ]; then
printf '%s\n\n----- %s:\n%s\n' "$notes" "$latest_tag" "$(latest_notes "$tag")"
log "$target: would update the notes of $tag and $latest_tag"
return 0
fi
# Edit only what differs, so that regular runs leave current notes alone.
if [ "$(gh api "repos/$gh_repo/releases/tags/$tag" --jq .body)" != "$notes" ]; then
gh release edit "$tag" --repo "$gh_repo" --notes "$notes" >/dev/null || return 1
log "$target: notes of $tag updated"
fi
if printf '%s\n' "$tags" | grep -qx -- "$latest_tag"; then
notes="$(latest_notes "$tag")"
if [ "$(gh api "repos/$gh_repo/releases/tags/$latest_tag" --jq .body)" != "$notes" ]; then
gh release edit "$latest_tag" --repo "$gh_repo" --notes "$notes" >/dev/null || return 1
log "$target: notes of $latest_tag updated"
fi
fi
}
failed=""
targets="$(grep -vE '^[[:space:]]*(#|$)' "$conf")"
IFS_SAVE="$IFS"
IFS='
'