generate_vulkan_layers_json.py: Fix Python 3 compatibility
authorRaul Tambre <raul@tambre.ee>
Thu, 5 Mar 2020 19:07:10 +0000 (21:07 +0200)
committerjeremyk-lunarg <jeremyk@lunarg.com>
Thu, 5 Mar 2020 20:55:12 +0000 (13:55 -0700)
json.dump() returns a string. Writing strings to a file opened in binary mode doesn't work. Python 2 doesn't properly distringuish bytes and strings.
Open in non-binary mode, so this code works on both.

Traceback (most recent call last):
  File "../../third_party/angle/third_party/vulkan-tools/src/build-gn/generate_vulkan_layers_json.py", line 126, in <module>
    sys.exit(main())
  File "../../third_party/angle/third_party/vulkan-tools/src/build-gn/generate_vulkan_layers_json.py", line 83, in main
    json.dump(data, outfile)
  File "C:\Program Files\Python38\lib\json\__init__.py", line 180, in dump
    fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'

Chromium bug: https://crbug.com/941669

build-gn/generate_vulkan_layers_json.py

index 2999cd8..2e2b3d5 100755 (executable)
@@ -79,7 +79,7 @@ def main():
             data[data_key]['library_path'] = prev_name
 
         target_fname = os.path.join(target_dir, os.path.basename(json_fname))
-        with open(target_fname, 'wb') as outfile:
+        with open(target_fname, 'w') as outfile:
             json.dump(data, outfile)
 
     # Get the Vulkan version from the vulkan_core.h file