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

Side by Side Diff: third_party/grpc/tools/run_tests/sanity/check_sources_and_headers.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
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 import json
32 import os
33 import re
34 import sys
35
36 root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../../..'))
37 with open(os.path.join(root, 'tools', 'run_tests', 'sources_and_headers.json')) as f:
38 js = json.loads(f.read())
39
40 re_inc1 = re.compile(r'^#\s*include\s*"([^"]*)"')
41 assert re_inc1.match('#include "foo"').group(1) == 'foo'
42 re_inc2 = re.compile(r'^#\s*include\s*<((grpc|grpc\+\+)/[^"]*)>')
43 assert re_inc2.match('#include <grpc++/foo>').group(1) == 'grpc++/foo'
44
45 def get_target(name):
46 for target in js:
47 if target['name'] == name:
48 return target
49 assert False, 'no target %s' % name
50
51 def target_has_header(target, name):
52 # print target['name'], name
53 if name in target['headers']:
54 return True
55 for dep in target['deps']:
56 if target_has_header(get_target(dep), name):
57 return True
58 if name == 'src/core/profiling/stap_probes.h':
59 return True
60 return False
61
62 def produces_object(name):
63 return os.path.splitext(name)[1] in ['.c', '.cc']
64
65 obj_producer_to_source = {'c': {}, 'c++': {}, 'csharp': {}}
66
67 errors = 0
68 for target in js:
69 if not target['third_party']:
70 for fn in target['src']:
71 with open(os.path.join(root, fn)) as f:
72 src = f.read().splitlines()
73 for line in src:
74 m = re_inc1.match(line)
75 if m:
76 if not target_has_header(target, m.group(1)):
77 print (
78 'target %s (%s) does not name header %s as a dependency' % (
79 target['name'], fn, m.group(1)))
80 errors += 1
81 m = re_inc2.match(line)
82 if m:
83 if not target_has_header(target, 'include/' + m.group(1)):
84 print (
85 'target %s (%s) does not name header %s as a dependency' % (
86 target['name'], fn, m.group(1)))
87 errors += 1
88 if target['type'] == 'lib':
89 for fn in target['src']:
90 language = target['language']
91 if produces_object(fn):
92 obj_base = os.path.splitext(os.path.basename(fn))[0]
93 if obj_base in obj_producer_to_source[language]:
94 if obj_producer_to_source[language][obj_base] != fn:
95 print (
96 'target %s (%s) produces an aliased object file with %s' % (
97 target['name'], fn, obj_producer_to_source[language][obj_base]))
98 else:
99 obj_producer_to_source[language][obj_base] = fn
100
101 assert errors == 0
OLDNEW
« no previous file with comments | « third_party/grpc/tools/run_tests/sanity/check_cache_mk.sh ('k') | third_party/grpc/tools/run_tests/sanity/check_submodules.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698