blob: 92cc20bfa8a9c3389e1b00f354cb25761c6accc1 [file] [log] [blame]
Frank Henigmandda048c2018-01-11 20:09:09 -05001#!/usr/bin/python2
Jamie Madilla8b73ed2017-11-02 09:22:29 -04002#
3# Copyright 2017 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# run_code_reneration.py:
8# Runs ANGLE format table and other script run_code_renerationgeneration.
9
Jamie Madilla72f4002018-06-29 17:05:01 -040010import hashlib
11import json
12import os
13import subprocess
14import sys
Jamie Madilla8b73ed2017-11-02 09:22:29 -040015
Jamie Madilla72f4002018-06-29 17:05:01 -040016script_dir = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
17root_dir = os.path.abspath(os.path.join(script_dir, '..'))
Jamie Madilld47044a2018-04-27 11:45:03 -040018
19# auto_script is a standard way for scripts to return their inputs and outputs.
20
Geoff Lang5695a5b2018-07-05 14:29:30 -040021def get_child_script_dirname(script):
22 # All script names are relative to ANGLE's root
23 return os.path.dirname(os.path.abspath(os.path.join(root_dir, script)))
24
Geoff Lang9a257802018-07-05 14:31:08 -040025# Replace all backslashes with forward slashes to be platform independent
26def clean_path_slashes(path):
27 return path.replace("\\", "/")
28
29# Takes a script input file name which is relative to the code generation script's directory and
30# changes it to be relative to the angle root directory
31def rebase_script_input_path(script_path, input_file_path):
32 return os.path.relpath(os.path.join(os.path.dirname(script_path), input_file_path), root_dir);
33
Jamie Madilld47044a2018-04-27 11:45:03 -040034def grab_from_script(script, param):
35 res = subprocess.check_output(['python', script, param]).strip()
Geoff Lang9a257802018-07-05 14:31:08 -040036 return [clean_path_slashes(rebase_script_input_path(script, name)) for name in res.split(',')]
Jamie Madilld47044a2018-04-27 11:45:03 -040037
38def auto_script(script):
39 # Set the CWD to the script directory.
Geoff Lang5695a5b2018-07-05 14:29:30 -040040 os.chdir(get_child_script_dirname(script))
Jamie Madilld47044a2018-04-27 11:45:03 -040041 base_script = os.path.basename(script)
42 return {
43 'script': script,
44 'inputs': grab_from_script(base_script, 'inputs'),
Jamie Madilld47044a2018-04-27 11:45:03 -040045 }
46
Jamie Madilla72f4002018-06-29 17:05:01 -040047hash_fname = "run_code_generation_hashes.json"
48
Jamie Madilld47044a2018-04-27 11:45:03 -040049# TODO(jmadill): Convert everyting to auto-script.
Jamie Madilla8b73ed2017-11-02 09:22:29 -040050generators = {
51 'ANGLE format': {
52 'inputs': [
53 'src/libANGLE/renderer/angle_format.py',
54 'src/libANGLE/renderer/angle_format_data.json',
55 'src/libANGLE/renderer/angle_format_map.json',
56 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040057 'script': 'src/libANGLE/renderer/gen_angle_format_table.py',
58 },
Luc Ferron4ea3b452018-03-13 11:48:26 -040059 'ANGLE load functions table': {
60 'inputs': [
61 'src/libANGLE/renderer/load_functions_data.json',
62 ],
Luc Ferron4ea3b452018-03-13 11:48:26 -040063 'script': 'src/libANGLE/renderer/gen_load_functions_table.py',
64 },
Brandon Jonesb77884b2018-10-10 09:07:12 -070065 'D3D11 blit shader selection': {
66 'inputs': [],
67 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_blit11helper.py',
68 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -040069 'D3D11 format': {
70 'inputs': [
71 'src/libANGLE/renderer/angle_format.py',
72 'src/libANGLE/renderer/d3d/d3d11/texture_format_data.json',
73 'src/libANGLE/renderer/d3d/d3d11/texture_format_map.json',
74 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040075 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_texture_format_table.py',
76 },
77 'DXGI format': {
78 'inputs': [
79 'src/libANGLE/renderer/angle_format.py',
80 'src/libANGLE/renderer/angle_format_map.json',
81 'src/libANGLE/renderer/d3d/d3d11/dxgi_format_data.json',
jchen10547edfe2018-09-25 21:17:56 +080082 'src/libANGLE/renderer/gen_angle_format_table.py',
Jamie Madilla8b73ed2017-11-02 09:22:29 -040083 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040084 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_format_table.py',
85 },
86 'DXGI format support': {
87 'inputs': [
88 'src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json',
89 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040090 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_support_tables.py',
91 },
92 'GL copy conversion table': {
93 'inputs': [
94 'src/libANGLE/es3_copy_conversion_formats.json',
95 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040096 'script': 'src/libANGLE/gen_copy_conversion_table.py',
97 },
98 'GL entry point': {
99 'inputs': [
100 'scripts/entry_point_packed_gl_enums.json',
101 'scripts/gl.xml',
102 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400103 'script': 'scripts/generate_entry_points.py',
104 },
105 'GL format map': {
106 'inputs': [
107 'src/libANGLE/es3_format_type_combinations.json',
108 'src/libANGLE/format_map_data.json',
109 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400110 'script': 'src/libANGLE/gen_format_map.py',
111 },
112 'uniform type': {
113 'inputs': [],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400114 'script': 'src/common/gen_uniform_type_table.py',
115 },
116 'OpenGL dispatch table': {
117 'inputs': [
118 'scripts/gl.xml',
119 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400120 'script': 'src/libANGLE/renderer/gl/generate_gl_dispatch_table.py',
121 },
Geoff Lang8ceea812018-04-10 03:07:13 -0400122 'packed enum': {
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400123 'inputs': [
Jamie Madilld4703d52018-05-24 17:31:43 -0400124 'src/common/packed_gl_enums.json',
125 'src/common/packed_egl_enums.json',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400126 ],
Jamie Madilld4703d52018-05-24 17:31:43 -0400127 'script': 'src/common/gen_packed_gl_enums.py',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400128 },
Jamie Madill5ad52992017-11-14 12:43:40 -0500129 'proc table': {
130 'inputs': [
131 'src/libGLESv2/proc_table_data.json',
132 ],
Jamie Madill5ad52992017-11-14 12:43:40 -0500133 'script': 'src/libGLESv2/gen_proc_table.py',
134 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400135 'Vulkan format': {
136 'inputs': [
137 'src/libANGLE/renderer/angle_format.py',
138 'src/libANGLE/renderer/angle_format_map.json',
139 'src/libANGLE/renderer/vulkan/vk_format_map.json',
140 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400141 'script': 'src/libANGLE/renderer/vulkan/gen_vk_format_table.py',
142 },
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500143 'Vulkan mandatory format support table': {
144 'inputs': [
145 'src/libANGLE/renderer/angle_format.py',
Frank Henigman388f9912018-06-15 17:18:09 -0400146 'third_party/vulkan-headers/src/registry/vk.xml',
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500147 'src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json',
148 ],
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500149 'script': 'src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py',
150 },
Jamie Madilld47044a2018-04-27 11:45:03 -0400151 'Vulkan internal shader programs':
152 auto_script('src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py'),
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300153 'Emulated HLSL functions': {
154 'inputs': [
155 'src/compiler/translator/emulated_builtin_function_data_hlsl.json'
156 ],
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300157 'script': 'src/compiler/translator/gen_emulated_builtin_function_tables.py'
158 },
Olli Etuaho140152e2018-02-08 14:46:44 +0200159 'ESSL static builtins': {
160 'inputs': [
161 'src/compiler/translator/builtin_function_declarations.txt',
Olli Etuaho391bda22018-02-23 11:43:14 +0200162 'src/compiler/translator/builtin_variables.json',
Olli Etuaho140152e2018-02-08 14:46:44 +0200163 ],
Olli Etuaho140152e2018-02-08 14:46:44 +0200164 'script': 'src/compiler/translator/gen_builtin_symbols.py',
165 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400166}
167
Jamie Madilla72f4002018-06-29 17:05:01 -0400168def md5(fname):
169 hash_md5 = hashlib.md5()
Frank Henigman569b9cb2018-07-07 21:44:35 -0400170 with open(fname, "r") as f:
Jamie Madilla72f4002018-06-29 17:05:01 -0400171 for chunk in iter(lambda: f.read(4096), b""):
172 hash_md5.update(chunk)
173 return hash_md5.hexdigest()
174
175def any_input_dirty(name, inputs):
Geoff Langb1cc7892018-07-05 15:05:21 -0400176 found_dirty_input = False
Jamie Madilla72f4002018-06-29 17:05:01 -0400177 for finput in inputs:
178 key = name + ":" + finput
179 new_hashes[key] = md5(finput)
180 if (not key in old_hashes) or (old_hashes[key] != new_hashes[key]):
Geoff Langb1cc7892018-07-05 15:05:21 -0400181 found_dirty_input = True
182 return found_dirty_input
Jamie Madilla72f4002018-06-29 17:05:01 -0400183
184os.chdir(script_dir)
185old_hashes = json.load(open(hash_fname))
186new_hashes = {}
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400187any_dirty = False
188
189for name, info in sorted(generators.iteritems()):
190
Jamie Madilla72f4002018-06-29 17:05:01 -0400191 # Reset the CWD to the root ANGLE directory.
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400192 os.chdir(root_dir)
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400193 script = info['script']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400194
Jamie Madilla72f4002018-06-29 17:05:01 -0400195 if any_input_dirty(name, info['inputs'] + [script]):
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400196 any_dirty = True
197
198 # Set the CWD to the script directory.
Geoff Lang5695a5b2018-07-05 14:29:30 -0400199 os.chdir(get_child_script_dirname(script))
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400200
201 print('Running ' + name + ' code generator')
202 if subprocess.call(['python', os.path.basename(script)]) != 0:
203 sys.exit(1)
204
205if any_dirty:
206 args = []
207 if os.name == 'nt':
208 args += ['git.bat']
209 else:
210 args += ['git']
Jamie Madill1c597ee2018-05-24 14:19:31 -0400211 # The diff can be so large the arguments to clang-format can break the Windows command
212 # line length limits. Work around this by calling git cl format with --full.
213 args += ['cl', 'format', '--full']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400214 print('Calling git cl format')
Frank Henigmandda048c2018-01-11 20:09:09 -0500215 subprocess.call(args)
Jamie Madilla72f4002018-06-29 17:05:01 -0400216
217 os.chdir(script_dir)
218 json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True,
219 separators=(',', ':\n '))