xref: /aosp_15_r20/external/angle/scripts/roll_aosp.sh (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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            # TODO(b/279980674): re-enable end2end tests
83            "build_angle_end2end_tests_aosp = true"
84            "build_angle_trace_tests = false"
85            "angle_test_enable_system_egl = true"
86        )
87
88        if [[ "$1" == "--enableApiTrace" ]]; then
89            gn_args=(
90                "${gn_args[@]}"
91                "angle_enable_trace = true"
92                "angle_enable_trace_android_logcat = true"
93            )
94        fi
95
96        gn gen ${GN_OUTPUT_DIRECTORY} --args="${gn_args[*]}"
97        gn desc ${GN_OUTPUT_DIRECTORY} --format=json "*" > ${GN_OUTPUT_DIRECTORY}/desc.$abi.json
98    done
99
100    python3 scripts/generate_android_bp.py \
101        --gn_json_arm=${GN_OUTPUT_DIRECTORY}/desc.arm.json \
102        --gn_json_arm64=${GN_OUTPUT_DIRECTORY}/desc.arm64.json \
103        --gn_json_x86=${GN_OUTPUT_DIRECTORY}/desc.x86.json \
104        --gn_json_x64=${GN_OUTPUT_DIRECTORY}/desc.x64.json \
105        --output=Android.bp
106}
107
108function generate_angle_commit_file() {
109    # Output chromium ANGLE git hash during ANGLE to Android roll into
110    # {AndroidANGLERoot}/angle_commit.h.
111    # In Android repos, we stop generating the angle_commit.h at compile time,
112    # because in Android repos, access to .git is not guaranteed, running
113    # commit_id.py at compile time will generate "unknown hash" for ANGLE_COMMIT_HASH.
114    # Instead, we generate angle_commit.h during ANGLE to Android roll time.
115    # Before roll_aosp.sh is called during the roll, ANGLE_UPSTREAM_HASH environment
116    # variable is set to {rolling_to} git hash, and that can be used by below
117    # script commit_id.py as the ANGLE_COMMIT_HASH written to the angle_commit.h.
118    # See b/348044346.
119    python3 src/commit_id.py \
120        gen \
121        angle_commit.h
122}
123
124if [[ "$1" == "--genAndroidBp" ]];then
125    generate_Android_bp_file "$2"
126    exit 0
127fi
128
129# Check out depot_tools locally and add it to the path
130DEPOT_TOOLS_DIR=_depot_tools
131rm -rf ${DEPOT_TOOLS_DIR}
132git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ${DEPOT_TOOLS_DIR}
133export PATH=`pwd`/${DEPOT_TOOLS_DIR}:$PATH
134
135
136# This script is executed by the Skia roller in *AOSP* checkout (with new ANGLE changes merged into it by git merge).
137# The Skia roller merges ANGLE changes and also has code to remove submodules and extra files.
138# For local setup including the additional Skia roller actions see go/angle-skia-roller-local
139#
140# Some caveats due to the way this is set up:
141# * If a file is deleted from AOSP by a previous commit to AOSP *and* is changed upstream in ANGLE,
142#   git merge will fail in Skia roller before even reaching this script. This sometimes happens with e.g. .gitmodules
143#
144# * If a file is needed to run gn gen (commonly BUILD.gn) it might need to take a different path:
145#
146#   * If this file comes from ANGLE, it is already git-merged into AOSP by Skia roller by the time we get to this script
147#      - example: ANGLE source files, but also e.g. third_party/jdk/BUILD.gn (see note below)
148#
149#   * If this file comes from a third_party dep (pulled by gclient in generate_Android_bp_file), it is either:
150#      1. deleted after the codegen ensuring it is *not* in AOSP (delete_after_codegen_paths)
151#      2. automatically ignored due to it being part of a sub-repo not this repo (.git subdirs in git deps but not cipd)
152#      3. copied to AOSP intentionally by this script (copy_to_aosp_paths, which deletes .git subdirs to avoid the case 2)
153#      4. copied to AOSP implicitly, without being in copy_to_aosp_paths:
154#         - dep does not have a .git subdir (dep_type cipd in DEPS)
155#         - not listed in delete_after_codegen_paths
156#         - example: files under third_party/r8
157#
158#   Note: a file being under third_party/ does *not* necessarily imply it comes from a dep. For example third_party/jdk/BUILD.gn
159#         comes from the ANGLE repo, not from the upstream Chromium third_pary/jdk repo.. but it can be different in other cases.
160#         In cases like third_party/jdk/BUILD.gn, we need to make sure it is *not* part of delete_after_codegen_paths as
161#         this script would delete this file from AOSP after one roll and the next roll would fail gn gen.
162
163# Deps copied to AOSP by having .git removed from them then git add (via git_add_paths)
164# .git removed so that it's not an "embedded repository" https://gist.github.com/claraj/e5563befe6c2fb108ad0efb6de47f265
165copy_to_aosp_paths=(
166    "build"
167    "third_party/abseil-cpp"
168    "third_party/glslang/src"
169    "third_party/spirv-headers/src"
170    "third_party/spirv-tools/src"
171    "third_party/vulkan-headers/src"
172    "third_party/vulkan_memory_allocator"
173)
174
175# Dirs and files deleted after codegen so that they don't get added to AOSP.
176# We don't need this for dirs with .git in them as those are already ignored by git.
177delete_after_codegen_paths=(
178   "third_party/android_build_tools"
179   "third_party/android_sdk"
180   "third_party/android_toolchain"
181   "third_party/jdk/current"  # subdirs only to keep third_party/jdk/BUILD.gn (not pulled by gclient as it comes from ANGLE repo)
182   "third_party/jdk/extras"
183   "third_party/llvm-build"
184   "third_party/rust"
185   "third_party/rust-toolchain"
186   "third_party/zlib"  # Replaced by Android's zlib
187
188   # build/linux is hundreds of megs that aren't needed.
189   "build/linux"
190   # Debuggable APKs cannot be merged into AOSP as a prebuilt
191   "build/android/CheckInstallApk-debug.apk"
192   # Remove Android.mk files to prevent automated CLs:
193   #   "[LSC] Add LOCAL_LICENSE_KINDS to external/angle"
194   "Android.mk"
195   "third_party/glslang/src/Android.mk"
196   "third_party/glslang/src/ndk_test/Android.mk"
197   "third_party/spirv-tools/src/Android.mk"
198   "third_party/spirv-tools/src/android_test/Android.mk"
199   "third_party/siso" # Not needed
200)
201
202# Dirs added to the commit with `git add -f`. Applies to both copy_to_aosp_paths and delete_after_codegen_paths.
203git_add_paths=(
204  "build"
205  "third_party"
206)
207
208
209# Delete first to get a clean checkout by gclient
210for path in "${copy_to_aosp_paths[@]}"; do
211    rm -rf "$path"
212done
213
214# Remove cruft from any previous bad rolls (https://anglebug.com/42266781)
215find third_party -wholename "*/_gclient_*" -delete
216
217# Workaround to avoid gclient errors https://crbug.com/skia/14155#c3
218rm -rf "third_party/zlib"
219
220# Sync all of ANGLE's deps so that 'gn gen' works
221python3 scripts/bootstrap.py
222gclient sync --reset --force --delete_unversioned_trees
223
224# Delete outdir to ensure a clean gn run.
225rm -rf ${GN_OUTPUT_DIRECTORY}
226
227generate_Android_bp_file
228git add Android.bp
229
230generate_angle_commit_file
231git add angle_commit.h
232
233# Delete outdir to cleanup after gn.
234rm -rf ${GN_OUTPUT_DIRECTORY}
235
236# Delete files that we do not want in AOSP.
237# Some of them are needed for codegen so this happens after generate_Android_bp_file.
238for path in "${delete_after_codegen_paths[@]}"; do
239   rm -rf "$path"
240done
241
242# Delete the .git files in each dep so that it can be copied to this repo. Some deps like jsoncpp
243# have multiple layers of deps so delete everything before adding them.
244for dep in "${copy_to_aosp_paths[@]}"; do
245   rm -rf "$dep"/.git
246done
247
248# Delete all the .gitmodules files, since they are not allowed in AOSP external projects.
249find . -name \.gitmodules -exec rm {} \;
250
251# Add all changes under git_add_paths to sync changes (including deletion) in those dirs to AOSP.
252for path in "${git_add_paths[@]}"; do
253    git add -f $path
254done
255
256# Done with depot_tools
257rm -rf $DEPOT_TOOLS_DIR
258