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
19set -e
20
21ANDROIDBUILDDIR=$PWD
22BUILDDIR=$ANDROIDBUILDDIR/..
23BASEDIR=$BUILDDIR/third_party
24SHADERCTHIRDPARTY=$BASEDIR/shaderc/third_party
25
26GLSLANG_REVISION=$(cat $ANDROIDBUILDDIR/glslang_revision_android)
27SPIRV_TOOLS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-tools_revision_android)
28SPIRV_HEADERS_REVISION=$(cat $ANDROIDBUILDDIR/spirv-headers_revision_android)
29SHADERC_REVISION=$(cat $ANDROIDBUILDDIR/shaderc_revision_android)
30
31echo "GLSLANG_REVISION=$GLSLANG_REVISION"
32echo "SPIRV_TOOLS_REVISION=$SPIRV_TOOLS_REVISION"
33echo "SHADERC_REVISION=$SHADERC_REVISION"
34
35function create_glslang () {
36   rm -rf $SHADERCTHIRDPARTY/glslang
37   echo "Creating local glslang repository ($SHADERCTHIRDPARTY/glslang)."
38   mkdir -p $SHADERCTHIRDPARTY/glslang
39   cd $SHADERCTHIRDPARTY/glslang
40   git clone persistent-https://android.git.corp.google.com/platform/external/shaderc/glslang .
41   git checkout $GLSLANG_REVISION
42}
43
44function update_glslang () {
45   echo "Updating $SHADERCTHIRDPARTY/glslang"
46   cd $SHADERCTHIRDPARTY/glslang
47   git fetch --all
48   git checkout $GLSLANG_REVISION
49}
50
51function create_spirv-tools () {
52   rm -rf $SHADERCTHIRDPARTY/spirv-tools
53   echo "Creating local spirv-tools repository ($SHADERCTHIRDPARTY/spirv-tools)."
54   mkdir -p $SHADERCTHIRDPARTY/spirv-tools
55   cd $SHADERCTHIRDPARTY/spirv-tools
56   git clone persistent-https://android.git.corp.google.com/platform/external/shaderc/spirv-tools .
57   git checkout $SPIRV_TOOLS_REVISION
58}
59
60function update_spirv-tools () {
61   echo "Updating $SHADERCTHIRDPARTY/spirv-tools"
62   cd $SHADERCTHIRDPARTY/spirv-tools
63   git fetch --all
64   git checkout $SPIRV_TOOLS_REVISION
65}
66
67function create_spirv-headers () {
68   rm -rf $SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers
69   echo "Creating local spirv-headers repository ($SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers)."
70   mkdir -p $SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers
71   cd $SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers
72   git clone persistent-https://android.git.corp.google.com/platform/external/shaderc/spirv-headers .
73   git checkout $SPIRV_HEADERS_REVISION
74}
75
76function update_spirv-headers () {
77   echo "Updating $SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers"
78   cd $SHADERCTHIRDPARTY/spirv-tools/external/spirv-headers
79   git fetch --all
80   git checkout $SPIRV_HEADERS_REVISION
81}
82
83function create_shaderc () {
84   rm -rf $BASEDIR/shaderc
85   echo "Creating local shaderc repository ($BASEDIR/shaderc)."
86   mkdir -p $BASEDIR
87   cd $BASEDIR
88   git clone persistent-https://android.git.corp.google.com/platform/external/shaderc/shaderc
89   cd shaderc
90   git checkout $SHADERC_REVISION
91}
92
93function update_shaderc () {
94   echo "Updating $BASEDIR/shaderc"
95   cd $BASEDIR/shaderc
96   git fetch --all
97   git checkout $SHADERC_REVISION
98}
99
100function build_shaderc () {
101   echo "Building $BASEDIR/shaderc"
102   cd $BASEDIR/shaderc/android_test
103   ndk-build -j 4
104}
105
106# Must be first since it provides folder that hosts
107# glslang and spirv-headers
108if [ ! -d "$BASEDIR/shaderc" -o ! -d "$BASEDIR/shaderc/.git" ]; then
109     create_shaderc
110fi
111
112update_shaderc
113if [ ! -d "$BASEDIR/glslang" -o ! -d "$BASEDIR/glslang/.git" -o -d "$BASEDIR/glslang/.svn" ]; then
114   create_glslang
115fi
116 update_glslang
117
118if [ ! -d "$BASEDIR/spirv-tools" -o ! -d "$BASEDIR/spirv-tools/.git" ]; then
119   create_spirv-tools
120fi
121update_spirv-tools
122
123if [ ! -d "$BASEDIR/spirv-tools/external/spirv-headers" -o ! -d "$BASEDIR/spirv-tools/external/spirv-headers/.git" ]; then
124   create_spirv-headers
125fi
126update_spirv-headers
127
128build_shaderc
129
130echo ""
131echo "${0##*/} finished."
132
133