| OLD | NEW |
| (Empty) |
| 1 #!/bin/bash | |
| 2 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 # | |
| 6 # Packages up tests for that they can run outside of the build tree. | |
| 7 | |
| 8 # Load common constants. This should be the first executable line. | |
| 9 # The path to common.sh should be relative to your script's location. | |
| 10 COMMON_SH="$(dirname "$0")/../../scripts/common.sh" | |
| 11 . "$COMMON_SH" | |
| 12 | |
| 13 mkdir -p ${OUT_DIR} | |
| 14 TARGET=${OUT_DIR}/cryptohome_tests | |
| 15 | |
| 16 # package_tests target runfile | |
| 17 function package_tests() { | |
| 18 local package="$1" | |
| 19 local testfile="$2" | |
| 20 shift; shift | |
| 21 local libs="$@" | |
| 22 TMPDIR="${TMPDIR:-/tmp}" | |
| 23 local builddir="$(mktemp -d $TMPDIR/shpkgr.XXXXXX)" | |
| 24 eval "cleanup() { [[ -n \"$builddir\" ]] && rm -rf $builddir; }" | |
| 25 trap cleanup ERR | |
| 26 | |
| 27 cat <<-EOF > $package | |
| 28 #!/bin/sh | |
| 29 # Self extracting archive - reqs bash,test,rm,pwd,tar,gzip,tail,basename | |
| 30 # Generated from "$0" | |
| 31 # export PKG_LEAVE_RUNFILES=1 to keep the exploded archive. | |
| 32 PREV=\`pwd\` | |
| 33 test \$? -eq 0 || exit 1 | |
| 34 BASE=\`basename \$0\` | |
| 35 test \$? -eq 0 || exit 1 | |
| 36 export RUNFILES=\`mktemp -d \$PREV/\$BASE.runfiles_XXXXXX\` | |
| 37 test \$? -eq 0 || exit 1 | |
| 38 # delete the runfiles on exit using a trap | |
| 39 trap "test \$PKG_LEAVE_RUNFILES || rm -rf \$RUNFILES" EXIT | |
| 40 # extract starting at the last line (20) | |
| 41 tail -n +20 \$0 | gzip -dc | tar x -C \$RUNFILES | |
| 42 test \$? -eq 0 || exit 1 | |
| 43 # execute the package but keep the current directory | |
| 44 /bin/bash --noprofile --norc -c "cd \$RUNFILES;. $testfile" \$0 "\$@" | |
| 45 exit \$? | |
| 46 __PACKAGER_TARBALL_GZ__ | |
| 47 EOF | |
| 48 pushd $builddir &> /dev/null | |
| 49 local source="$OLDPWD/$(dirname $0)" | |
| 50 cp -r "$source/../../third_party/shunit2" shunit2 | |
| 51 cp -r "$source/lib" lib | |
| 52 cp -r "$source/bin" bin | |
| 53 cp -r "$source/tests" tests | |
| 54 cp -a "$source/$testfile" $testfile | |
| 55 tar --exclude=".svn" --exclude=".git" -czf - * >> $package | |
| 56 popd &> /dev/null | |
| 57 trap - ERR | |
| 58 cleanup | |
| 59 chmod +x $package | |
| 60 } | |
| 61 | |
| 62 package_tests "$TARGET" test.sh | |
| OLD | NEW |