1#!/usr/bin/python2 2# 3# Copyright 2019 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# update_glslang_binary.py: 8# Helper script to update the version of glslang in cloud storage. 9# This glslang is used to precompile Vulkan shaders. This script builds 10# glslang and uploads it to the bucket for Windows or Linux. It 11# currently only works on Windows and Linux. It also will update the 12# hashes stored in the tree. For more info see README.md in this folder. 13 14import os 15import platform 16import shutil 17import subprocess 18import sys 19 20sys.path.append('tools/') 21import angle_tools 22 23gn_args = """is_clang = true 24is_debug = false 25angle_enable_vulkan = true""" 26 27 28def main(): 29 if not angle_tools.is_windows and not angle_tools.is_linux: 30 print('Script must be run on Linux or Windows.') 31 return 1 32 33 # Step 1: Generate an output directory 34 out_dir = os.path.join('out', 'glslang_release') 35 36 if not os.path.isdir(out_dir): 37 os.mkdir(out_dir) 38 39 args_gn = os.path.join(out_dir, 'args.gn') 40 if not os.path.isfile(args_gn): 41 with open(args_gn, 'w') as f: 42 f.write(gn_args) 43 f.close() 44 45 gn_exe = angle_tools.get_exe_name('gn', '.bat') 46 47 # Step 2: Generate the ninja build files in the output directory 48 if subprocess.call([gn_exe, 'gen', out_dir]) != 0: 49 print('Error calling gn') 50 return 2 51 52 # Step 3: Compile glslang_validator 53 if subprocess.call(['ninja', '-C', out_dir, 'glslang_validator']) != 0: 54 print('Error calling ninja') 55 return 3 56 57 # Step 4: Copy glslang_validator to the tools/glslang directory 58 glslang_exe = angle_tools.get_exe_name('glslang_validator', '.exe') 59 60 glslang_src = os.path.join(out_dir, glslang_exe) 61 glslang_dst = os.path.join(sys.path[0], glslang_exe) 62 63 shutil.copy(glslang_src, glslang_dst) 64 65 # Step 5: Delete the build directory 66 shutil.rmtree(out_dir) 67 68 # Step 6: Upload to cloud storage 69 if not angle_tools.upload_to_google_storage('angle-glslang-validator', [glslang_dst]): 70 print('Error upload to cloud storage') 71 return 4 72 73 # Step 7: Stage new SHA to git 74 if not angle_tools.stage_google_storage_sha1([glslang_dst]): 75 print('Error running git add') 76 return 5 77 78 print('') 79 print('The updated SHA has been staged for commit. Please commit and upload.') 80 print('Suggested commit message:') 81 print('----------------------------') 82 print('') 83 print('Update glslang_validator binary for %s.' % platform.system()) 84 print('') 85 print('This binary was updated using %s.' % os.path.basename(__file__)) 86 print('Please see instructions in tools/glslang/README.md.') 87 print('') 88 print('Bug: None') 89 90 return 0 91 92 93if __name__ == '__main__': 94 sys.exit(main()) 95