blob: 0dc82d2d25d3a061a8adf72985fe5f17612827f4 [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',
jchen10547edfe2018-09-25 21:17:56 +080078 'src/libANGLE/renderer/gen_angle_format_table.py',
Jamie Madilla8b73ed2017-11-02 09:22:29 -040079 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040080 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_format_table.py',
81 },
82 'DXGI format support': {
83 'inputs': [
84 'src/libANGLE/renderer/d3d/d3d11/dxgi_support_data.json',
85 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040086 'script': 'src/libANGLE/renderer/d3d/d3d11/gen_dxgi_support_tables.py',
87 },
88 'GL copy conversion table': {
89 'inputs': [
90 'src/libANGLE/es3_copy_conversion_formats.json',
91 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040092 'script': 'src/libANGLE/gen_copy_conversion_table.py',
93 },
94 'GL entry point': {
95 'inputs': [
96 'scripts/entry_point_packed_gl_enums.json',
97 'scripts/gl.xml',
98 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -040099 'script': 'scripts/generate_entry_points.py',
100 },
101 'GL format map': {
102 'inputs': [
103 'src/libANGLE/es3_format_type_combinations.json',
104 'src/libANGLE/format_map_data.json',
105 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400106 'script': 'src/libANGLE/gen_format_map.py',
107 },
108 'uniform type': {
109 'inputs': [],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400110 'script': 'src/common/gen_uniform_type_table.py',
111 },
112 'OpenGL dispatch table': {
113 'inputs': [
114 'scripts/gl.xml',
115 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400116 'script': 'src/libANGLE/renderer/gl/generate_gl_dispatch_table.py',
117 },
Geoff Lang8ceea812018-04-10 03:07:13 -0400118 'packed enum': {
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400119 'inputs': [
Jamie Madilld4703d52018-05-24 17:31:43 -0400120 'src/common/packed_gl_enums.json',
121 'src/common/packed_egl_enums.json',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400122 ],
Jamie Madilld4703d52018-05-24 17:31:43 -0400123 'script': 'src/common/gen_packed_gl_enums.py',
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400124 },
Jamie Madill5ad52992017-11-14 12:43:40 -0500125 'proc table': {
126 'inputs': [
127 'src/libGLESv2/proc_table_data.json',
128 ],
Jamie Madill5ad52992017-11-14 12:43:40 -0500129 'script': 'src/libGLESv2/gen_proc_table.py',
130 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400131 'Vulkan format': {
132 'inputs': [
133 'src/libANGLE/renderer/angle_format.py',
134 'src/libANGLE/renderer/angle_format_map.json',
135 'src/libANGLE/renderer/vulkan/vk_format_map.json',
136 ],
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400137 'script': 'src/libANGLE/renderer/vulkan/gen_vk_format_table.py',
138 },
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500139 'Vulkan mandatory format support table': {
140 'inputs': [
141 'src/libANGLE/renderer/angle_format.py',
Frank Henigman388f9912018-06-15 17:18:09 -0400142 'third_party/vulkan-headers/src/registry/vk.xml',
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500143 'src/libANGLE/renderer/vulkan/vk_mandatory_format_support_data.json',
144 ],
Luc Ferron0aa1ffe2018-02-08 13:42:36 -0500145 'script': 'src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py',
146 },
Jamie Madilld47044a2018-04-27 11:45:03 -0400147 'Vulkan internal shader programs':
148 auto_script('src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py'),
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300149 'Emulated HLSL functions': {
150 'inputs': [
151 'src/compiler/translator/emulated_builtin_function_data_hlsl.json'
152 ],
Olli Etuaho5fec7ab2018-04-04 11:58:33 +0300153 'script': 'src/compiler/translator/gen_emulated_builtin_function_tables.py'
154 },
Olli Etuaho140152e2018-02-08 14:46:44 +0200155 'ESSL static builtins': {
156 'inputs': [
157 'src/compiler/translator/builtin_function_declarations.txt',
Olli Etuaho391bda22018-02-23 11:43:14 +0200158 'src/compiler/translator/builtin_variables.json',
Olli Etuaho140152e2018-02-08 14:46:44 +0200159 ],
Olli Etuaho140152e2018-02-08 14:46:44 +0200160 'script': 'src/compiler/translator/gen_builtin_symbols.py',
161 },
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400162}
163
Jamie Madilla72f4002018-06-29 17:05:01 -0400164def md5(fname):
165 hash_md5 = hashlib.md5()
Frank Henigman569b9cb2018-07-07 21:44:35 -0400166 with open(fname, "r") as f:
Jamie Madilla72f4002018-06-29 17:05:01 -0400167 for chunk in iter(lambda: f.read(4096), b""):
168 hash_md5.update(chunk)
169 return hash_md5.hexdigest()
170
171def any_input_dirty(name, inputs):
Geoff Langb1cc7892018-07-05 15:05:21 -0400172 found_dirty_input = False
Jamie Madilla72f4002018-06-29 17:05:01 -0400173 for finput in inputs:
174 key = name + ":" + finput
175 new_hashes[key] = md5(finput)
176 if (not key in old_hashes) or (old_hashes[key] != new_hashes[key]):
Geoff Langb1cc7892018-07-05 15:05:21 -0400177 found_dirty_input = True
178 return found_dirty_input
Jamie Madilla72f4002018-06-29 17:05:01 -0400179
180os.chdir(script_dir)
181old_hashes = json.load(open(hash_fname))
182new_hashes = {}
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400183any_dirty = False
184
185for name, info in sorted(generators.iteritems()):
186
Jamie Madilla72f4002018-06-29 17:05:01 -0400187 # Reset the CWD to the root ANGLE directory.
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400188 os.chdir(root_dir)
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400189 script = info['script']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400190
Jamie Madilla72f4002018-06-29 17:05:01 -0400191 if any_input_dirty(name, info['inputs'] + [script]):
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400192 any_dirty = True
193
194 # Set the CWD to the script directory.
Geoff Lang5695a5b2018-07-05 14:29:30 -0400195 os.chdir(get_child_script_dirname(script))
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400196
197 print('Running ' + name + ' code generator')
198 if subprocess.call(['python', os.path.basename(script)]) != 0:
199 sys.exit(1)
200
201if any_dirty:
202 args = []
203 if os.name == 'nt':
204 args += ['git.bat']
205 else:
206 args += ['git']
Jamie Madill1c597ee2018-05-24 14:19:31 -0400207 # The diff can be so large the arguments to clang-format can break the Windows command
208 # line length limits. Work around this by calling git cl format with --full.
209 args += ['cl', 'format', '--full']
Jamie Madilla8b73ed2017-11-02 09:22:29 -0400210 print('Calling git cl format')
Frank Henigmandda048c2018-01-11 20:09:09 -0500211 subprocess.call(args)
Jamie Madilla72f4002018-06-29 17:05:01 -0400212
213 os.chdir(script_dir)
214 json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True,
215 separators=(',', ':\n '))