Flutter Engine
The Flutter Engine
embedder_layering_check.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
4# for details. All rights reserved. Use of this source code is governed by a
5# BSD-style license that can be found in the LICENSE file.
6
7# Simple tool for verifying that sources from the standalone embedder do not
8# directly include sources from the VM or vice versa.
9
10import os
11import re
12import sys
13
14INCLUDE_DIRECTIVE_RE = re.compile(r'^#include "(.*)"')
15
16PLATFORM_LAYER_RE = re.compile(r'^runtime/platform/')
17VM_LAYER_RE = re.compile(r'^runtime/(vm|lib)/')
18BIN_LAYER_RE = re.compile(r'^runtime/bin/')
19
20# Tests that don't match the simple case of *_test.cc.
21EXTRA_TEST_FILES = [
22 'runtime/bin/run_vm_tests.cc',
23 'runtime/bin/ffi_unit_test/run_ffi_unit_tests.cc',
24 'runtime/vm/libfuzzer/dart_libfuzzer.cc'
25]
26
27
28def CheckFile(sdk_root, path):
29 includes = set()
30 with open(os.path.join(sdk_root, path), encoding='utf-8') as file:
31 for line in file:
32 m = INCLUDE_DIRECTIVE_RE.match(line)
33 if m is not None:
34 header = os.path.join('runtime', m.group(1))
35 if os.path.isfile(os.path.join(sdk_root, header)):
36 includes.add(header)
37
38 errors = []
39 for include in includes:
40 if PLATFORM_LAYER_RE.match(path):
41 if VM_LAYER_RE.match(include):
42 errors.append(
43 'LAYERING ERROR: %s must not include %s' % (path, include))
44 elif BIN_LAYER_RE.match(include):
45 errors.append(
46 'LAYERING ERROR: %s must not include %s' % (path, include))
47 elif VM_LAYER_RE.match(path):
48 if BIN_LAYER_RE.match(include):
49 errors.append(
50 'LAYERING ERROR: %s must not include %s' % (path, include))
51 elif BIN_LAYER_RE.match(path):
52 if VM_LAYER_RE.match(include):
53 errors.append(
54 'LAYERING ERROR: %s must not include %s' % (path, include))
55 return errors
56
57
58def CheckDir(sdk_root, dir):
59 errors = []
60 for file in os.listdir(dir):
61 path = os.path.join(dir, file)
62 if os.path.isdir(path):
63 errors += CheckDir(sdk_root, path)
64 elif path.endswith('test.cc') or path in EXTRA_TEST_FILES:
65 None # Tests may violate layering.
66 elif path.endswith('.cc') or path.endswith('.h'):
67 errors += CheckFile(sdk_root, os.path.relpath(path, sdk_root))
68 return errors
69
70
71def DoCheck(sdk_root):
72 return CheckDir(sdk_root, 'runtime')
73
74
75if __name__ == '__main__':
76 errors = DoCheck('.')
77 print('\n'.join(errors))
78 if errors:
79 sys.exit(-1)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
def print(*args, **kwargs)
Definition: run_tests.py:49
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741