kit

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

standalone.sh (13825B)


      1 #!/bin/sh
      2 
      3 audit_standalone_fixture_dir=$SCRIPT_DIR/fixtures
      4 
      5 audit_standalone_require_dist() {
      6     if [ -z "$HARNESS_DIST" ]; then
      7         audit_case_blocked "standalone and relocation workflows require --dist"
      8         return 1
      9     fi
     10     return 0
     11 }
     12 
     13 audit_standalone_stage() {
     14     AUDIT_STANDALONE_RELOC="$CASE_DIR/work/Kit Release With Spaces"
     15     AUDIT_STANDALONE_SOURCE_DIR="$CASE_DIR/work/read only source"
     16     AUDIT_STANDALONE_SENTINELS=$CASE_DIR/work/sentinel-bin
     17     AUDIT_STANDALONE_PATH=$AUDIT_STANDALONE_RELOC/bin:$AUDIT_STANDALONE_SENTINELS:/usr/bin:/bin
     18     case "$(uname -s 2>/dev/null || printf unknown)" in
     19         MINGW*|MSYS*|CYGWIN*) AUDIT_STANDALONE_CC_ALIAS=$CASE_DIR/install/bin/cc.exe ;;
     20         *)                    AUDIT_STANDALONE_CC_ALIAS=$CASE_DIR/install/bin/cc ;;
     21     esac
     22 
     23     {
     24         printf 'cp -R %s %s\n' "$HARNESS_DIST" "$AUDIT_STANDALONE_RELOC"
     25         printf 'chmod -R u+w %s\n' "$AUDIT_STANDALONE_RELOC"
     26         printf 'mkdir -p %s %s\n' "$AUDIT_STANDALONE_SOURCE_DIR" "$AUDIT_STANDALONE_SENTINELS"
     27         printf 'cp %s %s\n' \
     28             "$audit_standalone_fixture_dir/native_sdk_malloc.c" \
     29             "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c"
     30     } > "$CASE_DIR/setup.command"
     31     if ! cp -R "$HARNESS_DIST" "$AUDIT_STANDALONE_RELOC" \
     32         > "$CASE_DIR/setup.stdout" 2> "$CASE_DIR/setup.stderr" ||
     33        ! chmod -R u+w "$AUDIT_STANDALONE_RELOC" \
     34         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr" ||
     35        ! mkdir -p "$AUDIT_STANDALONE_SOURCE_DIR" "$AUDIT_STANDALONE_SENTINELS" \
     36         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr" ||
     37        ! cp "$audit_standalone_fixture_dir/native_sdk_malloc.c" \
     38         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
     39         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr" ||
     40        ! cp "$audit_standalone_fixture_dir/sentinel-tool.sh" \
     41         "$AUDIT_STANDALONE_SENTINELS/audit-sentinel" \
     42         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr" ||
     43        ! chmod +x "$AUDIT_STANDALONE_SENTINELS/audit-sentinel" \
     44         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"; then
     45         audit_case_blocked "could not stage relocated distribution and standalone fixtures"
     46         return 1
     47     fi
     48 
     49     for audit_standalone_tool in \
     50         clang cc gcc c++ g++ as ld ar ranlib objcopy strip nm \
     51         xcrun pkg-config cmake make lipo otool dsymutil; do
     52         if ! ln -s audit-sentinel "$AUDIT_STANDALONE_SENTINELS/$audit_standalone_tool" \
     53             >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"; then
     54             audit_case_blocked "could not install host-tool sentinel $audit_standalone_tool"
     55             return 1
     56         fi
     57     done
     58     : > "$CASE_DIR/artifacts/sentinel.log"
     59     return 0
     60 }
     61 
     62 audit_standalone_discover_sysroot() {
     63     audit_case_step_exec discover-sysroot "$AUDIT_STANDALONE_RELOC/bin/kit" cc \
     64         --support-dir "$AUDIT_STANDALONE_RELOC/support" -print-sysroot
     65     audit_expect_exit 0
     66     audit_expect_stderr_empty
     67     audit_expect_stdout_nonempty
     68     AUDIT_STANDALONE_SYSROOT=
     69     IFS= read -r AUDIT_STANDALONE_SYSROOT < "$CASE_ACTIVE_DIR/stdout" || :
     70     if [ -z "$AUDIT_STANDALONE_SYSROOT" ] || [ ! -d "$AUDIT_STANDALONE_SYSROOT" ]; then
     71         audit_check_fail "native SDK reported by relocated Kit is unavailable: $AUDIT_STANDALONE_SYSROOT"
     72         return 1
     73     fi
     74     audit_check_pass "native SDK exists: $AUDIT_STANDALONE_SYSROOT"
     75     return 0
     76 }
     77 
     78 audit_standalone_path_space() {
     79     if ! audit_case_start standalone.path-space standalone kit,cc,install relocation-native native native native p0; then
     80         return
     81     fi
     82     audit_standalone_require_dist || return
     83     audit_standalone_stage || return
     84     audit_standalone_discover_sysroot || {
     85         audit_case_finish
     86         return
     87     }
     88 
     89     chmod 444 "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
     90         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"
     91     chmod 555 "$AUDIT_STANDALONE_SOURCE_DIR" \
     92         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"
     93 
     94     audit_case_step_exec direct "$AUDIT_STANDALONE_RELOC/bin/kit" cc \
     95         --support-dir "$AUDIT_STANDALONE_RELOC/support" \
     96         --sysroot "$AUDIT_STANDALONE_SYSROOT" \
     97         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
     98         -o "$CASE_DIR/artifacts/direct program"
     99     audit_expect_exit 0
    100     audit_expect_stderr_empty
    101     audit_expect_file_nonempty "$CASE_DIR/artifacts/direct program"
    102 
    103     if [ -f "$CASE_DIR/artifacts/direct program" ]; then
    104         audit_case_step_exec direct-run "$CASE_DIR/artifacts/direct program"
    105         audit_expect_exit 0
    106         audit_expect_stderr_empty
    107     fi
    108 
    109     audit_case_step_exec path-only /usr/bin/env \
    110         "PATH=$AUDIT_STANDALONE_PATH" kit cc \
    111         --support-dir "$AUDIT_STANDALONE_RELOC/support" \
    112         --sysroot "$AUDIT_STANDALONE_SYSROOT" \
    113         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    114         -o "$CASE_DIR/artifacts/path program"
    115     audit_expect_exit 0
    116     audit_expect_stderr_empty
    117     audit_expect_file_nonempty "$CASE_DIR/artifacts/path program"
    118 
    119     audit_case_step_exec install "$AUDIT_STANDALONE_RELOC/bin/kit" install \
    120         --all "$CASE_DIR/install/bin"
    121     audit_expect_exit 0
    122     audit_expect_stderr_empty
    123     audit_expect_file_exists "$AUDIT_STANDALONE_CC_ALIAS"
    124 
    125     audit_case_step_exec installed-alias /usr/bin/env \
    126         "PATH=$CASE_DIR/install/bin:$AUDIT_STANDALONE_SENTINELS:/usr/bin:/bin" cc \
    127         --support-dir "$AUDIT_STANDALONE_RELOC/support" \
    128         --sysroot "$AUDIT_STANDALONE_SYSROOT" \
    129         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    130         -o "$CASE_DIR/artifacts/installed program"
    131     audit_expect_exit 0
    132     audit_expect_stderr_empty
    133     audit_expect_file_nonempty "$CASE_DIR/artifacts/installed program"
    134 
    135     if [ -f "$CASE_DIR/artifacts/installed program" ]; then
    136         audit_case_step_exec installed-run "$CASE_DIR/artifacts/installed program"
    137         audit_expect_exit 0
    138         audit_expect_stderr_empty
    139     fi
    140     audit_expect_file_empty "$CASE_DIR/artifacts/sentinel.log"
    141     audit_case_finish
    142 }
    143 
    144 audit_standalone_support_discovery() {
    145     if ! audit_case_start standalone.support-discovery standalone cc relocation-default native native native p0; then
    146         return
    147     fi
    148     audit_standalone_require_dist || return
    149     audit_standalone_stage || return
    150 
    151     audit_case_step_exec discover-sysroot "$AUDIT_STANDALONE_RELOC/bin/kit" cc -print-sysroot
    152     audit_expect_exit 0
    153     audit_expect_stdout_nonempty
    154     AUDIT_STANDALONE_SYSROOT=
    155     IFS= read -r AUDIT_STANDALONE_SYSROOT < "$CASE_ACTIVE_DIR/stdout" || :
    156     if [ -z "$AUDIT_STANDALONE_SYSROOT" ] || [ ! -d "$AUDIT_STANDALONE_SYSROOT" ]; then
    157         audit_check_fail "native SDK reported by relocated Kit is unavailable: $AUDIT_STANDALONE_SYSROOT"
    158         audit_case_finish
    159         return
    160     fi
    161 
    162     audit_case_step_exec compile "$AUDIT_STANDALONE_RELOC/bin/kit" cc \
    163         --sysroot "$AUDIT_STANDALONE_SYSROOT" \
    164         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    165         -o "$CASE_DIR/artifacts/default-discovery"
    166     audit_expect_exit 0
    167     audit_expect_stderr_empty
    168     audit_expect_file_nonempty "$CASE_DIR/artifacts/default-discovery"
    169     if [ -f "$CASE_DIR/artifacts/default-discovery" ]; then
    170         audit_case_step_exec run "$CASE_DIR/artifacts/default-discovery"
    171         audit_expect_exit 0
    172         audit_expect_stderr_empty
    173     fi
    174 
    175     # An explicit bad root is authoritative even though the copied release has
    176     # a valid sibling support tree.
    177     audit_case_step_exec invalid-explicit-support \
    178         "$AUDIT_STANDALONE_RELOC/bin/kit" cc \
    179         --support-dir "$CASE_DIR/work/missing support" \
    180         -c "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    181         -o "$CASE_DIR/artifacts/invalid-explicit.o"
    182     audit_expect_exit 1
    183     audit_expect_stderr_nonempty
    184     if grep -F -q "support dir not found" "$CASE_ACTIVE_DIR/stderr"; then
    185         audit_check_pass "invalid explicit support root is diagnosed"
    186     else
    187         audit_check_fail "invalid explicit support root diagnostic is missing"
    188     fi
    189     if [ ! -e "$CASE_DIR/artifacts/invalid-explicit.o" ]; then
    190         audit_check_pass "invalid explicit support root produced no output"
    191     else
    192         audit_check_fail "invalid explicit support root produced output"
    193     fi
    194 
    195     # Put otherwise-valid support layouts in the invocation cwd, but run an
    196     # orphaned binary whose executable-relative candidates are both absent.
    197     # Canonical discovery must fail rather than revive the removed cwd/source-
    198     # checkout fallbacks.
    199     mkdir -p "$CASE_DIR/work/orphan/bin"
    200     cp "$AUDIT_STANDALONE_RELOC/bin/kit" "$CASE_DIR/work/orphan/bin/kit"
    201     ln -s "$AUDIT_STANDALONE_RELOC/support" "$CASE_DIR/work/support"
    202     ln -s "$AUDIT_STANDALONE_RELOC/support/rt" "$CASE_DIR/work/rt"
    203     audit_case_step_exec no-cwd-fallback "$CASE_DIR/work/orphan/bin/kit" cc \
    204         -c "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    205         -o "$CASE_DIR/artifacts/orphan.o"
    206     audit_expect_exit 1
    207     audit_expect_stderr_nonempty
    208     if grep -F -q "support dir not found" "$CASE_ACTIVE_DIR/stderr"; then
    209         audit_check_pass "orphaned binary ignores cwd support/source trees"
    210     else
    211         audit_check_fail "orphaned binary used cwd support/source fallback"
    212     fi
    213     if [ ! -e "$CASE_DIR/artifacts/orphan.o" ]; then
    214         audit_check_pass "orphaned binary produced no output"
    215     else
    216         audit_check_fail "orphaned binary unexpectedly produced output"
    217     fi
    218 
    219     audit_expect_file_empty "$CASE_DIR/artifacts/sentinel.log"
    220     audit_case_finish
    221 }
    222 
    223 audit_standalone_post_install_move() {
    224     if ! audit_case_start standalone.post-install-move standalone install,cc post-install-relocation native native native p1; then
    225         return
    226     fi
    227     audit_standalone_require_dist || return
    228     audit_standalone_stage || return
    229 
    230     audit_case_step_exec install "$AUDIT_STANDALONE_RELOC/bin/kit" install \
    231         --all "$CASE_DIR/install/bin"
    232     audit_expect_exit 0
    233     audit_expect_stderr_empty
    234     audit_expect_file_exists "$AUDIT_STANDALONE_CC_ALIAS"
    235 
    236     AUDIT_STANDALONE_MOVED="$CASE_DIR/work/Moved Kit Distribution"
    237     printf 'mv %s %s\n' "$AUDIT_STANDALONE_RELOC" "$AUDIT_STANDALONE_MOVED" \
    238         >> "$CASE_DIR/setup.command"
    239     if ! mv "$AUDIT_STANDALONE_RELOC" "$AUDIT_STANDALONE_MOVED" \
    240         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"; then
    241         audit_case_blocked "could not move isolated distribution after install"
    242         return
    243     fi
    244 
    245     # Invoke the managed path itself here.  A dangling POSIX symlink is skipped
    246     # during PATH lookup, which could accidentally run an unrelated host `cc`
    247     # and obscure the relocation result this case is meant to measure.
    248     audit_case_step_exec installed-before-repair "$AUDIT_STANDALONE_CC_ALIAS" --help
    249     case "$(uname -s 2>/dev/null || printf unknown)" in
    250         MINGW*|MSYS*|CYGWIN*)
    251             # Windows installs hard links. The executable entry survives the
    252             # move; --force still refreshes the managed set below and is the
    253             # documented repair operation.
    254             audit_expect_exit 0
    255             audit_expect_stdout_regex '^kit cc'
    256             audit_expect_stderr_empty
    257             ;;
    258         *)
    259             # POSIX installs absolute symlinks, which dangle until repaired.
    260             audit_expect_exit_one_of 126,127
    261             audit_expect_stderr_nonempty
    262             ;;
    263     esac
    264     audit_expect_file_empty "$CASE_DIR/artifacts/sentinel.log"
    265 
    266     audit_case_step_exec repair "$AUDIT_STANDALONE_MOVED/bin/kit" install \
    267         --all --force "$CASE_DIR/install/bin"
    268     audit_expect_exit 0
    269     audit_expect_stderr_empty
    270 
    271     audit_case_step_exec installed-after-repair /usr/bin/env \
    272         "PATH=$CASE_DIR/install/bin:$AUDIT_STANDALONE_SENTINELS:/usr/bin:/bin" cc --help
    273     audit_expect_exit 0
    274     audit_expect_stdout_regex '^kit cc'
    275     audit_expect_stderr_empty
    276     audit_expect_file_empty "$CASE_DIR/artifacts/sentinel.log"
    277 
    278     # The repaired alias must rediscover both the moved support tree and the
    279     # native SDK.  Keep the distribution read-only so this also catches a
    280     # regression that tries to publish runtime/cache artifacts beside `kit`.
    281     chmod -R a-w "$AUDIT_STANDALONE_MOVED" \
    282         >> "$CASE_DIR/setup.stdout" 2>> "$CASE_DIR/setup.stderr"
    283     audit_case_step_exec installed-compile-after-repair /usr/bin/env \
    284         "PATH=$CASE_DIR/install/bin:$AUDIT_STANDALONE_SENTINELS:/usr/bin:/bin" \
    285         cc "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    286         -o "$CASE_DIR/artifacts/repaired installed program"
    287     audit_expect_exit 0
    288     audit_expect_stderr_empty
    289     audit_expect_file_nonempty "$CASE_DIR/artifacts/repaired installed program"
    290     if [ -f "$CASE_DIR/artifacts/repaired installed program" ]; then
    291         audit_case_step_exec installed-run-after-repair \
    292             "$CASE_DIR/artifacts/repaired installed program"
    293         audit_expect_exit 0
    294         audit_expect_stderr_empty
    295     fi
    296     audit_expect_file_empty "$CASE_DIR/artifacts/sentinel.log"
    297 
    298     audit_case_step_exec direct-after-move "$AUDIT_STANDALONE_MOVED/bin/kit" cc \
    299         "$AUDIT_STANDALONE_SOURCE_DIR/native sdk malloc.c" \
    300         -o "$CASE_DIR/artifacts/direct moved program"
    301     audit_expect_exit 0
    302     audit_expect_stderr_empty
    303     audit_expect_file_nonempty "$CASE_DIR/artifacts/direct moved program"
    304     if [ -f "$CASE_DIR/artifacts/direct moved program" ]; then
    305         audit_case_step_exec direct-run-after-move \
    306             "$CASE_DIR/artifacts/direct moved program"
    307         audit_expect_exit 0
    308         audit_expect_stderr_empty
    309     fi
    310     audit_case_finish
    311 }
    312 
    313 audit_module_standalone() {
    314     audit_standalone_path_space
    315     audit_standalone_support_discovery
    316     audit_standalone_post_install_move
    317 }