Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2016 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 | # generate_vulkan_layers_json.py: |
| 8 | # Generate copies of the Vulkan layers JSON files, with no paths, forcing |
| 9 | # Vulkan to use the default search path to look for layers. |
| 10 | |
| 11 | import os, sys, json, glob |
| 12 | |
Jamie Madill | 93780e6 | 2017-01-31 15:38:26 -0500 | [diff] [blame] | 13 | if len(sys.argv) != 3: |
Jamie Madill | 0448ec8 | 2016-12-23 13:41:47 -0500 | [diff] [blame] | 14 | print("Usage: " + sys.argv[0] + " <source_dir> <target_dir>") |
| 15 | sys.exit(1) |
| 16 | |
| 17 | source_dir = sys.argv[1] |
| 18 | target_dir = sys.argv[2] |
| 19 | |
| 20 | if not os.path.isdir(source_dir): |
| 21 | print(source_dir + " is not a directory.") |
| 22 | sys.exit(1) |
| 23 | |
| 24 | if not os.path.exists(target_dir): |
| 25 | os.makedirs(target_dir) |
| 26 | |
| 27 | for json_fname in glob.glob(os.path.join(source_dir, "*.json")): |
| 28 | with open(json_fname) as infile: |
| 29 | data = json.load(infile) |
| 30 | |
| 31 | # update the path |
| 32 | prev_name = os.path.basename(data['layer']['library_path']) |
| 33 | data['layer']['library_path'] = prev_name |
| 34 | |
| 35 | target_fname = os.path.join(target_dir, os.path.basename(json_fname)) |
| 36 | with open(target_fname, "w") as outfile: |
| 37 | json.dump(data, outfile) |