xref: /aosp_15_r20/external/cronet/android/tools/gn2bp/gen_desc_json.sh (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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  # Delete once 130.0.6675.0 is imported.
77  git fetch https://chromium.googlesource.com/chromium/src refs/changes/44/5808944/6 && git cherry-pick FETCH_HEAD
78  # Delete once 130.0.6675.0 is imported.
79  git fetch https://chromium.googlesource.com/chromium/src refs/changes/45/5808945/6 && git cherry-pick FETCH_HEAD
80  # Delete once 130.0.6675.0 is imported.
81  git fetch https://chromium.googlesource.com/chromium/src refs/changes/78/5809278/6 && git cherry-pick FETCH_HEAD
82  # Delete once 130.0.6675.0 is imported.
83  git fetch https://chromium.googlesource.com/chromium/src refs/changes/40/5806340/8 && git cherry-pick FETCH_HEAD
84  # Delete once 130.0.6682.0 is imported.
85  git fetch https://chromium.googlesource.com/chromium/src refs/changes/80/5809380/6 && git cherry-pick FETCH_HEAD
86)
87#######################################
88# Generate desc.json for a specified architecture.
89# Globals:
90#   ANDROID_BUILD_TOP
91#   OUT_PATH
92# Arguments:
93#   target_cpu, string
94#   chromium_dir, string
95#######################################
96function gn_desc() (
97  local -r target_cpu="$1"
98  local -r chromium_dir="$2"
99  local -a gn_args=(
100    "target_os = \"android\""
101    "enable_websockets = false"
102    "disable_file_support = true"
103    "is_component_build = false"
104    "use_partition_alloc = false"
105    "include_transport_security_state_preload_list = false"
106    "use_platform_icu_alternatives = true"
107    "default_min_sdk_version = 21"
108    "enable_reporting = true"
109    "use_hashed_jni_names = true"
110    "enable_base_tracing = false"
111    "is_cronet_build = true"
112    "is_debug = false"
113    "is_official_build = true"
114    "use_nss_certs = false"
115    "clang_use_default_sample_profile = false"
116    "media_use_ffmpeg=false"
117    "use_thin_lto=false"
118    "enable_resource_allowlist_generation=false"
119    "exclude_unwind_tables=true"
120    "symbol_level=1"
121    "enable_rust=true"
122    "is_cronet_for_aosp_build=true"
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
162if [ -z "${ANDROID_BUILD_TOP}" ]; then
163    echo "ANDROID_BUILD_TOP is not set. Please run source build/envsetup.sh && lunch"
164    exit 1
165fi
166
167
168setup_chromium_src_repo "${rev}" "${chromium_dir}" "${force_reset}"
169cherry_pick_chromium_cls "${chromium_dir}"
170gn_desc x86 "${chromium_dir}"
171gn_desc x64 "${chromium_dir}"
172gn_desc arm "${chromium_dir}"
173gn_desc arm64 "${chromium_dir}"
174gn_desc riscv64 "${chromium_dir}"
175