1*8975f5c5SAndroid Build Coastguard Worker#!/bin/bash 2*8975f5c5SAndroid Build Coastguard Worker 3*8975f5c5SAndroid Build Coastguard Worker# Copyright The ANGLE Project Authors. All rights reserved. 4*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 5*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 6*8975f5c5SAndroid Build Coastguard Worker# 7*8975f5c5SAndroid Build Coastguard Worker# Generates a roll CL within the ANGLE repository of AOSP. 8*8975f5c5SAndroid Build Coastguard Worker# 9*8975f5c5SAndroid Build Coastguard Worker# WARNING: Running this script without args may mess up the checkout. 10*8975f5c5SAndroid Build Coastguard Worker# See --genAndroidBp for testing just the code generation. 11*8975f5c5SAndroid Build Coastguard Worker 12*8975f5c5SAndroid Build Coastguard Worker# exit when any command fails 13*8975f5c5SAndroid Build Coastguard Workerset -eE -o functrace 14*8975f5c5SAndroid Build Coastguard Worker 15*8975f5c5SAndroid Build Coastguard Workerfailure() { 16*8975f5c5SAndroid Build Coastguard Worker local lineno=$1 17*8975f5c5SAndroid Build Coastguard Worker local msg=$2 18*8975f5c5SAndroid Build Coastguard Worker echo "Failed at $lineno: $msg" 19*8975f5c5SAndroid Build Coastguard Worker} 20*8975f5c5SAndroid Build Coastguard Workertrap 'failure ${LINENO} "$BASH_COMMAND"' ERR 21*8975f5c5SAndroid Build Coastguard Worker 22*8975f5c5SAndroid Build Coastguard Worker# Change the working directory to the ANGLE root directory 23*8975f5c5SAndroid Build Coastguard Workercd "${0%/*}/.." 24*8975f5c5SAndroid Build Coastguard Worker 25*8975f5c5SAndroid Build Coastguard WorkerGN_OUTPUT_DIRECTORY=out/Android 26*8975f5c5SAndroid Build Coastguard Worker 27*8975f5c5SAndroid Build Coastguard Workerfunction generate_Android_bp_file() { 28*8975f5c5SAndroid Build Coastguard Worker abis=( 29*8975f5c5SAndroid Build Coastguard Worker "arm" 30*8975f5c5SAndroid Build Coastguard Worker "arm64" 31*8975f5c5SAndroid Build Coastguard Worker "x86" 32*8975f5c5SAndroid Build Coastguard Worker "x64" 33*8975f5c5SAndroid Build Coastguard Worker ) 34*8975f5c5SAndroid Build Coastguard Worker 35*8975f5c5SAndroid Build Coastguard Worker for abi in "${abis[@]}"; do 36*8975f5c5SAndroid Build Coastguard Worker # generate gn build files and convert them to blueprints 37*8975f5c5SAndroid Build Coastguard Worker gn_args=( 38*8975f5c5SAndroid Build Coastguard Worker "target_os = \"android\"" 39*8975f5c5SAndroid Build Coastguard Worker "is_component_build = false" 40*8975f5c5SAndroid Build Coastguard Worker "is_debug = false" 41*8975f5c5SAndroid Build Coastguard Worker "dcheck_always_on = false" 42*8975f5c5SAndroid Build Coastguard Worker "symbol_level = 0" 43*8975f5c5SAndroid Build Coastguard Worker "angle_standalone = false" 44*8975f5c5SAndroid Build Coastguard Worker "angle_build_all = false" 45*8975f5c5SAndroid Build Coastguard Worker "angle_expose_non_conformant_extensions_and_versions = true" 46*8975f5c5SAndroid Build Coastguard Worker 47*8975f5c5SAndroid Build Coastguard Worker # Build for 64-bit CPUs 48*8975f5c5SAndroid Build Coastguard Worker "target_cpu = \"$abi\"" 49*8975f5c5SAndroid Build Coastguard Worker 50*8975f5c5SAndroid Build Coastguard Worker # Target ndk API 26 to make sure ANGLE can use the Vulkan backend on Android 51*8975f5c5SAndroid Build Coastguard Worker "android32_ndk_api_level = 26" 52*8975f5c5SAndroid Build Coastguard Worker "android64_ndk_api_level = 26" 53*8975f5c5SAndroid Build Coastguard Worker 54*8975f5c5SAndroid Build Coastguard Worker # Disable all backends except Vulkan 55*8975f5c5SAndroid Build Coastguard Worker "angle_enable_vulkan = true" 56*8975f5c5SAndroid Build Coastguard Worker "angle_enable_gl = false" 57*8975f5c5SAndroid Build Coastguard Worker "angle_enable_d3d9 = false" 58*8975f5c5SAndroid Build Coastguard Worker "angle_enable_d3d11 = false" 59*8975f5c5SAndroid Build Coastguard Worker "angle_enable_null = false" 60*8975f5c5SAndroid Build Coastguard Worker "angle_enable_metal = false" 61*8975f5c5SAndroid Build Coastguard Worker "angle_enable_wgpu = false" 62*8975f5c5SAndroid Build Coastguard Worker 63*8975f5c5SAndroid Build Coastguard Worker # SwiftShader is loaded as the system Vulkan driver on Android, not compiled by ANGLE 64*8975f5c5SAndroid Build Coastguard Worker "angle_enable_swiftshader = false" 65*8975f5c5SAndroid Build Coastguard Worker 66*8975f5c5SAndroid Build Coastguard Worker # Disable all shader translator targets except desktop GL (for Vulkan) 67*8975f5c5SAndroid Build Coastguard Worker "angle_enable_essl = false" 68*8975f5c5SAndroid Build Coastguard Worker "angle_enable_glsl = false" 69*8975f5c5SAndroid Build Coastguard Worker "angle_enable_hlsl = false" 70*8975f5c5SAndroid Build Coastguard Worker 71*8975f5c5SAndroid Build Coastguard Worker "angle_enable_commit_id = false" 72*8975f5c5SAndroid Build Coastguard Worker 73*8975f5c5SAndroid Build Coastguard Worker # Disable histogram/protobuf support 74*8975f5c5SAndroid Build Coastguard Worker "angle_has_histograms = false" 75*8975f5c5SAndroid Build Coastguard Worker 76*8975f5c5SAndroid Build Coastguard Worker # Use system lib(std)c++, since the Chromium library breaks std::string 77*8975f5c5SAndroid Build Coastguard Worker "use_custom_libcxx = false" 78*8975f5c5SAndroid Build Coastguard Worker 79*8975f5c5SAndroid Build Coastguard Worker # rapidJSON is used for ANGLE's frame capture (among other things), which is unnecessary for AOSP builds. 80*8975f5c5SAndroid Build Coastguard Worker "angle_has_rapidjson = false" 81*8975f5c5SAndroid Build Coastguard Worker 82*8975f5c5SAndroid Build Coastguard Worker # TODO(b/279980674): re-enable end2end tests 83*8975f5c5SAndroid Build Coastguard Worker "build_angle_end2end_tests_aosp = true" 84*8975f5c5SAndroid Build Coastguard Worker "build_angle_trace_tests = false" 85*8975f5c5SAndroid Build Coastguard Worker "angle_test_enable_system_egl = true" 86*8975f5c5SAndroid Build Coastguard Worker ) 87*8975f5c5SAndroid Build Coastguard Worker 88*8975f5c5SAndroid Build Coastguard Worker if [[ "$1" == "--enableApiTrace" ]]; then 89*8975f5c5SAndroid Build Coastguard Worker gn_args=( 90*8975f5c5SAndroid Build Coastguard Worker "${gn_args[@]}" 91*8975f5c5SAndroid Build Coastguard Worker "angle_enable_trace = true" 92*8975f5c5SAndroid Build Coastguard Worker "angle_enable_trace_android_logcat = true" 93*8975f5c5SAndroid Build Coastguard Worker ) 94*8975f5c5SAndroid Build Coastguard Worker fi 95*8975f5c5SAndroid Build Coastguard Worker 96*8975f5c5SAndroid Build Coastguard Worker gn gen ${GN_OUTPUT_DIRECTORY} --args="${gn_args[*]}" 97*8975f5c5SAndroid Build Coastguard Worker gn desc ${GN_OUTPUT_DIRECTORY} --format=json "*" > ${GN_OUTPUT_DIRECTORY}/desc.$abi.json 98*8975f5c5SAndroid Build Coastguard Worker done 99*8975f5c5SAndroid Build Coastguard Worker 100*8975f5c5SAndroid Build Coastguard Worker python3 scripts/generate_android_bp.py \ 101*8975f5c5SAndroid Build Coastguard Worker --gn_json_arm=${GN_OUTPUT_DIRECTORY}/desc.arm.json \ 102*8975f5c5SAndroid Build Coastguard Worker --gn_json_arm64=${GN_OUTPUT_DIRECTORY}/desc.arm64.json \ 103*8975f5c5SAndroid Build Coastguard Worker --gn_json_x86=${GN_OUTPUT_DIRECTORY}/desc.x86.json \ 104*8975f5c5SAndroid Build Coastguard Worker --gn_json_x64=${GN_OUTPUT_DIRECTORY}/desc.x64.json \ 105*8975f5c5SAndroid Build Coastguard Worker --output=Android.bp 106*8975f5c5SAndroid Build Coastguard Worker} 107*8975f5c5SAndroid Build Coastguard Worker 108*8975f5c5SAndroid Build Coastguard Workerfunction generate_angle_commit_file() { 109*8975f5c5SAndroid Build Coastguard Worker # Output chromium ANGLE git hash during ANGLE to Android roll into 110*8975f5c5SAndroid Build Coastguard Worker # {AndroidANGLERoot}/angle_commit.h. 111*8975f5c5SAndroid Build Coastguard Worker # In Android repos, we stop generating the angle_commit.h at compile time, 112*8975f5c5SAndroid Build Coastguard Worker # because in Android repos, access to .git is not guaranteed, running 113*8975f5c5SAndroid Build Coastguard Worker # commit_id.py at compile time will generate "unknown hash" for ANGLE_COMMIT_HASH. 114*8975f5c5SAndroid Build Coastguard Worker # Instead, we generate angle_commit.h during ANGLE to Android roll time. 115*8975f5c5SAndroid Build Coastguard Worker # Before roll_aosp.sh is called during the roll, ANGLE_UPSTREAM_HASH environment 116*8975f5c5SAndroid Build Coastguard Worker # variable is set to {rolling_to} git hash, and that can be used by below 117*8975f5c5SAndroid Build Coastguard Worker # script commit_id.py as the ANGLE_COMMIT_HASH written to the angle_commit.h. 118*8975f5c5SAndroid Build Coastguard Worker # See b/348044346. 119*8975f5c5SAndroid Build Coastguard Worker python3 src/commit_id.py \ 120*8975f5c5SAndroid Build Coastguard Worker gen \ 121*8975f5c5SAndroid Build Coastguard Worker angle_commit.h 122*8975f5c5SAndroid Build Coastguard Worker} 123*8975f5c5SAndroid Build Coastguard Worker 124*8975f5c5SAndroid Build Coastguard Workerif [[ "$1" == "--genAndroidBp" ]];then 125*8975f5c5SAndroid Build Coastguard Worker generate_Android_bp_file "$2" 126*8975f5c5SAndroid Build Coastguard Worker exit 0 127*8975f5c5SAndroid Build Coastguard Workerfi 128*8975f5c5SAndroid Build Coastguard Worker 129*8975f5c5SAndroid Build Coastguard Worker# Check out depot_tools locally and add it to the path 130*8975f5c5SAndroid Build Coastguard WorkerDEPOT_TOOLS_DIR=_depot_tools 131*8975f5c5SAndroid Build Coastguard Workerrm -rf ${DEPOT_TOOLS_DIR} 132*8975f5c5SAndroid Build Coastguard Workergit clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ${DEPOT_TOOLS_DIR} 133*8975f5c5SAndroid Build Coastguard Workerexport PATH=`pwd`/${DEPOT_TOOLS_DIR}:$PATH 134*8975f5c5SAndroid Build Coastguard Worker 135*8975f5c5SAndroid Build Coastguard Worker 136*8975f5c5SAndroid Build Coastguard Worker# This script is executed by the Skia roller in *AOSP* checkout (with new ANGLE changes merged into it by git merge). 137*8975f5c5SAndroid Build Coastguard Worker# The Skia roller merges ANGLE changes and also has code to remove submodules and extra files. 138*8975f5c5SAndroid Build Coastguard Worker# For local setup including the additional Skia roller actions see go/angle-skia-roller-local 139*8975f5c5SAndroid Build Coastguard Worker# 140*8975f5c5SAndroid Build Coastguard Worker# Some caveats due to the way this is set up: 141*8975f5c5SAndroid Build Coastguard Worker# * If a file is deleted from AOSP by a previous commit to AOSP *and* is changed upstream in ANGLE, 142*8975f5c5SAndroid Build Coastguard Worker# git merge will fail in Skia roller before even reaching this script. This sometimes happens with e.g. .gitmodules 143*8975f5c5SAndroid Build Coastguard Worker# 144*8975f5c5SAndroid Build Coastguard Worker# * If a file is needed to run gn gen (commonly BUILD.gn) it might need to take a different path: 145*8975f5c5SAndroid Build Coastguard Worker# 146*8975f5c5SAndroid Build Coastguard Worker# * 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*8975f5c5SAndroid Build Coastguard Worker# - example: ANGLE source files, but also e.g. third_party/jdk/BUILD.gn (see note below) 148*8975f5c5SAndroid Build Coastguard Worker# 149*8975f5c5SAndroid Build Coastguard Worker# * If this file comes from a third_party dep (pulled by gclient in generate_Android_bp_file), it is either: 150*8975f5c5SAndroid Build Coastguard Worker# 1. deleted after the codegen ensuring it is *not* in AOSP (delete_after_codegen_paths) 151*8975f5c5SAndroid Build Coastguard Worker# 2. automatically ignored due to it being part of a sub-repo not this repo (.git subdirs in git deps but not cipd) 152*8975f5c5SAndroid Build Coastguard Worker# 3. copied to AOSP intentionally by this script (copy_to_aosp_paths, which deletes .git subdirs to avoid the case 2) 153*8975f5c5SAndroid Build Coastguard Worker# 4. copied to AOSP implicitly, without being in copy_to_aosp_paths: 154*8975f5c5SAndroid Build Coastguard Worker# - dep does not have a .git subdir (dep_type cipd in DEPS) 155*8975f5c5SAndroid Build Coastguard Worker# - not listed in delete_after_codegen_paths 156*8975f5c5SAndroid Build Coastguard Worker# - example: files under third_party/r8 157*8975f5c5SAndroid Build Coastguard Worker# 158*8975f5c5SAndroid Build Coastguard Worker# Note: a file being under third_party/ does *not* necessarily imply it comes from a dep. For example third_party/jdk/BUILD.gn 159*8975f5c5SAndroid Build Coastguard Worker# comes from the ANGLE repo, not from the upstream Chromium third_pary/jdk repo.. but it can be different in other cases. 160*8975f5c5SAndroid Build Coastguard Worker# In cases like third_party/jdk/BUILD.gn, we need to make sure it is *not* part of delete_after_codegen_paths as 161*8975f5c5SAndroid Build Coastguard Worker# this script would delete this file from AOSP after one roll and the next roll would fail gn gen. 162*8975f5c5SAndroid Build Coastguard Worker 163*8975f5c5SAndroid Build Coastguard Worker# Deps copied to AOSP by having .git removed from them then git add (via git_add_paths) 164*8975f5c5SAndroid Build Coastguard Worker# .git removed so that it's not an "embedded repository" https://gist.github.com/claraj/e5563befe6c2fb108ad0efb6de47f265 165*8975f5c5SAndroid Build Coastguard Workercopy_to_aosp_paths=( 166*8975f5c5SAndroid Build Coastguard Worker "build" 167*8975f5c5SAndroid Build Coastguard Worker "third_party/abseil-cpp" 168*8975f5c5SAndroid Build Coastguard Worker "third_party/glslang/src" 169*8975f5c5SAndroid Build Coastguard Worker "third_party/spirv-headers/src" 170*8975f5c5SAndroid Build Coastguard Worker "third_party/spirv-tools/src" 171*8975f5c5SAndroid Build Coastguard Worker "third_party/vulkan-headers/src" 172*8975f5c5SAndroid Build Coastguard Worker "third_party/vulkan_memory_allocator" 173*8975f5c5SAndroid Build Coastguard Worker) 174*8975f5c5SAndroid Build Coastguard Worker 175*8975f5c5SAndroid Build Coastguard Worker# Dirs and files deleted after codegen so that they don't get added to AOSP. 176*8975f5c5SAndroid Build Coastguard Worker# We don't need this for dirs with .git in them as those are already ignored by git. 177*8975f5c5SAndroid Build Coastguard Workerdelete_after_codegen_paths=( 178*8975f5c5SAndroid Build Coastguard Worker "third_party/android_build_tools" 179*8975f5c5SAndroid Build Coastguard Worker "third_party/android_sdk" 180*8975f5c5SAndroid Build Coastguard Worker "third_party/android_toolchain" 181*8975f5c5SAndroid Build Coastguard Worker "third_party/jdk/current" # subdirs only to keep third_party/jdk/BUILD.gn (not pulled by gclient as it comes from ANGLE repo) 182*8975f5c5SAndroid Build Coastguard Worker "third_party/jdk/extras" 183*8975f5c5SAndroid Build Coastguard Worker "third_party/llvm-build" 184*8975f5c5SAndroid Build Coastguard Worker "third_party/rust" 185*8975f5c5SAndroid Build Coastguard Worker "third_party/rust-toolchain" 186*8975f5c5SAndroid Build Coastguard Worker "third_party/zlib" # Replaced by Android's zlib 187*8975f5c5SAndroid Build Coastguard Worker 188*8975f5c5SAndroid Build Coastguard Worker # build/linux is hundreds of megs that aren't needed. 189*8975f5c5SAndroid Build Coastguard Worker "build/linux" 190*8975f5c5SAndroid Build Coastguard Worker # Debuggable APKs cannot be merged into AOSP as a prebuilt 191*8975f5c5SAndroid Build Coastguard Worker "build/android/CheckInstallApk-debug.apk" 192*8975f5c5SAndroid Build Coastguard Worker # Remove Android.mk files to prevent automated CLs: 193*8975f5c5SAndroid Build Coastguard Worker # "[LSC] Add LOCAL_LICENSE_KINDS to external/angle" 194*8975f5c5SAndroid Build Coastguard Worker "Android.mk" 195*8975f5c5SAndroid Build Coastguard Worker "third_party/glslang/src/Android.mk" 196*8975f5c5SAndroid Build Coastguard Worker "third_party/glslang/src/ndk_test/Android.mk" 197*8975f5c5SAndroid Build Coastguard Worker "third_party/spirv-tools/src/Android.mk" 198*8975f5c5SAndroid Build Coastguard Worker "third_party/spirv-tools/src/android_test/Android.mk" 199*8975f5c5SAndroid Build Coastguard Worker "third_party/siso" # Not needed 200*8975f5c5SAndroid Build Coastguard Worker) 201*8975f5c5SAndroid Build Coastguard Worker 202*8975f5c5SAndroid Build Coastguard Worker# Dirs added to the commit with `git add -f`. Applies to both copy_to_aosp_paths and delete_after_codegen_paths. 203*8975f5c5SAndroid Build Coastguard Workergit_add_paths=( 204*8975f5c5SAndroid Build Coastguard Worker "build" 205*8975f5c5SAndroid Build Coastguard Worker "third_party" 206*8975f5c5SAndroid Build Coastguard Worker) 207*8975f5c5SAndroid Build Coastguard Worker 208*8975f5c5SAndroid Build Coastguard Worker 209*8975f5c5SAndroid Build Coastguard Worker# Delete first to get a clean checkout by gclient 210*8975f5c5SAndroid Build Coastguard Workerfor path in "${copy_to_aosp_paths[@]}"; do 211*8975f5c5SAndroid Build Coastguard Worker rm -rf "$path" 212*8975f5c5SAndroid Build Coastguard Workerdone 213*8975f5c5SAndroid Build Coastguard Worker 214*8975f5c5SAndroid Build Coastguard Worker# Remove cruft from any previous bad rolls (https://anglebug.com/42266781) 215*8975f5c5SAndroid Build Coastguard Workerfind third_party -wholename "*/_gclient_*" -delete 216*8975f5c5SAndroid Build Coastguard Worker 217*8975f5c5SAndroid Build Coastguard Worker# Workaround to avoid gclient errors https://crbug.com/skia/14155#c3 218*8975f5c5SAndroid Build Coastguard Workerrm -rf "third_party/zlib" 219*8975f5c5SAndroid Build Coastguard Worker 220*8975f5c5SAndroid Build Coastguard Worker# Sync all of ANGLE's deps so that 'gn gen' works 221*8975f5c5SAndroid Build Coastguard Workerpython3 scripts/bootstrap.py 222*8975f5c5SAndroid Build Coastguard Workergclient sync --reset --force --delete_unversioned_trees 223*8975f5c5SAndroid Build Coastguard Worker 224*8975f5c5SAndroid Build Coastguard Worker# Delete outdir to ensure a clean gn run. 225*8975f5c5SAndroid Build Coastguard Workerrm -rf ${GN_OUTPUT_DIRECTORY} 226*8975f5c5SAndroid Build Coastguard Worker 227*8975f5c5SAndroid Build Coastguard Workergenerate_Android_bp_file 228*8975f5c5SAndroid Build Coastguard Workergit add Android.bp 229*8975f5c5SAndroid Build Coastguard Worker 230*8975f5c5SAndroid Build Coastguard Workergenerate_angle_commit_file 231*8975f5c5SAndroid Build Coastguard Workergit add angle_commit.h 232*8975f5c5SAndroid Build Coastguard Worker 233*8975f5c5SAndroid Build Coastguard Worker# Delete outdir to cleanup after gn. 234*8975f5c5SAndroid Build Coastguard Workerrm -rf ${GN_OUTPUT_DIRECTORY} 235*8975f5c5SAndroid Build Coastguard Worker 236*8975f5c5SAndroid Build Coastguard Worker# Delete files that we do not want in AOSP. 237*8975f5c5SAndroid Build Coastguard Worker# Some of them are needed for codegen so this happens after generate_Android_bp_file. 238*8975f5c5SAndroid Build Coastguard Workerfor path in "${delete_after_codegen_paths[@]}"; do 239*8975f5c5SAndroid Build Coastguard Worker rm -rf "$path" 240*8975f5c5SAndroid Build Coastguard Workerdone 241*8975f5c5SAndroid Build Coastguard Worker 242*8975f5c5SAndroid Build Coastguard Worker# Delete the .git files in each dep so that it can be copied to this repo. Some deps like jsoncpp 243*8975f5c5SAndroid Build Coastguard Worker# have multiple layers of deps so delete everything before adding them. 244*8975f5c5SAndroid Build Coastguard Workerfor dep in "${copy_to_aosp_paths[@]}"; do 245*8975f5c5SAndroid Build Coastguard Worker rm -rf "$dep"/.git 246*8975f5c5SAndroid Build Coastguard Workerdone 247*8975f5c5SAndroid Build Coastguard Worker 248*8975f5c5SAndroid Build Coastguard Worker# Delete all the .gitmodules files, since they are not allowed in AOSP external projects. 249*8975f5c5SAndroid Build Coastguard Workerfind . -name \.gitmodules -exec rm {} \; 250*8975f5c5SAndroid Build Coastguard Worker 251*8975f5c5SAndroid Build Coastguard Worker# Add all changes under git_add_paths to sync changes (including deletion) in those dirs to AOSP. 252*8975f5c5SAndroid Build Coastguard Workerfor path in "${git_add_paths[@]}"; do 253*8975f5c5SAndroid Build Coastguard Worker git add -f $path 254*8975f5c5SAndroid Build Coastguard Workerdone 255*8975f5c5SAndroid Build Coastguard Worker 256*8975f5c5SAndroid Build Coastguard Worker# Done with depot_tools 257*8975f5c5SAndroid Build Coastguard Workerrm -rf $DEPOT_TOOLS_DIR 258