Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Update source for glslang, spirv-tools, shaderc |
| 3 | |
| 4 | # Copyright 2016 The Android Open Source Project |
| 5 | # Copyright (C) 2015 Valve Corporation |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | |
| 19 | set -e |
| 20 | |
| 21 | ANDROIDBUILDDIR=$PWD |
Cody Northrop | 544a42e | 2016-11-03 14:44:55 -0600 | [diff] [blame] | 22 | BUILDDIR=$ANDROIDBUILDDIR |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 23 | BASEDIR=$BUILDDIR/third_party |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 24 | |
Cody Northrop | 4bf55d7 | 2016-03-31 16:33:00 -0600 | [diff] [blame] | 25 | GLSLANG_REVISION=$(cat $ANDROIDBUILDDIR/glslang_revision_android) |
| 26 | SPIRV_TOOLS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-tools_revision_android) |
Cody Northrop | 83ff93f | 2016-08-01 10:27:25 -0600 | [diff] [blame] | 27 | SPIRV_HEADERS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-headers_revision_android) |
Cody Northrop | 4bf55d7 | 2016-03-31 16:33:00 -0600 | [diff] [blame] | 28 | SHADERC_REVISION=$(cat $ANDROIDBUILDDIR/shaderc_revision_android) |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 29 | |
| 30 | echo "GLSLANG_REVISION=$GLSLANG_REVISION" |
| 31 | echo "SPIRV_TOOLS_REVISION=$SPIRV_TOOLS_REVISION" |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 32 | echo "SPIRV_HEADERS_REVISION=$SPIRV_HEADERS_REVISION" |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 33 | echo "SHADERC_REVISION=$SHADERC_REVISION" |
| 34 | |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 35 | GLSLANG_URL=$(cat $ANDROIDBUILDDIR/glslang_url_android) |
| 36 | SPIRV_TOOLS_URL=$(cat $ANDROIDBUILDDIR/spirv-tools_url_android) |
| 37 | SPIRV_HEADERS_URL=$(cat $ANDROIDBUILDDIR/spirv-headers_url_android) |
| 38 | SHADERC_URL=$(cat $ANDROIDBUILDDIR/shaderc_url_android) |
| 39 | |
| 40 | echo "GLSLANG_URL=$GLSLANG_URL" |
| 41 | echo "SPIRV_TOOL_URLS_=$SPIRV_TOOLS_URL" |
| 42 | echo "SPIRV_HEADERS_URL=$SPIRV_HEADERS_URL" |
| 43 | echo "SHADERC_URL=$SHADERC_URL" |
| 44 | |
Cody Northrop | 6e556a1 | 2016-11-03 14:35:08 -0600 | [diff] [blame] | 45 | if [[ $(uname) == "Linux" ]]; then |
Ciro Santilli | 0a05dd7 | 2017-03-07 08:00:31 +0000 | [diff] [blame] | 46 | cores="$(nproc || echo 4)" |
Cody Northrop | 6e556a1 | 2016-11-03 14:35:08 -0600 | [diff] [blame] | 47 | elif [[ $(uname) == "Darwin" ]]; then |
| 48 | cores=$(sysctl -n hw.ncpu) |
| 49 | fi |
| 50 | |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 51 | # |
| 52 | # Parse parameters |
| 53 | # |
| 54 | |
| 55 | function printUsage { |
| 56 | echo "Supported parameters are:" |
| 57 | echo " --abi <abi> (optional)" |
Cody Northrop | 51cd02a | 2017-10-12 20:44:04 -0600 | [diff] [blame] | 58 | echo " --no-build (optional)" |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 59 | echo |
| 60 | echo "i.e. ${0##*/} --abi arm64-v8a \\" |
| 61 | exit 1 |
| 62 | } |
| 63 | |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 64 | while [[ $# -gt 0 ]] |
| 65 | do |
| 66 | case $1 in |
| 67 | --abi) |
| 68 | abi="$2" |
| 69 | shift 2 |
| 70 | ;; |
Cody Northrop | 51cd02a | 2017-10-12 20:44:04 -0600 | [diff] [blame] | 71 | --no-build) |
| 72 | nobuild=1 |
| 73 | shift 1 |
| 74 | ;; |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 75 | *) |
| 76 | # unknown option |
| 77 | echo Unknown option: $1 |
| 78 | echo |
| 79 | printUsage |
| 80 | exit 1 |
| 81 | ;; |
| 82 | esac |
| 83 | done |
| 84 | |
| 85 | echo abi=$abi |
| 86 | if [[ -z $abi ]] |
| 87 | then |
| 88 | echo No abi provided, so building for all supported abis. |
| 89 | fi |
| 90 | |
Cody Northrop | 51cd02a | 2017-10-12 20:44:04 -0600 | [diff] [blame] | 91 | echo no-build=$nobuild |
| 92 | if [[ $nobuild ]] |
| 93 | then |
| 94 | echo Skipping build. |
| 95 | fi |
| 96 | |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 97 | function create_glslang () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 98 | rm -rf $BASEDIR/shaderc/third_party/glslang |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 99 | echo "Creating local glslang repository ($BASEDIR/glslang)." |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 100 | mkdir -p $BASEDIR/shaderc/third_party/glslang |
| 101 | cd $BASEDIR/shaderc/third_party/glslang |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 102 | git clone $GLSLANG_URL . |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 103 | git checkout $GLSLANG_REVISION |
| 104 | } |
| 105 | |
| 106 | function update_glslang () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 107 | echo "Updating $BASEDIR/shaderc/third_party/glslang" |
| 108 | cd $BASEDIR/shaderc/third_party/glslang |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 109 | if [[ $(git config --get remote.origin.url) != $GLSLANG_URL ]]; then |
| 110 | echo "glslang URL mismatch, recreating local repo" |
| 111 | create_glslang |
| 112 | return |
| 113 | fi |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 114 | git fetch --all |
| 115 | git checkout $GLSLANG_REVISION |
| 116 | } |
| 117 | |
| 118 | function create_spirv-tools () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 119 | rm -rf $BASEDIR/shaderc/third_party/spirv-tools |
| 120 | echo "Creating local spirv-tools repository ($BASEDIR/shaderc/third_party/spirv-tools)." |
| 121 | mkdir -p $BASEDIR/shaderc/third_party/spirv-tools |
| 122 | cd $BASEDIR/shaderc/third_party/spirv-tools |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 123 | git clone $SPIRV_TOOLS_URL . |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 124 | git checkout $SPIRV_TOOLS_REVISION |
| 125 | } |
| 126 | |
| 127 | function update_spirv-tools () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 128 | echo "Updating $BASEDIR/shaderc/third_party/spirv-tools" |
| 129 | cd $BASEDIR/shaderc/third_party/spirv-tools |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 130 | if [[ $(git config --get remote.origin.url) != $SPIRV_TOOLS_URL ]]; then |
| 131 | echo "spirv-tools URL mismatch, recreating local repo" |
| 132 | create_spirv-tools |
| 133 | return |
| 134 | fi |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 135 | git fetch --all |
| 136 | git checkout $SPIRV_TOOLS_REVISION |
| 137 | } |
| 138 | |
Cody Northrop | 83ff93f | 2016-08-01 10:27:25 -0600 | [diff] [blame] | 139 | function create_spirv-headers () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 140 | rm -rf $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers |
| 141 | echo "Creating local spirv-headers repository ($BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers)." |
| 142 | mkdir -p $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers |
| 143 | cd $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 144 | git clone $SPIRV_HEADERS_URL . |
Cody Northrop | 83ff93f | 2016-08-01 10:27:25 -0600 | [diff] [blame] | 145 | git checkout $SPIRV_HEADERS_REVISION |
| 146 | } |
| 147 | |
| 148 | function update_spirv-headers () { |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 149 | echo "Updating $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers" |
| 150 | cd $BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 151 | if [[ $(git config --get remote.origin.url) != $SPIRV_HEADERS_URL ]]; then |
| 152 | echo "spirv-headers URL mismatch, recreating local repo" |
| 153 | create_spirv-headers |
| 154 | return |
| 155 | fi |
Cody Northrop | 83ff93f | 2016-08-01 10:27:25 -0600 | [diff] [blame] | 156 | git fetch --all |
| 157 | git checkout $SPIRV_HEADERS_REVISION |
| 158 | } |
| 159 | |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 160 | function create_shaderc () { |
| 161 | rm -rf $BASEDIR/shaderc |
| 162 | echo "Creating local shaderc repository ($BASEDIR/shaderc)." |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 163 | mkdir -p $BASEDIR/shaderc |
| 164 | cd $BASEDIR/shaderc |
| 165 | git clone $SHADERC_URL . |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 166 | git checkout $SHADERC_REVISION |
| 167 | } |
| 168 | |
| 169 | function update_shaderc () { |
| 170 | echo "Updating $BASEDIR/shaderc" |
| 171 | cd $BASEDIR/shaderc |
Cody Northrop | 7396cb0 | 2017-03-27 16:30:14 -0600 | [diff] [blame] | 172 | if [[ $(git config --get remote.origin.url) != $SHADERC_URL ]]; then |
| 173 | echo "shaderc URL mismatch, recreating local repo" |
| 174 | create_shaderc |
| 175 | return |
| 176 | fi |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 177 | git fetch --all |
| 178 | git checkout $SHADERC_REVISION |
| 179 | } |
| 180 | |
| 181 | function build_shaderc () { |
| 182 | echo "Building $BASEDIR/shaderc" |
| 183 | cd $BASEDIR/shaderc/android_test |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 184 | if [[ $abi ]]; then |
Cody Northrop | aa83e7f | 2017-12-17 22:05:31 -0700 | [diff] [blame] | 185 | ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party APP_ABI=$abi -j $cores; |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 186 | else |
Cody Northrop | aa83e7f | 2017-12-17 22:05:31 -0700 | [diff] [blame] | 187 | ndk-build NDK_APPLICATION_MK=../../../jni/shaderc/Application.mk THIRD_PARTY_PATH=../third_party -j $cores; |
Cody Northrop | 749c6cc | 2017-09-29 15:34:45 -0600 | [diff] [blame] | 188 | fi |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 191 | if [ ! -d "$BASEDIR/shaderc" -o ! -d "$BASEDIR/shaderc/.git" ]; then |
| 192 | create_shaderc |
| 193 | fi |
| 194 | update_shaderc |
Mike Stroyan | f799518 | 2017-10-06 11:05:21 -0600 | [diff] [blame] | 195 | |
| 196 | if [ ! -d "$BASEDIR/shaderc/third_party/glslang" -o ! -d "$BASEDIR/shaderc/third_party/glslang/.git" -o -d "$BASEDIR/shaderc/third_party/glslang/.svn" ]; then |
| 197 | create_glslang |
| 198 | fi |
| 199 | update_glslang |
| 200 | |
| 201 | if [ ! -d "$BASEDIR/shaderc/third_party/spirv-tools" -o ! -d "$BASEDIR/shaderc/third_party/spirv-tools/.git" ]; then |
| 202 | create_spirv-tools |
| 203 | fi |
| 204 | update_spirv-tools |
| 205 | |
| 206 | if [ ! -d "$BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers" -o ! -d "$BASEDIR/shaderc/third_party/spirv-tools/external/spirv-headers/.git" ]; then |
| 207 | create_spirv-headers |
| 208 | fi |
| 209 | update_spirv-headers |
| 210 | |
Cody Northrop | 51cd02a | 2017-10-12 20:44:04 -0600 | [diff] [blame] | 211 | if [[ -z $nobuild ]] |
| 212 | then |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 213 | build_shaderc |
Cody Northrop | 51cd02a | 2017-10-12 20:44:04 -0600 | [diff] [blame] | 214 | fi |
Cody Northrop | b3106db | 2016-03-29 10:06:49 -0600 | [diff] [blame] | 215 | |
| 216 | echo "" |
| 217 | echo "${0##*/} finished." |
| 218 | |