• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3#  Copyright The ANGLE Project Authors. All rights reserved.
4#  Use of this source code is governed by a BSD-style license that can be
5#  found in the LICENSE file.
6#
7# Generates a roll CL within the ANGLE repository of AOSP.
8#
9# WARNING: Running this script without args may mess up the checkout.
10#   See --genAndroidBp for testing just the code generation.
11
12# exit when any command fails
13set -eE -o functrace
14
15failure() {
16  local lineno=$1
17  local msg=$2
18  echo "Failed at $lineno: $msg"
19}
20trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
21
22# Change the working directory to the ANGLE root directory
23cd "${0%/*}/.."
24
25GN_OUTPUT_DIRECTORY=out/Android
26
27function generate_Android_bp_file() {
28    abis=(
29        "arm"
30        "arm64"
31        "x86"
32        "x64"
33    )
34
35    for abi in "${abis[@]}"; do
36        # generate gn build files and convert them to blueprints
37        gn_args=(
38            "target_os = \"android\""
39            "is_component_build = false"
40            "is_debug = false"
41            "dcheck_always_on = false"
42            "symbol_level = 0"
43            "angle_standalone = false"
44            "angle_build_all = false"
45            "angle_expose_non_conformant_extensions_and_versions = true"
46
47            # Build for 64-bit CPUs
48            "target_cpu = \"$abi\""
49
50            # Target ndk API 26 to make sure ANGLE can use the Vulkan backend on Android
51            "android32_ndk_api_level = 26"
52            "android64_ndk_api_level = 26"
53
54            # Disable all backends except Vulkan
55            "angle_enable_vulkan = true"
56            "angle_enable_gl = false"
57            "angle_enable_d3d9 = false"
58            "angle_enable_d3d11 = false"
59            "angle_enable_null = false"
60            "angle_enable_metal = false"
61            "angle_enable_wgpu = false"
62
63            # SwiftShader is loaded as the system Vulkan driver on Android, not compiled by ANGLE
64            "angle_enable_swiftshader = false"
65
66            # Disable all shader translator targets except desktop GL (for Vulkan)
67            "angle_enable_essl = false"
68            "angle_enable_glsl = false"
69            "angle_enable_hlsl = false"
70
71            "angle_enable_commit_id = false"
72
73            # Disable histogram/protobuf support
74            "angle_has_histograms = false"
75
76            # Use system lib(std)c++, since the Chromium library breaks std::string
77            "use_custom_libcxx = false"
78
79            # rapidJSON is used for ANGLE's frame capture (among other things), which is unnecessary for AOSP builds.
80            "angle_has_rapidjson = false"
81        )
82
83        if [[ "$1" == "--enableApiTrace" ]]; then
84            gn_args=(
85                "${gn_args[@]}"
86                "angle_enable_trace = true"
87                "angle_enable_trace_android_logcat = true"
88            )
89        fi
90
91        gn gen ${GN_OUTPUT_DIRECTORY} --args="${gn_args[*]}"
92        gn desc ${GN_OUTPUT_DIRECTORY} --format=json "*" > ${GN_OUTPUT_DIRECTORY}/desc.$abi.json
93    done
94
95    python3 scripts/generate_android_bp.py \
96        --gn_json_arm=${GN_OUTPUT_DIRECTORY}/desc.arm.json \
97        --gn_json_arm64=${GN_OUTPUT_DIRECTORY}/desc.arm64.json \
98        --gn_json_x86=${GN_OUTPUT_DIRECTORY}/desc.x86.json \
99        --gn_json_x64=${GN_OUTPUT_DIRECTORY}/desc.x64.json \
100        --output=Android.bp
101}
102
103
104if [[ "$1" == "--genAndroidBp" ]];then
105    generate_Android_bp_file "$2"
106    exit 0
107fi
108
109# Check out depot_tools locally and add it to the path
110DEPOT_TOOLS_DIR=_depot_tools
111rm -rf ${DEPOT_TOOLS_DIR}
112git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ${DEPOT_TOOLS_DIR}
113export PATH=`pwd`/${DEPOT_TOOLS_DIR}:$PATH
114
115third_party_deps=(
116    "build"
117    "third_party/abseil-cpp"
118    "third_party/glslang/src"
119    "third_party/spirv-headers/src"
120    "third_party/spirv-tools/src"
121    "third_party/vulkan-headers/src"
122    "third_party/vulkan_memory_allocator"
123)
124
125root_add_deps=(
126  "build"
127  "third_party"
128)
129
130delete_only_deps=(
131    "third_party/zlib"  # Replaced by Android's zlib; delete for gclient to work https://crbug.com/skia/14155#c3
132)
133
134# Delete dep directories so that gclient can check them out
135for dep in "${third_party_deps[@]}" "${delete_only_deps[@]}"; do
136    rm -rf "$dep"
137done
138
139# Remove cruft from any previous bad rolls (https://anglebug.com/8352)
140extra_third_party_removal_patterns=(
141   "*/_gclient_*"
142)
143
144for removal_dir in "${extra_third_party_removal_patterns[@]}"; do
145    find third_party -wholename "$removal_dir" -delete
146done
147
148# Sync all of ANGLE's deps so that 'gn gen' works
149python3 scripts/bootstrap.py
150gclient sync --reset --force --delete_unversioned_trees
151
152# Delete outdir to ensure a clean gn run.
153rm -rf ${GN_OUTPUT_DIRECTORY}
154
155generate_Android_bp_file
156
157# Delete outdir to cleanup after gn.
158rm -rf ${GN_OUTPUT_DIRECTORY}
159
160# Delete all unsupported 3rd party dependencies. Do this after generate_Android_bp_file, so
161# it has access to all of the necessary BUILD.gn files.
162unsupported_third_party_deps=(
163   "third_party/jdk"
164   "third_party/llvm-build"
165   "third_party/android_build_tools"
166   "third_party/android_sdk"
167   "third_party/android_toolchain"
168   "third_party/zlib"  # Replaced by Android's zlib
169)
170for unsupported_third_party_dep in "${unsupported_third_party_deps[@]}"; do
171   rm -rf "$unsupported_third_party_dep"
172done
173
174git add Android.bp
175
176# Delete the .git files in each dep so that it can be added to this repo. Some deps like jsoncpp
177# have multiple layers of deps so delete everything before adding them.
178for dep in "${third_party_deps[@]}"; do
179   rm -rf "$dep"/.git
180done
181
182# Delete all the .gitmodules files, since they are not allowed in AOSP external projects.
183find . -name \.gitmodules -exec rm {} \;
184
185extra_removal_files=(
186   # build/linux is hundreds of megs that aren't needed.
187   "build/linux"
188   # Debuggable APKs cannot be merged into AOSP as a prebuilt
189   "build/android/CheckInstallApk-debug.apk"
190   # Remove Android.mk files to prevent automated CLs:
191   #   "[LSC] Add LOCAL_LICENSE_KINDS to external/angle"
192   "Android.mk"
193   "third_party/glslang/src/Android.mk"
194   "third_party/glslang/src/ndk_test/Android.mk"
195   "third_party/spirv-tools/src/Android.mk"
196   "third_party/spirv-tools/src/android_test/Android.mk"
197   "third_party/siso" # Not needed
198)
199
200for removal_file in "${extra_removal_files[@]}"; do
201   rm -rf "$removal_file"
202done
203
204# Add all changes under $root_add_deps so we delete everything not explicitly allowed.
205for root_add_dep in "${root_add_deps[@]}"; do
206    git add -f $root_add_dep
207done
208
209# Done with depot_tools
210rm -rf $DEPOT_TOOLS_DIR
211