diff --git a/PRESUBMIT.py b/PRESUBMIT.py index abfe1392157..b7a443f458c 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -216,18 +216,25 @@ def _CheckLayering(input_api, output_api): return [] local_root = input_api.change.RepositoryRoot() - layering_check = imp.load_source( - 'layering_check', - os.path.join(local_root, 'runtime', 'tools', 'layering_check.py')) - errors = layering_check.DoCheck(local_root) + compiler_layering_check = imp.load_source( + 'compiler_layering_check', + os.path.join(local_root, 'runtime', 'tools', + 'compiler_layering_check.py')) + errors = compiler_layering_check.DoCheck(local_root) + embedder_layering_check = imp.load_source( + 'embedder_layering_check', + os.path.join(local_root, 'runtime', 'tools', + 'embedder_layering_check.py')) + errors += embedder_layering_check.DoCheck(local_root) if errors: return [ output_api.PresubmitError( 'Layering check violation for C++ sources.', long_text='\n'.join(errors)) ] - else: - return [] + + return [] + def _CheckClangTidy(input_api, output_api): """Run clang-tidy on VM changes.""" diff --git a/runtime/tools/layering_check.py b/runtime/tools/compiler_layering_check.py similarity index 100% rename from runtime/tools/layering_check.py rename to runtime/tools/compiler_layering_check.py diff --git a/runtime/tools/embedder_layering_check.py b/runtime/tools/embedder_layering_check.py new file mode 100644 index 00000000000..d49b705bb83 --- /dev/null +++ b/runtime/tools/embedder_layering_check.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# +# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +# Simple tool for verifying that sources from the standalone embedder do not +# directly include sources from the VM or vice versa. + +import glob +import os +import re +import sys + +INCLUDE_DIRECTIVE_RE = re.compile(r'^#include "(.*)"') + +PLATFORM_LAYER_RE = re.compile(r'^runtime/platform/') +VM_LAYER_RE = re.compile(r'^runtime/(vm|lib)/') +BIN_LAYER_RE = re.compile(r'^runtime/bin/') + +# Tests that don't match the simple case of *_test.cc. +EXTRA_TEST_FILES = [ + 'runtime/bin/run_vm_tests.cc', 'runtime/vm/libfuzzer/dart_libfuzzer.cc' +] + + +def CheckFile(sdk_root, path): + includes = set() + with open(os.path.join(sdk_root, path)) as file: + for line in file: + m = INCLUDE_DIRECTIVE_RE.match(line) + if m is not None: + header = os.path.join('runtime', m.group(1)) + if os.path.isfile(os.path.join(sdk_root, header)): + includes.add(header) + + errors = [] + for include in includes: + if PLATFORM_LAYER_RE.match(path): + if VM_LAYER_RE.match(include): + errors.append( + 'LAYERING ERROR: %s must not include %s' % (path, include)) + elif BIN_LAYER_RE.match(include): + errors.append( + 'LAYERING ERROR: %s must not include %s' % (path, include)) + elif VM_LAYER_RE.match(path): + if BIN_LAYER_RE.match(include): + errors.append( + 'LAYERING ERROR: %s must not include %s' % (path, include)) + elif BIN_LAYER_RE.match(path): + if VM_LAYER_RE.match(include): + errors.append( + 'LAYERING ERROR: %s must not include %s' % (path, include)) + return errors + + +def CheckDir(sdk_root, dir): + errors = [] + for file in os.listdir(dir): + path = os.path.join(dir, file) + if os.path.isdir(path): + errors += CheckDir(sdk_root, path) + elif path.endswith('test.cc') or path in EXTRA_TEST_FILES: + None # Tests may violate layering. + elif path.endswith('.cc') or path.endswith('.h'): + errors += CheckFile(sdk_root, os.path.relpath(path, sdk_root)) + return errors + + +def DoCheck(sdk_root): + return CheckDir(sdk_root, 'runtime') + + +if __name__ == '__main__': + errors = DoCheck('.') + print '\n'.join(errors) + if errors: + sys.exit(-1) diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index 103ce151c69..abf3f558b74 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -4,7 +4,6 @@ #include "vm/kernel_isolate.h" -#include "bin/dartutils.h" #include "include/dart_native_api.h" #include "vm/compiler/jit/compiler.h" #include "vm/dart_api_impl.h"