Mohannad Farrag | 185b76a | 2024-02-16 18:07:16 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2023 Google Inc. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Script to generate `gn desc` json outputs that are used as an input to the |
| 18 | # gn2bp conversion tool. |
| 19 | # Inputs: |
| 20 | # Arguments: |
| 21 | # -d dir: The directory that points to a local checkout of chromium/src. |
| 22 | # -r rev: The reference revision of upstream Chromium to use. Must match the |
| 23 | # last revision that has been imported using import_cronet.sh. |
| 24 | # Optional arguments: |
| 25 | # -f: Force reset the chromium/src directory. |
| 26 | |
| 27 | set -e -x |
| 28 | |
| 29 | OPTSTRING=d:fr: |
| 30 | |
| 31 | usage() { |
| 32 | cat <<EOF |
| 33 | Usage: gen_gn_desc.sh -d dir -r rev [-f] |
| 34 | EOF |
| 35 | exit 1 |
| 36 | } |
| 37 | |
| 38 | |
| 39 | # Run this script inside a full chromium checkout. |
| 40 | |
| 41 | OUT_PATH="out/cronet" |
| 42 | |
| 43 | ####################################### |
| 44 | # Sets the chromium/src repository to a reference state. |
| 45 | # Arguments: |
| 46 | # rev, string |
| 47 | # chromium_dir, string |
| 48 | # force_reset, boolean |
| 49 | ####################################### |
| 50 | function setup_chromium_src_repo() ( |
| 51 | local -r rev="$1" |
| 52 | local -r chromium_dir="$2" |
| 53 | local -r force_reset="$3" |
| 54 | |
| 55 | cd "${chromium_dir}" |
| 56 | git fetch --tags |
| 57 | |
| 58 | if [ -n "${force_reset}" ]; then |
| 59 | git reset --hard |
| 60 | fi |
| 61 | |
| 62 | git checkout "${rev}" |
| 63 | gclient sync \ |
| 64 | --no-history \ |
| 65 | --shallow \ |
| 66 | --delete_unversioned_trees |
| 67 | ) |
| 68 | |
| 69 | ####################################### |
| 70 | # Generate desc.json for a specified architecture. |
| 71 | # Globals: |
| 72 | # ANDROID_BUILD_TOP |
| 73 | # OUT_PATH |
| 74 | # Arguments: |
| 75 | # target_cpu, string |
| 76 | # chromium_dir, string |
| 77 | ####################################### |
| 78 | function gn_desc() ( |
| 79 | local -r target_cpu="$1" |
| 80 | local -r chromium_dir="$2" |
| 81 | local -a gn_args=( |
| 82 | "target_os = \"android\"" |
| 83 | "enable_websockets = false" |
| 84 | "disable_file_support = true" |
| 85 | "is_component_build = false" |
| 86 | "use_partition_alloc = false" |
| 87 | "include_transport_security_state_preload_list = false" |
| 88 | "use_platform_icu_alternatives = true" |
| 89 | "default_min_sdk_version = 21" |
| 90 | "enable_reporting = true" |
| 91 | "use_hashed_jni_names = true" |
| 92 | "enable_base_tracing = false" |
| 93 | "is_cronet_build = true" |
| 94 | "is_debug = false" |
| 95 | "is_official_build = true" |
| 96 | "use_nss_certs = false" |
| 97 | "clang_use_default_sample_profile = false" |
| 98 | "media_use_ffmpeg=false" |
| 99 | "use_thin_lto=false" |
| 100 | "enable_resource_allowlist_generation=false" |
| 101 | "exclude_unwind_tables=true" |
| 102 | "symbol_level=1" |
| 103 | "enable_rust=false" |
| 104 | "is_cronet_for_aosp_build=true" |
| 105 | ) |
| 106 | gn_args+=("target_cpu = \"${target_cpu}\"") |
| 107 | |
| 108 | # Only set arm_use_neon on arm architectures to prevent warning from being |
| 109 | # written to json output. |
| 110 | if [[ "${target_cpu}" = "arm" ]]; then |
| 111 | gn_args+=("arm_use_neon = false") |
| 112 | fi |
| 113 | |
| 114 | cd "${chromium_dir}" |
| 115 | |
| 116 | # Configure gn args. |
| 117 | gn gen "${OUT_PATH}" --args="${gn_args[*]}" |
| 118 | |
| 119 | # Generate desc.json. |
| 120 | local -r out_file="${ANDROID_BUILD_TOP}/external/cronet/android/tools/gn2bp/desc_${target_cpu}.json" |
| 121 | gn desc "${OUT_PATH}" --format=json --all-toolchains "//*" > "${out_file}" |
| 122 | ) |
| 123 | |
| 124 | while getopts "${OPTSTRING}" opt; do |
| 125 | case "${opt}" in |
| 126 | d) chromium_dir="${OPTARG}" ;; |
| 127 | f) force_reset=true ;; |
| 128 | r) rev="${OPTARG}" ;; |
| 129 | ?) usage ;; |
| 130 | *) echo "'${opt}' '${OPTARG}'" |
| 131 | esac |
| 132 | done |
| 133 | |
| 134 | if [ -z "${chromium_dir}" ]; then |
| 135 | echo "-d argument required" |
| 136 | usage |
| 137 | fi |
| 138 | |
| 139 | if [ -z "${rev}" ]; then |
| 140 | echo "-r argument required" |
| 141 | usage |
| 142 | fi |
| 143 | |
| 144 | if [ -z "${ANDROID_BUILD_TOP}" ]; then |
| 145 | echo "ANDROID_BUILD_TOP is not set. Please run source build/envsetup.h && lunch" |
| 146 | exit 1 |
| 147 | fi |
| 148 | |
| 149 | |
| 150 | setup_chromium_src_repo "${rev}" "${chromium_dir}" "${force_reset}" |
| 151 | gn_desc x86 "${chromium_dir}" |
| 152 | gn_desc x64 "${chromium_dir}" |
| 153 | gn_desc arm "${chromium_dir}" |
| 154 | gn_desc arm64 "${chromium_dir}" |
| 155 | |