1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#!/bin/bash
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
if [ ! -d "./third_party/mediapipe" ]; then
echo "Please set the current working directory to chromium root first."
exit 1
fi
SRC_DIR=${PWD}
MP_VERSION=$(grep -oP 'Version: \K[0-9a-f]+' third_party/mediapipe/README.chromium)
function join_by {
local d=${1-}
local f=${2-}
if shift 2; then
printf "%s" "$f" "${@/#/$d}"
fi
}
# Fetch the following third party mediapipe dependencies.
THIRD_PARTY_DEPS=(
"com_google_audio_tools" # https://github.com/google/multichannel-audio-tools
)
# Patches to apply (<directory> <patch file>)
THIRD_PARTY_DEPS_PATCHES=(
"third_party/com_google_audio_tools third_party/com_google_audio_tools_fixes.diff"
)
EXCLUDE_PATTERNS=(
# Directories
.git/
docs/
ios/
java/
models/
objc/
python/
vision/
web/
# Suffixes
py$
# Wildcards
example
test
)
EXCLUDE_PATTERN=$(join_by '|' "${EXCLUDE_PATTERNS[@]}")
OBJC_INCLUDE_PATTERNS=(
objc/CFHolder.h
objc/util.cc
objc/util.h
)
OBJC_INCLUDE_PATTERN=$(join_by '|' "${OBJC_INCLUDE_PATTERNS[@]}")
WEB_INCLUDE_PATTERNS=(
web/jspi_check.h
)
WEB_INCLUDE_PATTERN=$(join_by '|' "${WEB_INCLUDE_PATTERNS[@]}")
if [[ -d "/tmp/mediapipe" ]]; then
rm -rf /tmp/mediapipe
fi
echo "Downloading "mediapipe@${MP_VERSION}"..."
mkdir -p /tmp/mediapipe
curl -s -L "https://github.com/google/mediapipe/archive/${MP_VERSION}.tar.gz" | tar xz --strip=1 -C /tmp/mediapipe
cd /tmp/mediapipe
FILES=$(find . -type f | grep -Ev "${EXCLUDE_PATTERN}" | sort)
OBJC_FILES=$(find . -type f | grep -E "${OBJC_INCLUDE_PATTERN}" | sort)
WEB_FILES=$(find . -type f | grep -E "${WEB_INCLUDE_PATTERN}" | sort)
cd "${SRC_DIR}"
rm -rf third_party/mediapipe/src
mkdir -p third_party/mediapipe/src
echo "Replacing existing files..."
cd third_party/mediapipe/src/
for file in ${FILES[@]} ${OBJC_FILES[@]} ${WEB_FILES[@]} ; do
mkdir -p "$(dirname ${file})"
cp "/tmp/mediapipe/${file}" "${file}"
done
# TODO: Consider using bazel directly to parse the WORKSPACE or pull deps.
echo "Downloading mediapipe third party dependencies..."
for dep in "${THIRD_PARTY_DEPS[@]}" ; do
echo "Downloading ${dep}..."
ARCHIVE=$(grep -Pzo "(?s)name = \"${dep}\".*?\)" WORKSPACE | grep -Eao 'https://github.com[^"]*' | sed "s/zip/tar\.gz/")
if [ -z "${ARCHIVE}" ]; then
echo "Failed to find ${dep} archive in WORKSPACE"
exit 1
fi
echo "Downloading ${ARCHIVE}..."
mkdir -p ./third_party/${dep}
curl -s -L "${ARCHIVE}" | tar xz --strip=1 -C ./third_party/${dep}
done
# Apply within third party dependencies.
for patch_file in "${THIRD_PARTY_DEPS_PATCHES[@]}" ; do
set -- $patch_file
echo $1
git apply --directory=$1 $2 || echo "Failed to apply $2"
done
# Replace (D)CHECK with ABSL equivalents.
for dep in "${THIRD_PARTY_DEPS[@]}" ; do
find ./third_party/${dep} -type f -exec sed -Ei 's/(DCHECK|CHECK)/ABSL_\0/g' {} \;
done
cd "${SRC_DIR}"
echo "Applying patches..."
for patch_file in $(ls third_party/mediapipe/patches/) ; do
git apply "third_party/mediapipe/patches/${patch_file}" || echo "Failed to apply third_party/mediapipe/patches/${patch_file}"
done
rm -rf /tmp/mediapipe
echo "Done"
|