blob: 809cbb83803670d8a376d27fc5460d1e5a8f16a1 [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 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -040065 'D3D11 format': {
66 'inputs': [
67 'src/libANGLE/renderer/angle_format.py',
68 'src/libANGLE/renderer/d3d/d3d11/texture_format_data.json',
69 'src/libANGLE/renderer/d3d/d3d11/texture_format_map.json',
70 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040071 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_texture_format_table.py',
72 },
73 'DXGI format': {
74 'inputs': [
75 'src/libANGLE/renderer/angle_format.py',
76 'src/libANGLE/renderer/angle_format_map.json',
77 'src/libANGLE/renderer/d3d/d3d11/dxgi_format_data.json',
78 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040079 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_format_table.py',
80 },
81 'DXGI format support': {
82 'inputs': [
83 'src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json',
84 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040085 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_support_tables.py',
86 },
87 'GL copy conversion table': {
88 'inputs': [
89 'src/libANGLE/es3_copy_conversion_formats.json',
90 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040091 'script': 'src/libANGLE/gen_copy_conversion_table.py',
92 },
93 'GL entry point': {
94 'inputs': [
95 'scripts/entry_point_packed_gl_enums.json',
96 'scripts/gl.xml',
97 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040098 'script': 'scripts/generate_entry_points.py',
99 },
100 'GL format map': {
101 'inputs': [
102 'src/libANGLE/es3_format_type_combinations.json',
103 'src/libANGLE/format_map_data.json',
104 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400105 'script': 'src/libANGLE/gen_format_map.py',
106 },
107 'uniform type': {
108 'inputs': [],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400109 'script': 'src/common/gen_uniform_type_table.py',
110 },
111 'OpenGL dispatch table': {
112 'inputs': [
113 'scripts/gl.xml',
114 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400115 'script': 'src/libANGLE/renderer/gl/generate_gl_dispatch_table.py',
116 },
Geoff Lang8ceea812018-04-10 03:07:13 -0400117 'packed enum': {
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400118 'inputs': [
Jamie Madilld4703d52018-05-24 17:31:43 -0400119 'src/common/packed_gl_enums.json',
120 'src/common/packed_egl_enums.json',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400121 ],
Jamie Madilld4703d52018-05-24 17:31:43 -0400122 'script': 'src/common/gen_packed_gl_enums.py',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400123 },
Jamie Madill5ad52992017-11-14 12:43:40 -0500124 'proc table': {
125 'inputs': [
126 'src/libGLESv2/proc_table_data.json',
127 ],
Jamie Madill5ad52992017-11-14 12:43:40 -0500128 'script': 'src/libGLESv2/gen_proc_table.py',
129 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400130 'Vulkan format': {
131 'inputs': [
132 'src/libANGLE/renderer/angle_format.py',
133 'src/libANGLE/renderer/angle_format_map.json',
134 'src/libANGLE/renderer/vulkan/vk_format_map.json',
135 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400136 'script': 'src/libANGLE/renderer/vulkan/gen_vk_format_table.py',
137 },
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500138 'Vulkan mandatory format support table': {
139 'inputs': [
140 'src/libANGLE/renderer/angle_format.py',
Frank Henigman388f9912018-06-15 17:18:09 -0400141 'third_party/vulkan-headers/src/registry/vk.xml',
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500142 'src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json',
143 ],
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500144 'script': 'src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py',
145 },
Jamie Madilld47044a2018-04-27 11:45:03 -0400146 'Vulkan internal shader programs':
147 auto_script('src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py'),
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300148 'Emulated HLSL functions': {
149 'inputs': [
150 'src/compiler/translator/emulated_builtin_function_data_hlsl.json'
151 ],
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300152 'script': 'src/compiler/translator/gen_emulated_builtin_function_tables.py'
153 },
Olli Etuaho140152e2018-02-08 14:46:44 +0200154 'ESSL static builtins': {
155 'inputs': [
156 'src/compiler/translator/builtin_function_declarations.txt',
Olli Etuaho391bda22018-02-23 11:43:14 +0200157 'src/compiler/translator/builtin_variables.json',
Olli Etuaho140152e2018-02-08 14:46:44 +0200158 ],
Olli Etuaho140152e2018-02-08 14:46:44 +0200159 'script': 'src/compiler/translator/gen_builtin_symbols.py',
160 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400161}
162
Jamie Madilla72f4002018-06-29 17:05:01 -0400163def md5(fname):
164 hash_md5 = hashlib.md5()
Frank Henigman569b9cb2018-07-07 21:44:35 -0400165 with open(fname, "r") as f:
Jamie Madilla72f4002018-06-29 17:05:01 -0400166 for chunk in iter(lambda: f.read(4096), b""):
167 hash_md5.update(chunk)
168 return hash_md5.hexdigest()
169
170def any_input_dirty(name, inputs):
Geoff Langb1cc7892018-07-05 15:05:21 -0400171 found_dirty_input = False
Jamie Madilla72f4002018-06-29 17:05:01 -0400172 for finput in inputs:
173 key = name + ":" + finput
174 new_hashes[key] = md5(finput)
175 if (not key in old_hashes) or (old_hashes[key] != new_hashes[key]):
Geoff Langb1cc7892018-07-05 15:05:21 -0400176 found_dirty_input = True
177 return found_dirty_input
Jamie Madilla72f4002018-06-29 17:05:01 -0400178
179os.chdir(script_dir)
180old_hashes = json.load(open(hash_fname))
181new_hashes = {}
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400182any_dirty = False
183
184for name, info in sorted(generators.iteritems()):
185
Jamie Madilla72f4002018-06-29 17:05:01 -0400186 # Reset the CWD to the root ANGLE directory.
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400187 os.chdir(root_dir)
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400188 script = info['script']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400189
Jamie Madilla72f4002018-06-29 17:05:01 -0400190 if any_input_dirty(name, info['inputs'] + [script]):
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400191 any_dirty = True
192
193 # Set the CWD to the script directory.
Geoff Lang5695a5b2018-07-05 14:29:30 -0400194 os.chdir(get_child_script_dirname(script))
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400195
196 print('Running ' + name + ' code generator')
197 if subprocess.call(['python', os.path.basename(script)]) != 0:
198 sys.exit(1)
199
200if any_dirty:
201 args = []
202 if os.name == 'nt':
203 args += ['git.bat']
204 else:
205 args += ['git']
Jamie Madill1c597ee2018-05-24 14:19:31 -0400206 # The diff can be so large the arguments to clang-format can break the Windows command
207 # line length limits. Work around this by calling git cl format with --full.
208 args += ['cl', 'format', '--full']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400209 print('Calling git cl format')
Frank Henigmandda048c2018-01-11 20:09:09 -0500210 subprocess.call(args)
Jamie Madilla72f4002018-06-29 17:05:01 -0400211
212 os.chdir(script_dir)
213 json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True,
214 separators=(',', ':\n '))