Zhi Dou | 77c9f0c | 2023-10-11 19:49:56 +0000 | [diff] [blame^] | 1 | #!/bin/bash -e |
| 2 | # Copyright (C) 2023 The Android Open Source Project |
| 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 | source $(cd $(dirname $BASH_SOURCE) &> /dev/null && pwd)/../../make/shell_utils.sh |
| 18 | require_top |
| 19 | |
| 20 | function print_help() { |
| 21 | echo -e "overrideflags is used to set default value for local build." |
| 22 | echo -e "\nOptions:" |
| 23 | echo -e "\t--release-config \tPath to release configuration directory. Required" |
| 24 | echo -e "\t--no-edit \tIf present, skip editing flag value file." |
| 25 | echo -e "\t-h/--help \tShow this help." |
| 26 | } |
| 27 | |
| 28 | function main() { |
| 29 | while (($# > 0)); do |
| 30 | case $1 in |
| 31 | --release-config) |
| 32 | if [[ $# -le 1 ]]; then |
| 33 | echo "--release-config requires a path" |
| 34 | return 1 |
| 35 | fi |
| 36 | local release_config_dir="$2" |
| 37 | shift 2 |
| 38 | ;; |
| 39 | --no-edit) |
| 40 | local no_edit="true" |
| 41 | shift 1 |
| 42 | ;; |
| 43 | -h|--help) |
| 44 | print_help |
| 45 | return |
| 46 | ;; |
| 47 | *) |
| 48 | echo "$1 is unrecognized" |
| 49 | print_help |
| 50 | return 1 |
| 51 | ;; |
| 52 | esac |
| 53 | done |
| 54 | |
| 55 | |
| 56 | |
| 57 | case $(uname -s) in |
| 58 | Darwin) |
| 59 | local host_arch=darwin-x86 |
| 60 | ;; |
| 61 | Linux) |
| 62 | local host_arch=linux-x86 |
| 63 | ;; |
| 64 | *) |
| 65 | >&2 echo Unknown host $(uname -s) |
| 66 | return |
| 67 | ;; |
| 68 | esac |
| 69 | |
| 70 | if [[ -z "${release_config_dir}" ]]; then |
| 71 | echo "Please provide release configuration path by --release-config" |
| 72 | exit 1 |
| 73 | elif [ ! -d "${release_config_dir}" ]; then |
| 74 | echo "${release_config_dir} is an invalid directory" |
| 75 | exit 1 |
| 76 | fi |
| 77 | local T="$(gettop)" |
| 78 | local aconfig_dir="${T}"/build/make/tools/aconfig/ |
| 79 | local overrideflag_py="${aconfig_dir}"/overrideflags/overrideflags.py |
| 80 | local overridefile="${release_config_dir}/aconfig/override_values.textproto" |
| 81 | |
| 82 | # Edit override file |
| 83 | if [[ -z "${no_edit}" ]]; then |
| 84 | editor="${EDITOR:-$(which vim)}" |
| 85 | |
| 86 | eval "${editor} ${overridefile}" |
| 87 | if [ $? -ne 0 ]; then |
| 88 | echo "Fail to set override values" |
| 89 | return 1 |
| 90 | fi |
| 91 | fi |
| 92 | |
| 93 | ${T}/prebuilts/build-tools/${host_arch}/bin/py3-cmd -u "${overrideflag_py}" \ |
| 94 | --overrides "${overridefile}" \ |
| 95 | --out "${release_config_dir}/aconfig" |
| 96 | } |
| 97 | |
| 98 | |
| 99 | main "$@" |