Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
build_workaround_header.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (c) 2018 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""code generator for gpu workaround definitions"""
6
7import os
8import os.path
9import sys
10from optparse import OptionParser
11
12_LICENSE = """// Copyright 2018 The Chromium Authors. All rights reserved.
13// Use of this source code is governed by a BSD-style license that can be
14// found in the LICENSE file.
15
16"""
17
18_DO_NOT_EDIT_WARNING = ("// This file is auto-generated from " +
19 os.path.basename(__file__) + "\n" +
20 "// DO NOT EDIT!\n\n")
21
23 workarounds = set()
24 for filename in files:
25 with open(filename, 'r') as f:
26 workarounds.update([workaround.strip() for workaround in f])
27 return sorted(list(workarounds))
28
29
30def write_header(filename, workarounds):
31 max_workaround_len = len(max(workarounds, key=len))
32
33 with open(filename, 'w') as f:
34 f.write(_LICENSE)
35 f.write(_DO_NOT_EDIT_WARNING)
36
37 indent = ' '
38 macro = 'GPU_OP'
39
40 # length of max string passed to write + 1
41 max_len = len(indent) + len(macro) + 1 + max_workaround_len + 1 + 1
42 write = lambda line: f.write(line + ' ' * (max_len - len(line)) + '\\\n')
43 f.write('#ifndef GPU_DRIVER_BUG_WORKAROUNDS\n')
44 write('#define GPU_DRIVER_BUG_WORKAROUNDS(GPU_OP)')
45 for w in workarounds:
46 write(indent + macro + '(' + w.upper() + ',')
47 write(indent + ' ' * (len(macro) + 1) + w + ')')
48
49 # one extra line for the last escaped newline to handle.
50 f.write('\n')
51 f.write('#endif // GPU_DRIVER_BUG_WORKAROUNDS\n')
52
53
54def main(argv):
55 usage = "usage: %prog [options] file1 file2 file3 etc"
56 parser = OptionParser(usage=usage)
57 parser.add_option(
58 "--output-file",
59 dest="output_file",
60 default="gpu_driver_bug_workaround_autogen.h",
61 help="the name of the header file to write")
62
63 (options, _) = parser.parse_args(args=argv)
64
65 workarounds = merge_files_into_workarounds(parser.largs)
66 write_header(options.output_file, workarounds)
67
68
69if __name__ == '__main__':
70 sys.exit(main(sys.argv[1:]))
static float max(float r, float g, float b)
Definition hsl.cpp:49
Definition main.py:1
void write(SkWStream *wStream, const T &text)
Definition skqp.cpp:188