Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: third_party/grpc/tools/buildgen/build-cleaner.py

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/grpc/tools/README.md ('k') | third_party/grpc/tools/buildgen/bunch.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python2.7
2 # Copyright 2015-2016, Google Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 # produces cleaner build.yaml files
32
33 import collections
34 import os
35 import sys
36 import yaml
37
38 TEST = (os.environ.get('TEST', 'false') == 'true')
39
40 _TOP_LEVEL_KEYS = ['settings', 'proto_deps', 'filegroups', 'libs', 'targets', 'v spackages']
41 _ELEM_KEYS = [
42 'name',
43 'gtest',
44 'cpu_cost',
45 'flaky',
46 'build',
47 'run',
48 'language',
49 'public_headers',
50 'headers',
51 'src',
52 'deps']
53
54 def repr_ordered_dict(dumper, odict):
55 return dumper.represent_mapping(u'tag:yaml.org,2002:map', odict.items())
56
57 yaml.add_representer(collections.OrderedDict, repr_ordered_dict)
58
59 def rebuild_as_ordered_dict(indict, special_keys):
60 outdict = collections.OrderedDict()
61 for key in sorted(indict.keys()):
62 if '#' in key:
63 outdict[key] = indict[key]
64 for key in special_keys:
65 if key in indict:
66 outdict[key] = indict[key]
67 for key in sorted(indict.keys()):
68 if key in special_keys: continue
69 if '#' in key: continue
70 outdict[key] = indict[key]
71 return outdict
72
73 def clean_elem(indict):
74 for name in ['public_headers', 'headers', 'src']:
75 if name not in indict: continue
76 inlist = indict[name]
77 protos = list(x for x in inlist if os.path.splitext(x)[1] == '.proto')
78 others = set(x for x in inlist if x not in protos)
79 indict[name] = protos + sorted(others)
80 return rebuild_as_ordered_dict(indict, _ELEM_KEYS)
81
82 for filename in sys.argv[1:]:
83 with open(filename) as f:
84 js = yaml.load(f)
85 js = rebuild_as_ordered_dict(js, _TOP_LEVEL_KEYS)
86 for grp in ['filegroups', 'libs', 'targets']:
87 if grp not in js: continue
88 js[grp] = sorted([clean_elem(x) for x in js[grp]],
89 key=lambda x: (x.get('language', '_'), x['name']))
90 output = yaml.dump(js, indent=2, width=80, default_flow_style=False)
91 # massage out trailing whitespace
92 lines = []
93 for line in output.splitlines():
94 lines.append(line.rstrip() + '\n')
95 output = ''.join(lines)
96 if TEST:
97 with open(filename) as f:
98 assert f.read() == output
99 else:
100 with open(filename, 'w') as f:
101 f.write(output)
OLDNEW
« no previous file with comments | « third_party/grpc/tools/README.md ('k') | third_party/grpc/tools/buildgen/bunch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698