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 27set -e -x 28 29OPTSTRING=d:fr: 30 31usage() { 32 cat <<EOF 33Usage: gen_gn_desc.sh -d dir -r rev [-f] 34EOF 35 exit 1 36} 37 38 39# Run this script inside a full chromium checkout. 40 41OUT_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####################################### 50function 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# Apply patches in external/cronet/patches. 71# Globals: 72# ANDROID_BUILD_TOP 73# Arguments: 74# chromium_dir, string 75####################################### 76function apply_patches() ( 77 local -r chromium_dir=$1 78 local -r patches_dir="${ANDROID_BUILD_TOP}/external/cronet/patches" 79 80 cd "${chromium_dir}" 81 82 local -r patches=$(ls "${patches_dir}") 83 local patch 84 for patch in ${patches}; do 85 git am --3way "${patches_dir}/${patch}" 86 done 87) 88 89####################################### 90# Generate desc.json for a specified architecture. 91# Globals: 92# ANDROID_BUILD_TOP 93# OUT_PATH 94# Arguments: 95# target_cpu, string 96# chromium_dir, string 97####################################### 98function gn_desc() ( 99 local -r target_cpu="$1" 100 local -r chromium_dir="$2" 101 local -a gn_args=( 102 "target_os = \"android\"" 103 "enable_websockets = false" 104 "disable_file_support = true" 105 "is_component_build = false" 106 "use_partition_alloc = false" 107 "include_transport_security_state_preload_list = false" 108 "use_platform_icu_alternatives = true" 109 "default_min_sdk_version = 19" 110 "enable_reporting = true" 111 "use_hashed_jni_names = true" 112 "enable_base_tracing = false" 113 "is_cronet_build = true" 114 "is_debug = false" 115 "is_official_build = true" 116 "use_nss_certs = false" 117 "clang_use_default_sample_profile = false" 118 "media_use_ffmpeg=false" 119 "use_thin_lto=false" 120 "enable_resource_allowlist_generation=false" 121 "exclude_unwind_tables=true" 122 "symbol_level=1" 123 ) 124 gn_args+=("target_cpu = \"${target_cpu}\"") 125 126 # Only set arm_use_neon on arm architectures to prevent warning from being 127 # written to json output. 128 if [[ "${target_cpu}" = "arm" ]]; then 129 gn_args+=("arm_use_neon = false") 130 fi 131 132 cd "${chromium_dir}" 133 134 # Configure gn args. 135 gn gen "${OUT_PATH}" --args="${gn_args[*]}" 136 137 # Generate desc.json. 138 local -r out_file="${ANDROID_BUILD_TOP}/external/cronet/android/tools/gn2bp/desc_${target_cpu}.json" 139 gn desc "${OUT_PATH}" --format=json --all-toolchains "//*" > "${out_file}" 140) 141 142while getopts "${OPTSTRING}" opt; do 143 case "${opt}" in 144 d) chromium_dir="${OPTARG}" ;; 145 f) force_reset=true ;; 146 r) rev="${OPTARG}" ;; 147 ?) usage ;; 148 *) echo "'${opt}' '${OPTARG}'" 149 esac 150done 151 152if [ -z "${chromium_dir}" ]; then 153 echo "-d argument required" 154 usage 155fi 156 157if [ -z "${rev}" ]; then 158 echo "-r argument required" 159 usage 160fi 161 162setup_chromium_src_repo "${rev}" "${chromium_dir}" "${force_reset}" 163apply_patches "${chromium_dir}" 164gn_desc x86 "${chromium_dir}" 165gn_desc x64 "${chromium_dir}" 166gn_desc arm "${chromium_dir}" 167gn_desc arm64 "${chromium_dir}" 168 169