1 #!/bin/bash 2 # Copyright 2017 The TensorFlow Authors. All Rights Reserved. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # ============================================================================== 16 17 set -e 18 19 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 20 cd "$SCRIPT_DIR/../../.." 21 22 DOWNLOADS_DIR=tensorflow/contrib/lite/downloads 23 BZL_FILE_PATH=tensorflow/workspace.bzl 24 25 # Ensure it is being run from repo root 26 if [ ! -f $BZL_FILE_PATH ]; then 27 echo "Could not find ${BZL_FILE_PATH}": 28 echo "Likely you are not running this from the root directory of the repository."; 29 exit 1; 30 fi 31 32 EIGEN_URL="$(grep -o 'http.*bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)" 33 GEMMLOWP_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)" 34 GOOGLETEST_URL="https://github.com/google/googletest/archive/release-1.8.0.tar.gz" 35 ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | head -n1)" 36 NEON_2_SSE_URL="https://github.com/intel/ARM_NEON_2_x86_SSE/archive/master.zip" 37 FARMHASH_URL="https://mirror.bazel.build/github.com/google/farmhash/archive/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz" 38 FLATBUFFERS_URL="https://github.com/google/flatbuffers/archive/master.zip" 39 40 # TODO(petewarden): Some new code in Eigen triggers a clang bug with iOS arm64, 41 # so work around it by patching the source. 42 replace_by_sed() { 43 local regex="${1}" 44 shift 45 # Detect the version of sed by the return value of "--version" flag. GNU-sed 46 # supports "--version" while BSD-sed doesn't. 47 if ! sed --version >/dev/null 2>&1; then 48 # BSD-sed. 49 sed -i '' -e "${regex}" "$@" 50 else 51 # GNU-sed. 52 sed -i -e "${regex}" "$@" 53 fi 54 } 55 56 download_and_extract() { 57 local usage="Usage: download_and_extract URL DIR" 58 local url="${1:?${usage}}" 59 local dir="${2:?${usage}}" 60 echo "downloading ${url}" >&2 61 mkdir -p "${dir}" 62 if [[ "${url}" == *gz ]]; then 63 curl -Ls "${url}" | tar -C "${dir}" --strip-components=1 -xz 64 elif [[ "${url}" == *zip ]]; then 65 tempdir=$(mktemp -d) 66 tempdir2=$(mktemp -d) 67 68 curl -L ${url} > ${tempdir}/zipped.zip 69 unzip ${tempdir}/zipped.zip -d ${tempdir2} 70 71 # If the zip file contains nested directories, extract the files from the 72 # inner directory. 73 if ls ${tempdir2}/*/* 1> /dev/null 2>&1; then 74 # unzip has no strip components, so unzip to a temp dir, and move the 75 # files we want from the tempdir to destination. 76 cp -R ${tempdir2}/*/* ${dir}/ 77 else 78 cp -R ${tempdir2}/* ${dir}/ 79 fi 80 rm -rf ${tempdir2} ${tempdir} 81 fi 82 83 # Delete any potential BUILD files, which would interfere with Bazel builds. 84 find "${dir}" -type f -name '*BUILD' -delete 85 } 86 87 download_and_extract "${EIGEN_URL}" "${DOWNLOADS_DIR}/eigen" 88 download_and_extract "${GEMMLOWP_URL}" "${DOWNLOADS_DIR}/gemmlowp" 89 download_and_extract "${GOOGLETEST_URL}" "${DOWNLOADS_DIR}/googletest" 90 download_and_extract "${ABSL_URL}" "${DOWNLOADS_DIR}/absl" 91 download_and_extract "${NEON_2_SSE_URL}" "${DOWNLOADS_DIR}/neon_2_sse" 92 download_and_extract "${FARMHASH_URL}" "${DOWNLOADS_DIR}/farmhash" 93 download_and_extract "${FLATBUFFERS_URL}" "${DOWNLOADS_DIR}/flatbuffers" 94 95 replace_by_sed 's#static uint32x4_t p4ui_CONJ_XOR = vld1q_u32( conj_XOR_DATA );#static uint32x4_t p4ui_CONJ_XOR; // = vld1q_u32( conj_XOR_DATA ); - Removed by script#' \ 96 "${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h" 97 replace_by_sed 's#static uint32x2_t p2ui_CONJ_XOR = vld1_u32( conj_XOR_DATA );#static uint32x2_t p2ui_CONJ_XOR;// = vld1_u32( conj_XOR_DATA ); - Removed by scripts#' \ 98 "${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h" 99 replace_by_sed 's#static uint64x2_t p2ul_CONJ_XOR = vld1q_u64( p2ul_conj_XOR_DATA );#static uint64x2_t p2ul_CONJ_XOR;// = vld1q_u64( p2ul_conj_XOR_DATA ); - Removed by script#' \ 100 "${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h" 101 102 echo "download_dependencies.sh completed successfully." >&2 103