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