-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathupdate_build_files_for_tink_2_0_bazel.sh
executable file
·79 lines (66 loc) · 2.39 KB
/
update_build_files_for_tink_2_0_bazel.sh
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
#!/bin/bash
# Copyright 2023 Google LLC
#
# 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.
################################################################################
# This script updates BUILD files for tink-cc users who use Bazel.
#
# Tink C++ 2.0 changes the project structure moving source code into a `tink`
# folder. As a consequence, all Bazel targets new become `//tink:.*` or
# `//tink/.*`. This scripts perfoms the following replacements:
#
# - "@${TINK_CC_REPO_NAME}//([a-z_]+)(.*)" => "@${TINK_CC_REPO_NAME}//tink/\1\2"
# - "@${TINK_CC_REPO_NAME}//:([a-z_]+)" => "@${TINK_CC_REPO_NAME}//tink:\1"
# - "@${TINK_CC_REPO_NAME}" => "@${TINK_CC_REPO_NAME}//tink:${TINK_CC_REPO_NAME}"
set -euo pipefail
WORKSPACE_DIR=
TINK_CC_REPO_NAME=
usage() {
echo "$0 [-h] <Project root dir> <Tink C++ Bazel repo name>"
echo " -h: Show this help message."
exit 1
}
process_params() {
while getopts "h" opt; do
case "${opt}" in
*) usage ;;
esac
done
shift $((OPTIND - 1))
WORKSPACE_DIR="$1"
TINK_CC_REPO_NAME="$2"
readonly WORKSPACE_DIR
readonly TINK_CC_REPO_NAME
}
main() {
process_params "$@"
if [[ ! -d "${WORKSPACE_DIR}" ]]; then
echo "ERROR: ${WORKSPACE_DIR} does not exist." >&2
usage
fi
pushd "${WORKSPACE_DIR}"
readonly platform="$(uname | tr '[:upper:]' '[:lower:]')"
SEDOPTS=( -i )
# Different than GNU sed, BSD sed's -i parameter requires an extra argument.
if [[ "${platform}" == "darwin" ]]; then
SEDOPTS+=( '' )
fi
readonly SEDOPTS
grep "@${TINK_CC_REPO_NAME}" . -r -l --include BUILD --include BUILD.bazel \
| xargs sed "${SEDOPTS[@]}" \
-e 's#"@'"${TINK_CC_REPO_NAME}"'//\([a-z_]\{1,\}\)\(.*\)"#"@'"${TINK_CC_REPO_NAME}"'//tink/\1\2"#g' \
-e 's#"@'"${TINK_CC_REPO_NAME}"'"#"@'"${TINK_CC_REPO_NAME}"'//tink:tink_cc"#g' \
-e 's#"@'"${TINK_CC_REPO_NAME}"'//:\(.*\)"#"@'"${TINK_CC_REPO_NAME}"'//tink:\1"#g'
popd
}
main "$@"