• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Imports intermediate CLs for correct generation of desc_*.json
71# Arguments:
72#   chromium_dir, string
73#######################################
74function cherry_pick_chromium_cls() (
75  cd "${chromium_dir}"
76  # Remove once 122.0.6168.0 is imported
77  git fetch https://chromium.googlesource.com/chromium/src refs/changes/32/5083632/4 && git cherry-pick FETCH_HEAD
78  git fetch https://chromium.googlesource.com/chromium/src refs/changes/14/5094514/5 && git cherry-pick FETCH_HEAD
79  # Remove once 122.0.6183.0 is imported
80  git fetch https://chromium.googlesource.com/chromium/src refs/changes/87/5088887/9 && git cherry-pick FETCH_HEAD
81  # Remove once 122.0.6240.0 is imported
82  git fetch https://chromium.googlesource.com/chromium/src refs/changes/35/5184435/4 && git cherry-pick FETCH_HEAD
83  # Remove once 123.0.6272.0 is imported
84  git fetch https://chromium.googlesource.com/chromium/src refs/changes/93/5164293/3 && git cherry-pick FETCH_HEAD
85  # Remove once 123.0.6286.0 is imported
86  git fetch https://chromium.googlesource.com/chromium/src refs/changes/42/5259242/5 && git cherry-pick FETCH_HEAD
87  # Remove once 124.0.6317.0 is imported
88  git fetch https://chromium.googlesource.com/chromium/src refs/changes/51/5317651/2 && git cherry-pick FETCH_HEAD
89  # Remove once 124.0.6340.0 is imported
90  git fetch https://chromium.googlesource.com/chromium/src refs/changes/79/5340179/4 && git cherry-pick FETCH_HEAD
91)
92#######################################
93# Generate desc.json for a specified architecture.
94# Globals:
95#   ANDROID_BUILD_TOP
96#   OUT_PATH
97# Arguments:
98#   target_cpu, string
99#   chromium_dir, string
100#######################################
101function gn_desc() (
102  local -r target_cpu="$1"
103  local -r chromium_dir="$2"
104  local -a gn_args=(
105    "target_os = \"android\""
106    "enable_websockets = false"
107    "disable_file_support = true"
108    "is_component_build = false"
109    "use_partition_alloc = false"
110    "include_transport_security_state_preload_list = false"
111    "use_platform_icu_alternatives = true"
112    "default_min_sdk_version = 21"
113    "enable_reporting = true"
114    "use_hashed_jni_names = true"
115    "enable_base_tracing = false"
116    "is_cronet_build = true"
117    "is_debug = false"
118    "is_official_build = true"
119    "use_nss_certs = false"
120    "clang_use_default_sample_profile = false"
121    "media_use_ffmpeg=false"
122    "use_thin_lto=false"
123    "enable_resource_allowlist_generation=false"
124    "exclude_unwind_tables=true"
125    "symbol_level=1"
126    "enable_rust=false"
127    "is_cronet_for_aosp_build=true"
128  )
129  gn_args+=("target_cpu = \"${target_cpu}\"")
130
131  # Only set arm_use_neon on arm architectures to prevent warning from being
132  # written to json output.
133  if [[ "${target_cpu}" = "arm" ]]; then
134    gn_args+=("arm_use_neon = false")
135  fi
136
137  cd "${chromium_dir}"
138
139  # Configure gn args.
140  gn gen "${OUT_PATH}" --args="${gn_args[*]}"
141
142  # Generate desc.json.
143  local -r out_file="${ANDROID_BUILD_TOP}/external/cronet/android/tools/gn2bp/desc_${target_cpu}.json"
144  gn desc "${OUT_PATH}" --format=json --all-toolchains "//*" > "${out_file}"
145)
146
147while getopts "${OPTSTRING}" opt; do
148  case "${opt}" in
149    d) chromium_dir="${OPTARG}" ;;
150    f) force_reset=true ;;
151    r) rev="${OPTARG}" ;;
152    ?) usage ;;
153    *) echo "'${opt}' '${OPTARG}'"
154  esac
155done
156
157if [ -z "${chromium_dir}" ]; then
158  echo "-d argument required"
159  usage
160fi
161
162if [ -z "${rev}" ]; then
163  echo "-r argument required"
164  usage
165fi
166
167if [ -z "${ANDROID_BUILD_TOP}" ]; then
168    echo "ANDROID_BUILD_TOP is not set. Please run source build/envsetup.sh && lunch"
169    exit 1
170fi
171
172
173setup_chromium_src_repo "${rev}" "${chromium_dir}" "${force_reset}"
174cherry_pick_chromium_cls "${chromium_dir}"
175gn_desc x86 "${chromium_dir}"
176gn_desc x64 "${chromium_dir}"
177gn_desc arm "${chromium_dir}"
178gn_desc arm64 "${chromium_dir}"
179gn_desc riscv64 "${chromium_dir}"
180