kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

buildcoord-kitchen.sh (6830B)


      1 #!/bin/sh
      2 # Coarse Tier 1 kitchen-sink smoke for the build coordinator driver path.
      3 
      4 set -u
      5 
      6 script_dir=$(cd "$(dirname "$0")" && pwd)
      7 repo_root=$(cd "$script_dir/../../.." && pwd)
      8 KIT="${KIT:-$repo_root/build/kit}"
      9 
     10 if [ ! -x "$KIT" ]; then
     11     echo "buildcoord-kitchen: kit binary not found at $KIT" >&2
     12     exit 2
     13 fi
     14 
     15 work=$(mktemp -d "${TMPDIR:-/tmp}/kit-t1-buildcoord.XXXXXX")
     16 trap 'rm -rf "$work"' EXIT
     17 
     18 KIT_KIT_DIR="$repo_root/test/lib"
     19 . "$repo_root/test/lib/kit_sh_kit.sh"
     20 kit_report_init
     21 
     22 ws="$work/ws"
     23 store="$work/store"
     24 mkdir -p "$ws/recipes" "$ws/src" "$store"
     25 
     26 make_pkg() {
     27     pkg=$1
     28     shift
     29     mkdir -p "$ws/$pkg"
     30     {
     31         printf 'kit-build 1\n'
     32         while [ "$#" -gt 0 ]; do
     33             printf '[target %s]\nrecipe //recipes/%s\n' "$1" "$2"
     34             shift 2
     35         done
     36     } > "$ws/$pkg/BUILD.kit"
     37 }
     38 
     39 make_pkg app bundle app.sh
     40 make_pkg argv echo argv.sh
     41 make_pkg fail probe fail.sh
     42 make_pkg lib data lib.sh
     43 make_pkg test pass test_pass.sh
     44 
     45 cat > "$ws/src/a.txt" <<'EOF'
     46 alpha
     47 EOF
     48 cat > "$ws/src/b.txt" <<'EOF'
     49 beta
     50 EOF
     51 
     52 cat > "$ws/recipes/lib.sh" <<'EOF'
     53 #!/bin/sh
     54 set -eu
     55 mkdir -p "$KIT_BUILD_OUT"
     56 flavor=$("$KIT" build config-get flavor || true)
     57 printf 'lib:%s\n' "$flavor" > "$KIT_BUILD_OUT/lib.txt"
     58 EOF
     59 
     60 cat > "$ws/recipes/argv.sh" <<'EOF'
     61 #!/bin/sh
     62 set -eu
     63 mkdir -p "$KIT_BUILD_OUT"
     64 printf '%s\n' "$@" > "$KIT_BUILD_OUT/args.txt"
     65 EOF
     66 
     67 cat > "$ws/recipes/app.sh" <<'EOF'
     68 #!/bin/sh
     69 set -eu
     70 mkdir -p "$KIT_BUILD_OUT"
     71 mode=$("$KIT" build config-get mode || true)
     72 printf 'mode:%s\n' "$mode" > "$KIT_BUILD_OUT/mode.txt"
     73 printf '%s\n' "$KIT_BUILD_TARGET" > "$KIT_BUILD_OUT/target.txt"
     74 info=$("$KIT" build source --format id-path src/a.txt)
     75 printf '%s\n' "$info" > "$KIT_BUILD_OUT/source-info.txt"
     76 cat "${info#* }" > "$KIT_BUILD_OUT/a.txt"
     77 for p in $("$KIT" build glob 'src/*.txt'); do
     78     cat "$("$KIT" build source "$p")"
     79 done > "$KIT_BUILD_OUT/sources.txt"
     80 dep_dir=$("$KIT" build need --config flavor=dep //lib:data)
     81 cat "$dep_dir/lib.txt" > "$KIT_BUILD_OUT/lib.txt"
     82 tok=$("$KIT" build need-submit //argv:echo -- async one)
     83 async_dir=$("$KIT" build need-await "$tok")
     84 cat "$async_dir/args.txt" > "$KIT_BUILD_OUT/async.txt"
     85 EOF
     86 
     87 cat > "$ws/recipes/test_pass.sh" <<'EOF'
     88 #!/bin/sh
     89 set -eu
     90 mkdir -p "$KIT_BUILD_OUT"
     91 "$KIT" build source src/a.txt >/dev/null
     92 printf 'test-artifact\n' > "$KIT_BUILD_OUT/result.txt"
     93 printf 'test-stdout\n'
     94 printf 'test-stderr\n' >&2
     95 EOF
     96 
     97 cat > "$ws/recipes/fail.sh" <<'EOF'
     98 #!/bin/sh
     99 set -eu
    100 exit 9
    101 EOF
    102 
    103 chmod +x "$ws"/recipes/*.sh
    104 
    105 run_build() {
    106     name=$1
    107     shift
    108     "$KIT" build --store "$store" --root "$ws" --def BUILD.kit \
    109         --config "env.KIT=$KIT" "$@" \
    110         > "$work/$name.out" 2> "$work/$name.err"
    111 }
    112 
    113 run_test() {
    114     name=$1
    115     shift
    116     "$KIT" build test --store "$store" --root "$ws" --def BUILD.kit \
    117         --config "env.KIT=$KIT" "$@" \
    118         > "$work/$name.out" 2> "$work/$name.err"
    119 }
    120 
    121 build_ok() {
    122     name=$1
    123     shift
    124     if run_build "$name" "$@"; then
    125         ok "$name"
    126     else
    127         not_ok "$name" "$work/$name.err"
    128     fi
    129 }
    130 
    131 test_pass() {
    132     name=$1
    133     shift
    134     if run_test "$name" "$@" &&
    135        awk 'NR == 1 && $1 == "PASS" {ok = 1} END {exit ok ? 0 : 1}' \
    136            "$work/$name.out"; then
    137         ok "$name"
    138     else
    139         if [ -s "$work/$name.err" ]; then
    140             not_ok "$name" "$work/$name.err"
    141         else
    142             not_ok "$name" "$work/$name.out"
    143         fi
    144     fi
    145 }
    146 
    147 tree_path_from() {
    148     awk 'NF >= 2 {print $2; exit}' "$1"
    149 }
    150 
    151 test_tree_path_from() {
    152     awk 'NF >= 3 {print $3; exit}' "$1"
    153 }
    154 
    155 first_field_from() {
    156     awk 'NF >= 1 {print $1; exit}' "$1"
    157 }
    158 
    159 second_field_from() {
    160     awk 'NF >= 2 {print $2; exit}' "$1"
    161 }
    162 
    163 build_ok buildcoord-kitchen-cold --stats --config mode=debug //app:bundle
    164 contains buildcoord-kitchen-cold-runs "$work/buildcoord-kitchen-cold.err" \
    165     "recipes_run=3"
    166 cold_path=$(tree_path_from "$work/buildcoord-kitchen-cold.out")
    167 contains buildcoord-kitchen-source-a "$cold_path/a.txt" "alpha"
    168 contains buildcoord-kitchen-glob-a "$cold_path/sources.txt" "alpha"
    169 contains buildcoord-kitchen-glob-b "$cold_path/sources.txt" "beta"
    170 contains buildcoord-kitchen-config "$cold_path/mode.txt" "mode:debug"
    171 contains buildcoord-kitchen-target "$cold_path/target.txt" "//app:bundle"
    172 contains buildcoord-kitchen-need "$cold_path/lib.txt" "lib:dep"
    173 contains buildcoord-kitchen-submit-await "$cold_path/async.txt" "async"
    174 source_id=$(first_field_from "$cold_path/source-info.txt")
    175 source_path=$(second_field_from "$cold_path/source-info.txt")
    176 if [ ${#source_id} -eq 64 ] && [ -f "$source_path" ]; then
    177     ok buildcoord-kitchen-source-format
    178 else
    179     printf 'id=%s\npath=%s\n' "$source_id" "$source_path" \
    180         > "$work/buildcoord-kitchen-source-format.diag"
    181     not_ok buildcoord-kitchen-source-format \
    182         "$work/buildcoord-kitchen-source-format.diag"
    183 fi
    184 
    185 build_ok buildcoord-kitchen-cache --stats --config mode=debug //app:bundle
    186 contains buildcoord-kitchen-cache-hit "$work/buildcoord-kitchen-cache.err" \
    187     "deep_hits=1"
    188 contains buildcoord-kitchen-cache-no-run "$work/buildcoord-kitchen-cache.err" \
    189     "recipes_run=0"
    190 cache_path=$(tree_path_from "$work/buildcoord-kitchen-cache.out")
    191 if [ "$cache_path" = "$cold_path" ]; then
    192     ok buildcoord-kitchen-cache-reuses-tree
    193 else
    194     printf 'cold=%s\ncache=%s\n' "$cold_path" "$cache_path" \
    195         > "$work/buildcoord-kitchen-cache-reuses-tree.diag"
    196     not_ok buildcoord-kitchen-cache-reuses-tree \
    197         "$work/buildcoord-kitchen-cache-reuses-tree.diag"
    198 fi
    199 
    200 cat > "$ws/src/b.txt" <<'EOF'
    201 beta2
    202 EOF
    203 build_ok buildcoord-kitchen-input-change --stats --config mode=debug \
    204     //app:bundle
    205 changed_path=$(tree_path_from "$work/buildcoord-kitchen-input-change.out")
    206 contains buildcoord-kitchen-input-change-visible "$changed_path/sources.txt" \
    207     "beta2"
    208 
    209 test_pass buildcoord-kitchen-test-cold --stats //test:pass
    210 contains buildcoord-kitchen-test-run "$work/buildcoord-kitchen-test-cold.err" \
    211     "test_runs=1"
    212 test_path=$(test_tree_path_from "$work/buildcoord-kitchen-test-cold.out")
    213 contains buildcoord-kitchen-test-artifact "$test_path/result.txt" \
    214     "test-artifact"
    215 contains buildcoord-kitchen-test-stdout "$test_path/stdout" "test-stdout"
    216 contains buildcoord-kitchen-test-stderr "$test_path/stderr" "test-stderr"
    217 
    218 test_pass buildcoord-kitchen-test-cache --stats //test:pass
    219 contains buildcoord-kitchen-test-cache-hit \
    220     "$work/buildcoord-kitchen-test-cache.err" "test_cache_hits=1"
    221 contains buildcoord-kitchen-test-cache-no-run \
    222     "$work/buildcoord-kitchen-test-cache.err" "test_runs=0"
    223 
    224 run_fail buildcoord-kitchen-failing-recipe \
    225     "$KIT" build --store "$store" --root "$ws" --def BUILD.kit \
    226         --config "env.KIT=$KIT" //fail:probe
    227 contains buildcoord-kitchen-failing-recipe-diag \
    228     "$work/buildcoord-kitchen-failing-recipe.err" "build failed"
    229 
    230 kit_summary buildcoord-kitchen
    231 kit_exit