| #!/bin/bash |
| |
| # Copyright (C) 2015 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| set -xue |
| BDK_USER_DATA=$PWD/../user_data |
| BDK=$PWD/bdk |
| DATA_DIR=$PWD/tests/data |
| TEST_TMP_DATA=$PWD/tests/tmp_user_data |
| HOST_TOOL_PATH=out/out-board/host/linux-$(uname -m | cut -f1 -d_)/bin |
| TOOL_PATH=out/out-board/target/product/board |
| |
| |
| # Changes to a temporary path that cleans itself up. |
| # Adds a config file opting out of . |
| setup_working_path() { |
| local tmp=`mktemp -d` |
| trap "rm -rf $tmp" exit |
| cd $tmp |
| |
| # Set config values, setting aside old values. |
| # Note: this DB uses relative paths to PWD. In a real user's config, |
| # all paths will be absolute. |
| mv ${BDK_USER_DATA}/config.db ${BDK_USER_DATA}/config_old.db |
| cp ${DATA_DIR}/config.db ${BDK_USER_DATA}/config.db |
| |
| # Update our trap. |
| trap "rm -rf $tmp && \ |
| mv ${BDK_USER_DATA}/config_old.db ${BDK_USER_DATA}/config.db" exit |
| |
| # Set some values. Note: these should be kept in sync with the DB. |
| TEST_TREE=${tmp}/OS |
| TEST_BSPs=${tmp}/BSPs |
| TEST_PLATFORM_CACHE=${tmp}/platform_cache |
| |
| # Initialize the test_tree. |
| cp -r ${DATA_DIR}/test_tree ${TEST_TREE} |
| } |
| |
| # Places make in stubs/ and updates PATH. |
| # Call this from within the product directory. |
| stub_make() { |
| echo "Replacing make with a stub" |
| mkdir -p stubs |
| cat <<-EOF >stubs/make |
| #!/bin/sh |
| echo "\$0" |
| while test -n "\$*"; do |
| echo "\$1" |
| shift |
| done |
| EOF |
| chmod +x stubs/make |
| export PATH=${PWD}/stubs:${PATH} |
| } |
| |
| |
| # Places git in stubs/ and updates PATH. |
| stub_git() { |
| echo "Replacing git with a stub" |
| mkdir -p stubs |
| cat <<-EOF >stubs/git |
| #!/bin/sh |
| if [ "\$2" = "rev-parse" ]; then |
| echo "deadbeef" |
| else |
| cp -RT "${DATA_DIR}/package_tree" "\${*: -1}" |
| mkdir "\${*: -1}/.git" |
| fi |
| EOF |
| chmod +x stubs/git |
| export PATH=${PWD}/stubs:${PATH} |
| } |
| |
| |
| # Places tar in stubs/ and updates PATH |
| stub_tar() { |
| echo "Replacing tar with a stub" |
| mkdir -p stubs |
| cat <<-EOF >stubs/tar |
| #!/bin/sh |
| cp -RT "${DATA_DIR}/package_tree" "\$2" |
| EOF |
| chmod +x stubs/tar |
| export PATH=$PWD/stubs:$PATH |
| } |
| |
| # Places curl in stubs/ and updates PATH. |
| stub_curl() { |
| echo "Replacing curl with a stub" |
| mkdir -p stubs |
| cat <<-EOF >stubs/curl |
| #!/bin/sh |
| cp -RT "${DATA_DIR}/package_tree/tarball.tar.gz" "\$2" |
| EOF |
| chmod +x stubs/curl |
| export PATH=${PWD}/stubs:${PATH} |
| } |
| |
| # Nops git stub. |
| stub_dead_git() { |
| echo "Overwriting git with nop stub" |
| cat <<-EOF >stubs/git |
| #!/bin/sh |
| EOF |
| chmod +x stubs/git |
| export PATH=${PWD}/stubs:${PATH} |
| } |
| |
| # Nops curl stub. |
| stub_dead_curl() { |
| echo "Overwriting curl with nop stub" |
| cat <<-EOF >stubs/curl |
| #!/bin/sh |
| EOF |
| chmod +x stubs/curl |
| export PATH=${PWD}/stubs:${PATH} |
| } |
| |
| # Run after stub_make from the same working directory. |
| # Places per-product tools in the right out/ paths. |
| # Call this from within the product directory. |
| stub_tools() { |
| mkdir -p $HOST_TOOL_PATH |
| cp stubs/make $HOST_TOOL_PATH/fastboot |
| cp stubs/make $HOST_TOOL_PATH/adb |
| mkdir -p $TOOL_PATH |
| cp stubs/make $TOOL_PATH/provision-device |
| } |