blob: d0fd25b3194e67fea284329ab4ff06dd01999f71 [file] [log] [blame]
Jeff Gilbert1b605ee2017-10-30 18:41:46 -07001#!/usr/bin/python2
Jamie Madill0448ec82016-12-23 13:41:47 -05002#
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
11import os, sys, json, glob
12
Jamie Madill93780e62017-01-31 15:38:26 -050013if len(sys.argv) != 3:
Jamie Madill0448ec82016-12-23 13:41:47 -050014 print("Usage: " + sys.argv[0] + " <source_dir> <target_dir>")
15 sys.exit(1)
16
17source_dir = sys.argv[1]
18target_dir = sys.argv[2]
19
Tobin Ehlisb9d1daa2018-01-04 08:30:26 -070020data_key = 'layer'
21if 'icd' in source_dir:
22 data_key = 'ICD'
23
Jamie Madill0448ec82016-12-23 13:41:47 -050024if not os.path.isdir(source_dir):
25 print(source_dir + " is not a directory.")
26 sys.exit(1)
27
28if not os.path.exists(target_dir):
29 os.makedirs(target_dir)
30
31for json_fname in glob.glob(os.path.join(source_dir, "*.json")):
32 with open(json_fname) as infile:
33 data = json.load(infile)
34
35 # update the path
Tobin Ehlisb9d1daa2018-01-04 08:30:26 -070036 if not data_key in data:
37 raise Exception("Could not find '" + data_key + "' key in " + json_fname)
Jamie Madill8a57b462017-12-28 12:25:03 -050038
39 # The standard validation layer has no library path.
Tobin Ehlisb9d1daa2018-01-04 08:30:26 -070040 if 'library_path' in data[data_key]:
41 prev_name = os.path.basename(data[data_key]['library_path'])
42 data[data_key]['library_path'] = prev_name
Jamie Madill0448ec82016-12-23 13:41:47 -050043
44 target_fname = os.path.join(target_dir, os.path.basename(json_fname))
45 with open(target_fname, "w") as outfile:
46 json.dump(data, outfile)