• 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# exit when any command fails
10set -eE -o functrace
11
12failure() {
13  local lineno=$1
14  local msg=$2
15  echo "Failed at $lineno: $msg"
16}
17trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
18
19# Change the working directory to the ANGLE root directory
20cd "${0%/*}/.."
21
22GN_OUTPUT_DIRECTORY=out/Android
23
24function generate_Android_bp_file() {
25    rm -rf ${GN_OUTPUT_DIRECTORY}
26
27    abis=(
28        "arm"
29        "arm64"
30        "x86"
31        "x64"
32    )
33
34    for abi in "${abis[@]}"; do
35        # generate gn build files and convert them to blueprints
36        gn_args=(
37            "target_os = \"android\""
38            "is_component_build = false"
39            "is_debug = false"
40            "dcheck_always_on = false"
41            "symbol_level = 0"
42            "angle_standalone = false"
43            "angle_build_all = false"
44
45            # Build for 64-bit CPUs
46            "target_cpu = \"$abi\""
47
48            # Target ndk API 26 to make sure ANGLE can use the Vulkan backend on Android
49            "android32_ndk_api_level = 26"
50            "android64_ndk_api_level = 26"
51
52            # Disable all backends except Vulkan
53            "angle_enable_vulkan = true"
54            "angle_enable_gl = false"
55            "angle_enable_d3d9 = false"
56            "angle_enable_d3d11 = false"
57            "angle_enable_null = false"
58            "angle_enable_metal = false"
59
60            # SwiftShader is loaded as the system Vulkan driver on Android, not compiled by ANGLE
61            "angle_enable_swiftshader = false"
62
63            # Disable all shader translator targets except desktop GL (for Vulkan)
64            "angle_enable_essl = false"
65            "angle_enable_glsl = false"
66            "angle_enable_hlsl = false"
67
68            "angle_enable_commit_id = false"
69
70            # Disable histogram/protobuf support
71            "angle_has_histograms = false"
72
73            # Use system lib(std)c++, since the Chromium library breaks std::string
74            "use_custom_libcxx = false"
75
76            # rapidJSON is used for ANGLE's frame capture (among other things), which is unnecessary for AOSP builds.
77            "angle_has_rapidjson = false"
78        )
79
80        if [[ "$1" == "--enableApiTrace" ]]; then
81            gn_args=(
82                "${gn_args[@]}"
83                "angle_enable_trace = true"
84                "angle_enable_trace_android_logcat = true"
85            )
86        fi
87
88        gn gen ${GN_OUTPUT_DIRECTORY} --args="${gn_args[*]}"
89        gn desc ${GN_OUTPUT_DIRECTORY} --format=json "*" > ${GN_OUTPUT_DIRECTORY}/desc.$abi.json
90    done
91
92    python scripts/generate_android_bp.py \
93        ${GN_OUTPUT_DIRECTORY}/desc.arm.json \
94        ${GN_OUTPUT_DIRECTORY}/desc.arm64.json \
95        ${GN_OUTPUT_DIRECTORY}/desc.x86.json \
96        ${GN_OUTPUT_DIRECTORY}/desc.x64.json > Android.bp
97
98    rm -rf ${GN_OUTPUT_DIRECTORY}
99}
100
101
102if [[ "$1" == "--genAndroidBp" ]];then
103    generate_Android_bp_file "$2"
104    exit 0
105fi
106
107# Check out depot_tools locally and add it to the path
108DEPOT_TOOLS_DIR=_depot_tools
109rm -rf ${DEPOT_TOOLS_DIR}
110git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ${DEPOT_TOOLS_DIR}
111export PATH=`pwd`/${DEPOT_TOOLS_DIR}:$PATH
112
113third_party_deps=(
114    "third_party/abseil-cpp"
115    "third_party/vulkan-deps/glslang/src"
116    "third_party/vulkan-deps/spirv-headers/src"
117    "third_party/vulkan-deps/spirv-tools/src"
118    "third_party/vulkan-deps/vulkan-headers/src"
119    "third_party/vulkan_memory_allocator"
120    "third_party/zlib"
121)
122
123# Only add the parts of NDK and vulkan-deps that are required by ANGLE. The entire dep is too large.
124delete_only_deps=(
125    "third_party/vulkan-deps"
126)
127
128# Delete dep directories so that gclient can check them out
129for dep in "${third_party_deps[@]}" "${delete_only_deps[@]}"; do
130    rm -rf "$dep"
131done
132
133# Sync all of ANGLE's deps so that 'gn gen' works
134python scripts/bootstrap.py
135gclient sync --reset --force --delete_unversioned_trees
136
137generate_Android_bp_file
138
139# Delete all unsupported 3rd party dependencies. Do this after generate_Android_bp_file, so
140# it has access to all of the necessary BUILD.gn files.
141unsupported_third_party_deps=(
142   "third_party/jdk"
143   "third_party/llvm-build"
144   "third_party/android_build_tools"
145   "third_party/android_sdk"
146)
147for unsupported_third_party_dep in "${unsupported_third_party_deps[@]}"; do
148   rm -rf "$unsupported_third_party_dep"
149done
150
151git add Android.bp
152
153# Delete the .git files in each dep so that it can be added to this repo. Some deps like jsoncpp
154# have multiple layers of deps so delete everything before adding them.
155for dep in "${third_party_deps[@]}"; do
156   rm -rf "$dep"/.git
157done
158
159extra_removal_files=(
160   # Some third_party deps have OWNERS files which contains users that have not logged into
161   # the Android gerrit. Repo cannot upload with these files present.
162   "third_party/abseil-cpp/OWNERS"
163   "third_party/vulkan_memory_allocator/OWNERS"
164   "third_party/zlib/OWNERS"
165   "third_party/zlib/google/OWNERS"
166   "third_party/zlib/contrib/tests/OWNERS"
167   "third_party/zlib/contrib/bench/OWNERS"
168   "third_party/zlib/contrib/tests/fuzzers/OWNERS"
169   # Remove Android.mk files to prevent automated CLs:
170   #   "[LSC] Add LOCAL_LICENSE_KINDS to external/angle"
171   "Android.mk"
172   "third_party/vulkan-deps/glslang/src/Android.mk"
173   "third_party/vulkan-deps/glslang/src/ndk_test/Android.mk"
174   "third_party/vulkan-deps/spirv-tools/src/Android.mk"
175   "third_party/vulkan-deps/spirv-tools/src/android_test/Android.mk"
176)
177
178for removal_file in "${extra_removal_files[@]}"; do
179   rm -f "$removal_file"
180done
181
182# Add all changes to third_party/ so we delete everything not explicitly allowed.
183git add -f "third_party/*"
184
185# Done with depot_tools
186rm -rf $DEPOT_TOOLS_DIR
187