| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Build Alpine Linux packages: baseline, OSH as /bin/sh, OSH as /bin/bash
|
| 4 | # See regtest/aports.md
|
| 5 | #
|
| 6 | # Usage:
|
| 7 | # regtest/aports-run.sh <function name>
|
| 8 | #
|
| 9 | # Common usage:
|
| 10 | #
|
| 11 | # export APORTS_EPOCH=2025-08-04-foo # optional override
|
| 12 | # $0 build-many-shards-overlayfs shard{0..16} # build all 17 shards in 2 configs
|
| 13 | #
|
| 14 | # Also useful:
|
| 15 | #
|
| 16 | # $0 fetch-packages fetch $pkg_filter $a_repo # alpine repo is 'main' or 'community'
|
| 17 | #
|
| 18 | # $0 fetch-packages fetch 100,300p # packages 100-300
|
| 19 | # $0 fetch-packages fetch '.*' # all packages
|
| 20 | #
|
| 21 | # Look for results in _tmp/aports-build/
|
| 22 | #
|
| 23 | # Build many packages:
|
| 24 | #
|
| 25 | # $0 build-packages-overlayfs osh-as-sh shard9 community
|
| 26 | # $0 build-packages-overlayfs osh-as-sh shardA # main is default $a_repo
|
| 27 | #
|
| 28 | # Build a single package:
|
| 29 | #
|
| 30 | # $0 build-package-overlayfs osh-as-sh userspace-rcu
|
| 31 | # $0 build-package-overlayfs osh-as-sh xterm community # community repo
|
| 32 | #
|
| 33 | # Drop into a shell:
|
| 34 | # INTERACTIVE=1 $0 build-package-overlayfs osh-as-sh userspace-rcu
|
| 35 | #
|
| 36 | # PKG_FILTER
|
| 37 | # shard[0-9]+ - shard3 is packages 301 to 400
|
| 38 | # [0-9]+ - 42 means build the first 42 packages
|
| 39 | # [0-9]+,[0-9]+p - 100,300p packages 100 to 300 (sed syntax)
|
| 40 | # ALL - all packages
|
| 41 | # .* - egrep pattern matching all packages
|
| 42 | # curl - egrep pattern matching 'curl'
|
| 43 | #
|
| 44 | # Preview packages:
|
| 45 | #
|
| 46 | # $0 package-dirs shard9 community
|
| 47 |
|
| 48 | : ${LIB_OSH=stdlib/osh}
|
| 49 | source $LIB_OSH/bash-strict.sh
|
| 50 | source $LIB_OSH/task-five.sh
|
| 51 |
|
| 52 | source regtest/aports-common.sh
|
| 53 |
|
| 54 | #
|
| 55 | # Config
|
| 56 | #
|
| 57 |
|
| 58 | show-config() {
|
| 59 | enter-rootfs sh -c '
|
| 60 | ls -l /bin/sh /bin/ash /bin/bash
|
| 61 | '
|
| 62 | }
|
| 63 |
|
| 64 | save-default-config() {
|
| 65 | enter-rootfs sh -c '
|
| 66 | set -x
|
| 67 | dest=/bin/bash.ORIG
|
| 68 | cp /bin/bash $dest
|
| 69 | '
|
| 70 | show-config
|
| 71 | }
|
| 72 |
|
| 73 |
|
| 74 | set-baseline() {
|
| 75 | # ensure we have the default config
|
| 76 | enter-rootfs sh -c '
|
| 77 | set -x
|
| 78 | ln -s -f /bin/busybox /bin/sh
|
| 79 | ln -s -f /bin/busybox /bin/ash
|
| 80 | cp /bin/bash.ORIG /bin/bash
|
| 81 | '
|
| 82 | show-config
|
| 83 | }
|
| 84 |
|
| 85 | set-osh-as-X() {
|
| 86 | local x=$1
|
| 87 |
|
| 88 | enter-rootfs sh -c '
|
| 89 | x=$1
|
| 90 | set -x
|
| 91 | if ! test -f /usr/local/bin/oils-for-unix; then
|
| 92 | echo "Build Oils first"
|
| 93 | exit
|
| 94 | fi
|
| 95 | ln -s -f /usr/local/bin/oils-for-unix /bin/$x
|
| 96 | ' dummy0 "$x"
|
| 97 | show-config
|
| 98 | }
|
| 99 |
|
| 100 | set-osh-as-sh() {
|
| 101 | set-osh-as-X sh
|
| 102 | }
|
| 103 |
|
| 104 | set-osh-as-ash() {
|
| 105 | set-osh-as-X ash
|
| 106 | }
|
| 107 |
|
| 108 | set-osh-as-bash() {
|
| 109 | set-osh-as-X bash
|
| 110 | }
|
| 111 |
|
| 112 | #
|
| 113 | # Run
|
| 114 | #
|
| 115 |
|
| 116 | package-dirs() {
|
| 117 | # lz gives 5 packages: some fail at baseline
|
| 118 | # lzip: a single fast package
|
| 119 | # mpfr4: OSH bug, and big log
|
| 120 | # yash: make sure it doesn't hang
|
| 121 | local package_filter=${1:-'lz|mpfr|yash'}
|
| 122 | local a_repo=${2:-main} # or 'community'
|
| 123 |
|
| 124 | local -a prefix
|
| 125 |
|
| 126 | if [[ $package_filter = 'ALL' ]]; then
|
| 127 | prefix=( cat )
|
| 128 |
|
| 129 | # 100 means 0 to 100
|
| 130 | elif [[ $package_filter =~ ^[0-9]+$ ]]; then
|
| 131 | prefix=( head -n $package_filter )
|
| 132 |
|
| 133 | # 100,300p means lines 100 to 300
|
| 134 | elif [[ $package_filter =~ ^[0-9]+,[0-9]+p$ ]]; then
|
| 135 | prefix=( sed -n $package_filter )
|
| 136 |
|
| 137 | elif [[ $package_filter =~ ^shard([0-9]+)$ ]]; then
|
| 138 | # shards of 100 packages
|
| 139 |
|
| 140 | local shard_num=${BASH_REMATCH[1]}
|
| 141 | #echo shard=$shard_num
|
| 142 |
|
| 143 | local range
|
| 144 | # shard 0 is 0-99
|
| 145 | # shard 9 is 900 to 999
|
| 146 | # shard 10 is 1000 to 1099
|
| 147 | case $shard_num in
|
| 148 | # sed doesn't like 000,099
|
| 149 | 0) range='1,100p' ;;
|
| 150 | *) range="${shard_num}01,$(( shard_num + 1))00p" ;;
|
| 151 | esac
|
| 152 |
|
| 153 | prefix=( sed -n "$range" )
|
| 154 |
|
| 155 | # shardA, shardB For testing the combined report
|
| 156 | elif [[ $package_filter =~ ^shard([A-Z]+)$ ]]; then
|
| 157 | local shard_name=${BASH_REMATCH[1]}
|
| 158 | case $a_repo in
|
| 159 | main)
|
| 160 | case $shard_name in
|
| 161 | A) package_filter='^gzip' ;; # failure
|
| 162 | B) package_filter='^xz' ;; # failure
|
| 163 | C) package_filter='^lz' ;; # 3 packages
|
| 164 | D) package_filter='^jq$' ;; # produces autotools test-suite.log
|
| 165 | E) package_filter='^py3-p' ;; # many packages in parallel
|
| 166 | F) package_filter='^py3-pathspec' ;; # very fast package
|
| 167 | P) package_filter='^xz$|^shorewall' ;; # patches
|
| 168 | *) package_filter='^perl-http-daemon' ;; # test out perl
|
| 169 | esac
|
| 170 | ;;
|
| 171 | community)
|
| 172 | case $shard_name in
|
| 173 | A) package_filter='^py3-zulip' ;; # one Python package
|
| 174 | B) package_filter='^xterm' ;; # one C package
|
| 175 | C) package_filter='^shfmt' ;; # one Go package
|
| 176 | D) package_filter='^shellspec' ;; # OSH disagreement because of 'var'
|
| 177 | *) package_filter='^shell' ;; # a bunch of packages
|
| 178 | esac
|
| 179 | ;;
|
| 180 | *)
|
| 181 | die "Invalid a_repo $a_repo"
|
| 182 | ;;
|
| 183 | esac
|
| 184 |
|
| 185 | prefix=( egrep "$package_filter" )
|
| 186 |
|
| 187 | elif [[ $package_filter =~ ^disagree-(.*)+$ ]]; then
|
| 188 | local filename=${BASH_REMATCH[1]}
|
| 189 | # A file of EXACT package names, not patterns
|
| 190 | # See copy-disagree
|
| 191 | local package_file="_tmp/$package_filter.txt"
|
| 192 | comm -1 -2 <(sort $package_file) <(sort _tmp/apk-${a_repo}-manifest.txt)
|
| 193 | return
|
| 194 |
|
| 195 | else
|
| 196 | prefix=( egrep "$package_filter" )
|
| 197 |
|
| 198 | fi
|
| 199 |
|
| 200 | "${prefix[@]}" _tmp/apk-${a_repo}-manifest.txt
|
| 201 | }
|
| 202 |
|
| 203 | copy-disagree() {
|
| 204 | ### Determine what to run
|
| 205 |
|
| 206 | local epoch=${1:-2025-09-18-bash}
|
| 207 | cp -v \
|
| 208 | _tmp/aports-report/$epoch/disagree-packages.txt \
|
| 209 | _tmp/disagree-$epoch.txt
|
| 210 | }
|
| 211 |
|
| 212 | do-packages() {
|
| 213 | ### Download sources - abuild puts it in /var/cahe/distfiles
|
| 214 | local action=${1:-fetch}
|
| 215 | local package_filter=${2:-}
|
| 216 | local a_repo=${3:-main}
|
| 217 | # flags to pass to the inner shell
|
| 218 | local sh_flags=${4:-'-e -u'} # -u to disable -e
|
| 219 |
|
| 220 | # 6 seconds for 10 packages
|
| 221 | # There are ~1600 packages
|
| 222 | # So if there are 20 shards, each shard could have 10?
|
| 223 |
|
| 224 | local -a package_dirs
|
| 225 | package_dirs=( $(package-dirs "$package_filter" "$a_repo") )
|
| 226 |
|
| 227 | echo "${dirs[@]}"
|
| 228 | #return
|
| 229 |
|
| 230 | time enter-rootfs-user sh $sh_flags -c '
|
| 231 |
|
| 232 | action=$1
|
| 233 | a_repo=$2
|
| 234 | shift 2
|
| 235 | for dir in "$@"; do
|
| 236 | time abuild -r -C aports/$a_repo/$dir "$action"
|
| 237 | done
|
| 238 | ' dummy0 "$action" "$a_repo" "${package_dirs[@]}"
|
| 239 | }
|
| 240 |
|
| 241 | fetch-packages() {
|
| 242 | local package_filter=${1:-}
|
| 243 | local a_repo=${2:-main}
|
| 244 |
|
| 245 | # -u means we don't pass -e (and it's non-empty)
|
| 246 | do-packages fetch "$package_filter" "$a_repo" '-u'
|
| 247 | }
|
| 248 |
|
| 249 | banner() {
|
| 250 | echo
|
| 251 | echo "=== $@"
|
| 252 | echo
|
| 253 | }
|
| 254 |
|
| 255 | build-package-overlayfs() {
|
| 256 | local config=${1:-baseline}
|
| 257 | local pkg=${2:-lua5.4}
|
| 258 | local a_repo=${3:-main}
|
| 259 |
|
| 260 | # baseline stack:
|
| 261 | # _chroot/aports-build
|
| 262 | # _chroot/package-upper/baseline/gzip # upper dir / layer dir
|
| 263 | #
|
| 264 | # osh-as-sh stack:
|
| 265 | # _chroot/aports-build
|
| 266 | # _chroot/osh-as-sh.overlay/layer # this has the symlink
|
| 267 | # _chroot/package-upper/osh-as-sh/gzip # upper dir / layer dir
|
| 268 |
|
| 269 | # allow concurrency
|
| 270 | local xargs_slot="${XARGS_SLOT:-99}"
|
| 271 | local ov_base_dir=_chroot/package-slot${xargs_slot}.overlay
|
| 272 |
|
| 273 | local merged=$ov_base_dir/merged
|
| 274 | local work=$ov_base_dir/work
|
| 275 |
|
| 276 | local layer_dir=_chroot/package-layers/$config/$pkg
|
| 277 | mkdir -p $merged $work $layer_dir
|
| 278 |
|
| 279 | local overlay_opts
|
| 280 | case $config in
|
| 281 | baseline)
|
| 282 | overlay_opts="lowerdir=$CHROOT_DIR,upperdir=$layer_dir,workdir=$work"
|
| 283 | ;;
|
| 284 | osh-as-sh)
|
| 285 | local osh_as_sh=_chroot/osh-as-sh.overlay/layer
|
| 286 | overlay_opts="lowerdir=$osh_as_sh:$CHROOT_DIR,upperdir=$layer_dir,workdir=$work"
|
| 287 | ;;
|
| 288 | *)
|
| 289 | die "Invalid config $config"
|
| 290 | ;;
|
| 291 | esac
|
| 292 |
|
| 293 | sudo mount \
|
| 294 | -t overlay \
|
| 295 | aports-package \
|
| 296 | -o "$overlay_opts" \
|
| 297 | $merged
|
| 298 |
|
| 299 | local -a prefix
|
| 300 | if test -n "$XARGS_SLOT"; then
|
| 301 | local x=$XARGS_SLOT
|
| 302 |
|
| 303 | # run slot 0 on cores 0 and 1
|
| 304 | # run slot 9 on cores 18 and 19
|
| 305 | local cores="$(( x*2 )),$(( x*2 + 1 ))"
|
| 306 |
|
| 307 | # oversubscribe
|
| 308 | # run slot 0 on cores 0 and 1
|
| 309 | # run slot 19 on cores 19 and 0
|
| 310 | #local cores="$(( x )),$(( (x + 1) % NUM_CORES ))"
|
| 311 | prefix=( taskset -c "$cores" )
|
| 312 | fi
|
| 313 |
|
| 314 | "${prefix[@]}" $merged/enter-chroot -u udu sh -c '
|
| 315 | cd oils
|
| 316 |
|
| 317 | # show the effect of the overlay
|
| 318 | #ls -l /bin/sh
|
| 319 |
|
| 320 | regtest/aports-guest.sh build-one-package "$@"
|
| 321 | ' dummy0 "$pkg" "$a_repo" "$xargs_slot"
|
| 322 |
|
| 323 | if test -n "$INTERACTIVE"; then
|
| 324 | echo "Starting interactive shell in overlayfs environment for package $a_repo/$pkg"
|
| 325 | echo "Rebuild: abuild -f -r -C ~/aports/$a_repo/$pkg"
|
| 326 | echo " Help: abuild -h"
|
| 327 | # If the last command in the child shell exited non-zero then ctrl-d/exit
|
| 328 | # will report that error code to the parent. If we don't ignore that error
|
| 329 | # we will exit early and leave the package overlay mounted.
|
| 330 | set +o errexit
|
| 331 | $merged/enter-chroot -u udu
|
| 332 | set -o errexit
|
| 333 | fi
|
| 334 |
|
| 335 | unmount-loop $merged
|
| 336 | }
|
| 337 |
|
| 338 | build-pkg() {
|
| 339 | ### trivial wrapper around build-package-overlayfs - change arg order for xargs
|
| 340 | local config=${1:-baseline}
|
| 341 | local a_repo=${2:-main}
|
| 342 | local pkg=${3:-lua5.4}
|
| 343 |
|
| 344 | build-package-overlayfs "$config" "$pkg" "$a_repo"
|
| 345 |
|
| 346 | # TODO:
|
| 347 | # - we should only do this after we've done BOTH configs, so it appears
|
| 348 | # atomically
|
| 349 | save-package-files $config $a_repo $pkg
|
| 350 |
|
| 351 | # TODO: blow away the layer dir, since we saved the "tombstone".
|
| 352 | # We're not doing this now because we're still reporting off DEPRECATED shard
|
| 353 | # files.
|
| 354 | }
|
| 355 |
|
| 356 | LOG_SIZE_THRESHOLD=$(( 500 * 1000 )) # 500 KB
|
| 357 | #LOG_SIZE_THRESHOLD=$(( 1 * 1000 ))
|
| 358 |
|
| 359 | abridge-one-log() {
|
| 360 | local src=$1
|
| 361 | local dest=$2
|
| 362 |
|
| 363 | local size
|
| 364 | size=$(stat --format '%s' $src)
|
| 365 | if test $size -lt $LOG_SIZE_THRESHOLD; then
|
| 366 | #cp --verbose $src $dest
|
| 367 | cp $src $dest
|
| 368 | else
|
| 369 | # Bug fix: abridging to 1000 lines isn't sufficient. We got some logs
|
| 370 | # that were hundreds of MB, with less than 1000 lines!
|
| 371 | { echo "*** This log is abridged to its last $LOG_SIZE_THRESHOLD bytes"
|
| 372 | echo
|
| 373 | tail --bytes $LOG_SIZE_THRESHOLD $src
|
| 374 | } > $dest
|
| 375 | fi
|
| 376 | }
|
| 377 |
|
| 378 | # save-package-files creates a tree we can rsync
|
| 379 | # For EACH PACKAGE, without shards
|
| 380 | #
|
| 381 | # TODO: Both baseline and osh-as-sh should appear atomically?
|
| 382 |
|
| 383 | # Source tree:
|
| 384 | #
|
| 385 | # _chroot/package-layers/
|
| 386 | # baseline/
|
| 387 | # jq/
|
| 388 | # home/udu/
|
| 389 | # oils/_tmp/aports-guest/
|
| 390 | # jq.log.txt
|
| 391 | # jq.task.tsv
|
| 392 | # packages/main/x86_64
|
| 393 | # jq-*.apk
|
| 394 | # aports/main/jq/
|
| 395 | # src/jq-1.8.0/test-suite.log
|
| 396 | #
|
| 397 | # _tmp/aports-build/
|
| 398 | # 2025-11-12/
|
| 399 | # shard0/ # TODO: remove shards
|
| 400 | # baseline/
|
| 401 | # NEW:
|
| 402 | # apk/
|
| 403 | # jq.apk.txt # md5sum
|
| 404 | # layer/
|
| 405 | # jq.tombstone.txt # find '%s %P\n'
|
| 406 | # task/
|
| 407 | # jq.task.tsv
|
| 408 | # EXISTING:
|
| 409 | # apk.txt
|
| 410 | # tasks.tsv
|
| 411 | # log/
|
| 412 | # jq.log.txt
|
| 413 | # test-suite/
|
| 414 | # jq/ TODO: support multiple logs
|
| 415 | # test-suite.log
|
| 416 |
|
| 417 | save-package-files() {
|
| 418 | ### Copy some files from _chroot/package-layers/ -> _tmp/aports-build
|
| 419 |
|
| 420 | local config=${1:-baseline}
|
| 421 | local a_repo=${2:-main}
|
| 422 | local pkg=${3:-jq}
|
| 423 |
|
| 424 | local layer_dir=_chroot/package-layers/$config/$pkg
|
| 425 | local dest_dir=$BASE_DIR/$APORTS_EPOCH/$config
|
| 426 |
|
| 427 | # 5 directories
|
| 428 | mkdir -p $dest_dir/{apk,layer,task,log,test-suite}
|
| 429 |
|
| 430 | cp \
|
| 431 | $layer_dir/home/udu/oils/_tmp/aports-guest/$pkg.task.tsv \
|
| 432 | $dest_dir/task
|
| 433 |
|
| 434 | abridge-one-log \
|
| 435 | $layer_dir/home/udu/oils/_tmp/aports-guest/$pkg.log.txt \
|
| 436 | $dest_dir/log/$pkg.log.txt
|
| 437 |
|
| 438 | # Abridge this log too
|
| 439 | { find $layer_dir/home/udu/aports/$a_repo/$pkg -name 'test-suite.log' 2> /dev/null || true; } |
|
| 440 | while read -r log_src; do
|
| 441 | local test_suite_dest_dir=$dest_dir/test-suite/$pkg
|
| 442 | mkdir -p $test_suite_dest_dir
|
| 443 | abridge-one-log \
|
| 444 | $log_src \
|
| 445 | $test_suite_dest_dir/test-suite.log.txt
|
| 446 | done
|
| 447 |
|
| 448 | md5sum $layer_dir/home/udu/packages/$a_repo/x86_64/*.apk \
|
| 449 | > $dest_dir/apk/$pkg.apk.txt 2> /dev/null || true # allow failure if nothing built
|
| 450 |
|
| 451 | # Truncate large listings - e.g. clang packages have over 120K files
|
| 452 | { find $layer_dir -printf '%s %P\n' 2> /dev/null || true; } |
|
| 453 | head -n 1000 > $dest_dir/layer/$pkg.tombstone.txt
|
| 454 |
|
| 455 | #tree $dest_dir
|
| 456 |
|
| 457 | # log.txt
|
| 458 | # log.txt
|
| 459 | }
|
| 460 |
|
| 461 | NUM_CORES=$(( $(nproc) ))
|
| 462 |
|
| 463 | # 2 cores per package build
|
| 464 | NUM_PAR=$(( NUM_CORES / 2 ))
|
| 465 |
|
| 466 | # over-subscribe - allow 20 processes to see 2 cores each
|
| 467 | # Note: this causes more timeouts. TODO: get rid of shards to get rid of
|
| 468 | # stragglers, and then raise the timeout to 20 minutes or more.
|
| 469 | # NUM_PAR=$(( NUM_CORES ))
|
| 470 |
|
| 471 | # TODO: we ran into the env.sh race condition in the enter-chroot script
|
| 472 | # generated by alpine-chroot-install
|
| 473 | build-many-packages-overlayfs() {
|
| 474 | local package_filter=${1:-}
|
| 475 | local config=${2:-baseline}
|
| 476 | local a_repo=${3:-main}
|
| 477 | local parallel=${4:-T}
|
| 478 |
|
| 479 | banner "Building packages (filter=$package_filter a_repo=$a_repo)"
|
| 480 |
|
| 481 | local -a flags
|
| 482 | if test -n "$parallel"; then
|
| 483 | log "(with $NUM_PAR jobs in parallel)"
|
| 484 | flags=( -P $NUM_PAR )
|
| 485 | else
|
| 486 | log '(serially)'
|
| 487 | fi
|
| 488 |
|
| 489 | package-dirs "$package_filter" $a_repo |
|
| 490 | xargs "${flags[@]}" -n 1 --process-slot-var=XARGS_SLOT -- \
|
| 491 | $0 build-pkg $config $a_repo
|
| 492 | }
|
| 493 |
|
| 494 |
|
| 495 | clean-host-and-guest() {
|
| 496 | # host dir _tmp/aports-build
|
| 497 | rm -r -f -v $BASE_DIR
|
| 498 | }
|
| 499 |
|
| 500 | clean-guest() {
|
| 501 | # clean guest chroot
|
| 502 | sudo rm -r -f -v $CHROOT_HOME_DIR/oils/_tmp
|
| 503 | }
|
| 504 |
|
| 505 | readonly -a CONFIGS=( baseline osh-as-sh )
|
| 506 |
|
| 507 | APORTS_EPOCH="${APORTS_EPOCH:-}"
|
| 508 | # default epoch
|
| 509 | if test -z "$APORTS_EPOCH"; then
|
| 510 | APORTS_EPOCH=$(date '+%Y-%m-%d')
|
| 511 | fi
|
| 512 |
|
| 513 | _build-many-configs-overlayfs() {
|
| 514 | local package_filter=${1:-}
|
| 515 | local epoch=${2:-$APORTS_EPOCH}
|
| 516 | local a_repo=${3:-main}
|
| 517 |
|
| 518 | if test -z "$package_filter"; then
|
| 519 | die "Package filter is required (e.g. shard3, ALL)"
|
| 520 | fi
|
| 521 |
|
| 522 | clean-guest
|
| 523 |
|
| 524 | # See note about /etc/sudoers.d at top of file
|
| 525 |
|
| 526 | local dest_dir="$BASE_DIR/$epoch/$package_filter" # e.g. shard10
|
| 527 |
|
| 528 | for config in "${CONFIGS[@]}"; do
|
| 529 | banner "$epoch: Using config $config"
|
| 530 |
|
| 531 | build-many-packages-overlayfs "$package_filter" "$config" "$a_repo"
|
| 532 | done
|
| 533 | }
|
| 534 |
|
| 535 | remove-shard-files() {
|
| 536 | local shard_dir=${1:-_chroot/shardC}
|
| 537 |
|
| 538 | # For all packages packages, for baseline and osh-as-sh, clean up the aports source dir
|
| 539 | # For linux, clang, etc. it becomes MANY GIGABYTES
|
| 540 | #
|
| 541 | # 2025-09-12: ignore errors from rm; I think there was a race condition -
|
| 542 | # processes could still be running and creating files
|
| 543 | #
|
| 544 | # rm: cannot remove '_chroot/shard6/baseline/llvm19/home/udu/aports/main/llvm19/src/llvm-project-19.1.7.src/build/lib': Directory not empty
|
| 545 | # real 1041m46.464s
|
| 546 |
|
| 547 | #log "Removing big files in shard $shard_dir"
|
| 548 | #sudo rm -r -f $shard_dir/*/*/home/udu/aports/ || true
|
| 549 |
|
| 550 | log "Removing all files in $shard_dir"
|
| 551 | sudo rm -r -f $shard_dir || true
|
| 552 | }
|
| 553 |
|
| 554 | build-many-shards-overlayfs() {
|
| 555 | sudo -k
|
| 556 |
|
| 557 | local a_repo=${A_REPO:-main} # env var like $APORTS_EPOCH
|
| 558 |
|
| 559 | # Clean up old runs
|
| 560 | sudo rm -r -f _chroot/package-layers _chroot/shard* _chroot/disagree*
|
| 561 |
|
| 562 | banner "$APORTS_EPOCH $a_repo: building shards: $*"
|
| 563 |
|
| 564 | time for shard_name in "$@"; do
|
| 565 | _build-many-configs-overlayfs "$shard_name" "$APORTS_EPOCH" "$a_repo"
|
| 566 |
|
| 567 | # Move layer files to _chroot/shard10/{baseline,osh}/...
|
| 568 | mv -v --no-target-directory _chroot/package-layers _chroot/$shard_name
|
| 569 |
|
| 570 | # Make it rsync-able in _tmp/aports-build ($BASE_DIR)
|
| 571 | make-shard-tree $shard_name $a_repo
|
| 572 |
|
| 573 | # Remove big files
|
| 574 | remove-shard-files _chroot/$shard_name
|
| 575 |
|
| 576 | # TODO: we should publish and clean up after every PACKAGE, rather than
|
| 577 | # each shard
|
| 578 | done
|
| 579 | }
|
| 580 |
|
| 581 | build-and-stat() {
|
| 582 | # Measure resource utilization
|
| 583 | local proc_dir="$BASE_DIR/$APORTS_EPOCH/proc-log"
|
| 584 | mkdir -v -p $proc_dir
|
| 585 | regtest/proc_log.py --out-dir $proc_dir --sleep-secs 5 &
|
| 586 | local proc_log_pid=$!
|
| 587 |
|
| 588 | sleep 0.05 # prevent overlapping sudo prompt
|
| 589 |
|
| 590 | build-many-shards-overlayfs "$@"
|
| 591 |
|
| 592 | kill -s TERM $proc_log_pid
|
| 593 | wc -l $proc_dir/*.txt
|
| 594 | }
|
| 595 |
|
| 596 | make-shard-tree() {
|
| 597 | ### Put outputs in rsync-able format, for a SINGLE shard
|
| 598 |
|
| 599 | # The dir structure is like this:
|
| 600 | #
|
| 601 | # _tmp/aports-build/
|
| 602 | # 2025-09-10-overlayfs/
|
| 603 | # shard0/
|
| 604 | # baseline/
|
| 605 | # apk.txt
|
| 606 | # tasks.tsv
|
| 607 | # log/
|
| 608 | # gzip.log.txt
|
| 609 | # xz.log.txt
|
| 610 | # test-suite/ # autotools dir
|
| 611 | # gzip/
|
| 612 | # test-suite.log.txt
|
| 613 | # osh-as-sh/
|
| 614 | # apk.txt
|
| 615 | # tasks.tsv
|
| 616 | # log/
|
| 617 | # gzip.log.txt
|
| 618 | # xz.log.txt
|
| 619 | # test-suite/
|
| 620 | # gzip/
|
| 621 | # test-suite.log.txt
|
| 622 | # shard1/
|
| 623 | # ...
|
| 624 | # shard16/
|
| 625 | # ...
|
| 626 |
|
| 627 | local shard_name=$1
|
| 628 | local a_repo=${2:-main}
|
| 629 | local epoch=${3:-$APORTS_EPOCH}
|
| 630 |
|
| 631 | local shard_dir=_chroot/$shard_name
|
| 632 |
|
| 633 | for config in baseline osh-as-sh; do
|
| 634 | local dest_dir=$BASE_DIR/$epoch/$shard_name/$config
|
| 635 | mkdir -p $dest_dir
|
| 636 | #ls -l $shard_dir/$config
|
| 637 |
|
| 638 | # Four outputs
|
| 639 | # 1) log.txt for each package
|
| 640 | # 2) Optional test-suite.txt for each package
|
| 641 | # 3) merged tasks.tsv
|
| 642 | # - comes from .task.tsv
|
| 643 | # 4) merged apk.txt
|
| 644 | #
|
| 645 | # So 3 and 4 should not be merged yet
|
| 646 | #
|
| 647 | # _tmp/aports-build/
|
| 648 | # 2025-11-12/
|
| 649 | # shardP/
|
| 650 | # baseline/
|
| 651 | # log/
|
| 652 | # test-suite/
|
| 653 | # apk.txt
|
| 654 | # tasks.tsv
|
| 655 | #
|
| 656 | # We want to
|
| 657 |
|
| 658 | time python3 devtools/tsv_concat.py \
|
| 659 | $shard_dir/$config/*/home/udu/oils/_tmp/aports-guest/*.task.tsv > $dest_dir/tasks.tsv
|
| 660 |
|
| 661 | # Allowed to fail if zero .apk are built
|
| 662 | time md5sum $shard_dir/$config/*/home/udu/packages/$a_repo/x86_64/*.apk \
|
| 663 | > $dest_dir/apk.txt 2> /dev/null || true
|
| 664 |
|
| 665 | abridge-logs $shard_dir/$config $dest_dir
|
| 666 |
|
| 667 | done
|
| 668 | }
|
| 669 |
|
| 670 | abridge-logs() {
|
| 671 | local config_src_dir=${1:-_chroot/shardD/osh-as-sh}
|
| 672 | local dest_dir=${2:-$BASE_DIR/shardD/osh-as-sh}
|
| 673 |
|
| 674 | local log_dest_dir=$dest_dir/log
|
| 675 | local test_suite_dest_dir=$dest_dir/test-suite
|
| 676 | mkdir -p $log_dest_dir $test_suite_dest_dir
|
| 677 |
|
| 678 | local threshold=$(( 500 * 1000 )) # 500 KB
|
| 679 |
|
| 680 | # this assumes the build process doesn't create *.log.txt
|
| 681 | # test-suite.log is the name used by the autotools test runner - we want to save those too
|
| 682 | # ignore permission errors with || true
|
| 683 | { find $config_src_dir -name '*.log.txt' -a -printf '%s\t%P\n' 2> /dev/null || true; } |
|
| 684 | while read -r size path; do
|
| 685 | local src=$config_src_dir/$path
|
| 686 | # Remove text until last slash (shortest match)
|
| 687 | # like $(basename $path) but in bash, for speed
|
| 688 | local filename=${path##*/}
|
| 689 | local dest=$log_dest_dir/$filename
|
| 690 |
|
| 691 | if test "$size" -lt "$threshold"; then
|
| 692 | cp -v $src $dest
|
| 693 | else
|
| 694 | # Bug fix: abriding to 1000 lines isn't sufficient. We got some logs
|
| 695 | # that were hundreds of MB, with less than 1000 lines!
|
| 696 | { echo "*** This log is abridged to its last 500 KB:"
|
| 697 | echo
|
| 698 | tail --bytes 500000 $src
|
| 699 | } > $dest
|
| 700 | fi
|
| 701 | done
|
| 702 |
|
| 703 | { find $config_src_dir -name 'test-suite.log' -a -printf '%P\n' 2> /dev/null || true; } |
|
| 704 | while read -r path; do
|
| 705 | local src=$config_src_dir/$path
|
| 706 |
|
| 707 | # Remove text after the first slash (shortest match)
|
| 708 | local package_name=${path%%/*}
|
| 709 | local dest=$test_suite_dest_dir/$package_name/test-suite.log.txt
|
| 710 |
|
| 711 | mkdir -p "$(dirname $dest)"
|
| 712 | cp -v --no-target-directory $src $dest
|
| 713 | done
|
| 714 |
|
| 715 | # 500K threshold: 76 MB
|
| 716 | du --si -s $log_dest_dir
|
| 717 | }
|
| 718 |
|
| 719 | demo-build() {
|
| 720 | local pkg=${1:-gzip} # in shardA, uses many cores
|
| 721 | local do_pin=${2:-}
|
| 722 |
|
| 723 | local -a prefix
|
| 724 | if test -n "$do_pin"; then
|
| 725 | echo "*** Pinning to CPU 0 ***"
|
| 726 | prefix=( taskset -c 0 )
|
| 727 | fi
|
| 728 |
|
| 729 | "${prefix[@]}" $CHROOT_DIR/enter-chroot -u udu sh -c '
|
| 730 | pkg=$1
|
| 731 |
|
| 732 | echo "nproc = $(nproc)"
|
| 733 |
|
| 734 | cd oils
|
| 735 | set -x
|
| 736 |
|
| 737 | # Note the user / real ratio! How many cores did we use?
|
| 738 | time regtest/aports-guest.sh build-one-package $pkg
|
| 739 | ' dummy0 $pkg
|
| 740 | }
|
| 741 |
|
| 742 | test-taskset() {
|
| 743 | local pkg=${1:-gzip} # in shardA, uses many cores
|
| 744 |
|
| 745 | demo-build $pkg ''
|
| 746 | demo-build $pkg T
|
| 747 | }
|
| 748 |
|
| 749 | test-proc-log() {
|
| 750 | local out_dir=_tmp/proc-log
|
| 751 | mkdir -p $out_dir
|
| 752 |
|
| 753 | regtest/proc_log.py --out-dir $out_dir &
|
| 754 | local pid=$!
|
| 755 | sleep 3.1 # should get 3 entries
|
| 756 | kill $pid
|
| 757 | wc -l $out_dir/*.txt
|
| 758 | }
|
| 759 |
|
| 760 | task-five "$@"
|