• 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
62            # SwiftShader is loaded as the system Vulkan driver on Android, not compiled by ANGLE
63            "angle_enable_swiftshader = false"
64
65            # Disable all shader translator targets except desktop GL (for Vulkan)
66            "angle_enable_essl = false"
67            "angle_enable_glsl = false"
68            "angle_enable_hlsl = false"
69
70            "angle_enable_commit_id = false"
71
72            # Disable histogram/protobuf support
73            "angle_has_histograms = false"
74
75            # Use system lib(std)c++, since the Chromium library breaks std::string
76            "use_custom_libcxx = false"
77
78            # rapidJSON is used for ANGLE's frame capture (among other things), which is unnecessary for AOSP builds.
79            "angle_has_rapidjson = false"
80        )
81
82        if [[ "$1" == "--enableApiTrace" ]]; then
83            gn_args=(
84                "${gn_args[@]}"
85                "angle_enable_trace = true"
86                "angle_enable_trace_android_logcat = true"
87            )
88        fi
89
90        gn gen ${GN_OUTPUT_DIRECTORY} --args="${gn_args[*]}"
91        gn desc ${GN_OUTPUT_DIRECTORY} --format=json "*" > ${GN_OUTPUT_DIRECTORY}/desc.$abi.json
92    done
93
94    python3 scripts/generate_android_bp.py \
95        --gn_json_arm=${GN_OUTPUT_DIRECTORY}/desc.arm.json \
96        --gn_json_arm64=${GN_OUTPUT_DIRECTORY}/desc.arm64.json \
97        --gn_json_x86=${GN_OUTPUT_DIRECTORY}/desc.x86.json \
98        --gn_json_x64=${GN_OUTPUT_DIRECTORY}/desc.x64.json \
99        > Android.bp
100}
101
102
103if [[ "$1" == "--genAndroidBp" ]];then
104    generate_Android_bp_file "$2"
105    exit 0
106fi
107
108# Check out depot_tools locally and add it to the path
109DEPOT_TOOLS_DIR=_depot_tools
110rm -rf ${DEPOT_TOOLS_DIR}
111git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ${DEPOT_TOOLS_DIR}
112export PATH=`pwd`/${DEPOT_TOOLS_DIR}:$PATH
113
114third_party_deps=(
115    "build"
116    "third_party/abseil-cpp"
117    "third_party/vulkan-deps/glslang/src"
118    "third_party/vulkan-deps/spirv-headers/src"
119    "third_party/vulkan-deps/spirv-tools/src"
120    "third_party/vulkan-deps/vulkan-headers/src"
121    "third_party/vulkan_memory_allocator"
122)
123
124root_add_deps=(
125  "build"
126  "third_party"
127)
128
129# Only add the parts of NDK and vulkan-deps that are required by ANGLE. The entire dep is too large.
130delete_only_deps=(
131    "third_party/vulkan-deps"
132    "third_party/zlib"  # Replaced by Android's zlib; delete for gclient to work https://crbug.com/skia/14155#c3
133)
134
135# Delete dep directories so that gclient can check them out
136for dep in "${third_party_deps[@]}" "${delete_only_deps[@]}"; do
137    rm -rf "$dep"
138done
139
140# Sync all of ANGLE's deps so that 'gn gen' works
141python scripts/bootstrap.py
142gclient sync --reset --force --delete_unversioned_trees
143
144# Delete outdir to ensure a clean gn run.
145rm -rf ${GN_OUTPUT_DIRECTORY}
146
147generate_Android_bp_file
148
149# Delete outdir to cleanup after gn.
150rm -rf ${GN_OUTPUT_DIRECTORY}
151
152# Delete all unsupported 3rd party dependencies. Do this after generate_Android_bp_file, so
153# it has access to all of the necessary BUILD.gn files.
154unsupported_third_party_deps=(
155   "third_party/jdk"
156   "third_party/llvm-build"
157   "third_party/android_build_tools"
158   "third_party/android_sdk"
159   "third_party/android_toolchain"
160   "third_party/zlib"  # Replaced by Android's zlib
161)
162for unsupported_third_party_dep in "${unsupported_third_party_deps[@]}"; do
163   rm -rf "$unsupported_third_party_dep"
164done
165
166git add Android.bp
167
168# Delete the .git files in each dep so that it can be added to this repo. Some deps like jsoncpp
169# have multiple layers of deps so delete everything before adding them.
170for dep in "${third_party_deps[@]}"; do
171   rm -rf "$dep"/.git
172done
173
174extra_removal_files=(
175   # build/linux is hundreds of megs that aren't needed.
176   "build/linux"
177   # Debuggable APKs cannot be merged into AOSP as a prebuilt
178   "build/android/CheckInstallApk-debug.apk"
179   # Remove Android.mk files to prevent automated CLs:
180   #   "[LSC] Add LOCAL_LICENSE_KINDS to external/angle"
181   "Android.mk"
182   "third_party/vulkan-deps/glslang/src/Android.mk"
183   "third_party/vulkan-deps/glslang/src/ndk_test/Android.mk"
184   "third_party/vulkan-deps/spirv-tools/src/Android.mk"
185   "third_party/vulkan-deps/spirv-tools/src/android_test/Android.mk"
186)
187
188for removal_file in "${extra_removal_files[@]}"; do
189   rm -rf "$removal_file"
190done
191
192# Add all changes under $root_add_deps so we delete everything not explicitly allowed.
193for root_add_dep in "${root_add_deps[@]}"; do
194    git add -f $root_add_dep
195done
196
197# Done with depot_tools
198rm -rf $DEPOT_TOOLS_DIR
199