phase1b_stdlib_sweep.sh raw

   1  #!/bin/bash
   2  # Phase 1b: stdlib compile sweep.
   3  #
   4  # No other phase compiles a stdlib package: phase 1 builds only the five
   5  # compiler-support packages (token mxutil syntax types rewrite) and the other
   6  # phases build fixtures and the compiler itself. That gap hid real breakage -
   7  # src/internal/coverage/{encodecounter,encodemeta}, src/text/tabwriter and
   8  # src/net/http did not compile at all while the suite was green, because the
   9  # only check anyone ran was `moxie build -a ./_mxc_stage4` returning 0, which
  10  # says nothing about any other package.
  11  #
  12  # One build, not one per package: a blank import pulls a package into the
  13  # compile closure, so a single main importing all of them compiles every one of
  14  # them in one pass. Building the packages separately costs a full closure each
  15  # (net/http alone is ~20 minutes) and bought nothing - the compiler names the
  16  # package in the error either way.
  17  #
  18  # A package that is known broken today is listed in SWEEP_KNOWN and SKIPs with
  19  # its reason, so the set of broken packages stays visible and shrinking it is a
  20  # deliberate act: move the name to SWEEP when it is fixed.
  21  set -uo pipefail
  22  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  23  ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  24  source "$SCRIPT_DIR/util.sh"
  25  source "$SCRIPT_DIR/split-util.sh"
  26  
  27  # Packages that must compile. net/http carries the crypto/tls closure, which is
  28  # what reaches crypto/ecdsa and its fips140 generics.
  29  #
  30  # Every entry here must RESOLVE. It did not always: encoding/json, encoding/xml,
  31  # regexp and text/template were on this list while no such package existed in
  32  # the tree, and the sweep reported "41 packages ok" because the compiler skipped
  33  # an import it could not resolve instead of failing (round 103). encoding/json
  34  # and encoding/xml went with the reflect/any exodus (3b6e25e8, 4da18fb0);
  35  # regexp and text/template are not reflect-free either, and every in-tree
  36  # importer of them was dead code, removed in the same round. With the loader
  37  # strict, an entry naming a package that does not exist fails the build - so
  38  # this list is now self-verifying and a missing package can never pass again.
  39  SWEEP=(
  40  	compress/flate
  41  	compress/gzip
  42  	compress/zlib
  43  	context
  44  	crypto/aes
  45  	crypto/cipher
  46  	crypto/ecdh
  47  	crypto/ecdsa
  48  	crypto/ed25519
  49  	crypto/elliptic
  50  	crypto/hmac
  51  	crypto/rsa
  52  	crypto/sha256
  53  	crypto/x509
  54  	debug/gosym
  55  	encoding/base64
  56  	encoding/binary
  57  	encoding/hex
  58  	hash/crc32
  59  	hash/fnv
  60  	index/suffixarray
  61  	internal/coverage/cfile
  62  	internal/coverage/cformat
  63  	internal/coverage/encodecounter
  64  	internal/coverage/encodemeta
  65  	internal/profile
  66  	internal/trace
  67  	internal/trace/internal/tracev1
  68  	iter
  69  	maps
  70  	slices
  71  	math
  72  	math/big
  73  	mime
  74  	mime/multipart
  75  	net
  76  	net/http
  77  	net/textproto
  78  	net/url
  79  	os/exec
  80  	os/user
  81  	runtime/trace
  82  	text/tabwriter
  83  	time
  84  	unicode/utf8
  85  )
  86  
  87  # Packages known not to compile, with the reason. SKIP, never FAIL: the suite
  88  # must not encode today's breakage as acceptable, but it must not go red for a
  89  # defect that is already recorded either. Empty is the goal - every entry here
  90  # is a package that should be fixed and then moved back into SWEEP.
  91  SWEEP_KNOWN=(
  92  )
  93  
  94  # One unit, and it stays one unit - see the note above `unit_args` below for why
  95  # the sweep is not split per package. Without an entry here the driver sees a
  96  # phase with no units and reports success without running anything, which is
  97  # exactly the failure this line exists to prevent.
  98  UNITS=(stdlib_sweep)
  99  
 100  td="$(tempdir stdlib_sweep)"
 101  rm -rf "$td"; mkdir -p "$td/pkg"
 102  {
 103  	echo "package main"
 104  	echo ""
 105  	echo "import ("
 106  	for pkg in "${SWEEP[@]}"; do
 107  		echo "	_ \"$pkg\""
 108  	done
 109  	echo ")"
 110  	echo ""
 111  	echo "func main() {"
 112  	echo "	// A sweep binary is a batch program: stoppable at entry, then it runs"
 113  	echo "	// its imports' initialisers to completion."
 114  	echo "	select {"
 115  	echo "	case <-shutdown:"
 116  	echo "		return"
 117  	echo "	default:"
 118  	echo "	}"
 119  	echo "}"
 120  } >"$td/pkg/main.mx"
 121  
 122  # One unit, and it stays one unit. The sweep is one build so that the 45
 123  # packages share the closure they have in common (net/http, crypto/tls, math/big
 124  # are most of the cost of every package that touches them); splitting it into 45
 125  # builds would compile that closure 45 times instead of once. What the unit
 126  # layer buys here is what it buys every phase: its own log, its own timeout, and
 127  # a result that survives the rest of the run.
 128  unit_args "$@"
 129  
 130  echo ""
 131  echo "=== Phase 1b: Stdlib compile sweep (${#SWEEP[@]} packages) ==="
 132  
 133  log="$td/build.log"
 134  rc=0
 135  MOXIEROOT="$ROOT" "$MOXIE" build -o "$td/sweep" "$td/pkg" >"$log" 2>&1 || rc=$?
 136  if [ $rc -eq 0 ]; then
 137  	# It compiled AND linked: run it, so a bad entry point cannot pass unrun.
 138  	if "$td/sweep" >"$td/run.log" 2>&1; then
 139  		unit_ok "stdlib:sweep" "${#SWEEP[@]} packages ok"
 140  	else
 141  		unit_no "stdlib:sweep" "built but failed to run: $(tail -2 "$td/run.log")"
 142  	fi
 143  else
 144  	# Name the package the compiler blamed, not the whole set.
 145  	first="$(grep -E '^mxc:|error:' "$log" | head -1 || true)"
 146  	if [ -z "$first" ]; then
 147  		first="$(tail -3 "$log" | head -1)"
 148  	fi
 149  	unit_no "stdlib:sweep" "$first"
 150  	echo "    (full log: $log)"
 151  	cp "$log" "$TMPROOT/stdlib_sweep.log" 2>/dev/null || true
 152  fi
 153  
 154  if [ "${#SWEEP_KNOWN[@]}" -gt 0 ]; then
 155  	for entry in "${SWEEP_KNOWN[@]}"; do
 156  		pkg="${entry%%|*}"
 157  		reason="${entry#*|}"
 158  		log_skip "stdlib:$pkg" "$reason"
 159  	done
 160  fi
 161  exit $?
 162