From 4a576907c837296b1767dfe87139fc6a65cf024c Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Thu, 16 Jan 2020 08:59:53 -0800 Subject: [PATCH] Added verify_duplicate_sources --- .../plugins/verify_duplicate_sources.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/buildgen/plugins/verify_duplicate_sources.py diff --git a/tools/buildgen/plugins/verify_duplicate_sources.py b/tools/buildgen/plugins/verify_duplicate_sources.py new file mode 100644 index 00000000000..06b2b1cb426 --- /dev/null +++ b/tools/buildgen/plugins/verify_duplicate_sources.py @@ -0,0 +1,42 @@ +# Copyright 2020 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Buildgen duplicate source validation plugin.""" + + +def mako_plugin(dictionary): + """The exported plugin code for verify_duplicate_sources. + + This validates that a certain set of libraries don't contain + duplicate source files which may cause One Definition Rule (ODR) + violation. + """ + errors = [] + target_groups = ( + ('gpr', 'grpc', 'grpc++'), + ('gpr', 'grpc_unsecure', 'grpc++_unsecure'), + ) + lib_map = {lib['name']: lib for lib in dictionary.get('libs')} + for target_group in target_groups: + src_map = {} + for target in target_group: + for src in lib_map[target]['src']: + if src.endswith('.cc'): + if src in src_map: + errors.append( + 'Source {0} is used in both {1} and {2}'.format( + src, src_map[src], target)) + else: + src_map[src] = target + if errors: + raise Exception('\n'.join(errors))