Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
verify_sources.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse
8import os
9import sys
10import pathlib
11
12
13def main():
14 parser = argparse.ArgumentParser(
15 "Verifies that all .dart files are included in sources, and sources don't include nonexsitent files"
16 )
17 parser.add_argument(
18 "--source_dir", help="Path to the directory containing the package sources", required=True
19 )
20 parser.add_argument("--stamp", help="File to touch when source checking succeeds", required=True)
21 parser.add_argument("sources", help="source files", nargs=argparse.REMAINDER)
22 args = parser.parse_args()
23
24 actual_sources = set()
25 # Get all dart sources from source directory.
26 src_dir_path = pathlib.Path(args.source_dir)
27 for (dirpath, dirnames, filenames) in os.walk(src_dir_path, topdown=True):
28 relpath_to_src_root = pathlib.Path(dirpath).relative_to(src_dir_path)
29 actual_sources.update(
30 os.path.normpath(relpath_to_src_root.joinpath(filename))
31 for filename in filenames
32 if pathlib.Path(filename).suffix == ".dart"
33 )
34
35 expected_sources = set(args.sources)
36 # It is possible for sources to include dart files outside of source_dir.
37 actual_sources.update([
38 s for s in (expected_sources - actual_sources) if src_dir_path.joinpath(s).resolve().exists()
39 ],)
40
41 if actual_sources == expected_sources:
42 with open(args.stamp, "w") as stamp:
43 stamp.write("Success!")
44 return 0
45
46 def sources_to_abs_path(sources):
47 return sorted(str(src_dir_path.joinpath(s)) for s in sources)
48
49 missing_sources = actual_sources - expected_sources
50 if missing_sources:
51 print(
52 '\nSource files found that were missing from the "sources" parameter:\n{}\n'.format(
53 "\n".join(sources_to_abs_path(missing_sources))
54 ),
55 )
56 nonexistent_sources = expected_sources - actual_sources
57 if nonexistent_sources:
58 print(
59 '\nSource files listed in "sources" parameter but not found:\n{}\n'.format(
60 "\n".join(sources_to_abs_path(nonexistent_sources))
61 ),
62 )
63 return 1
64
65
66if __name__ == "__main__":
67 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
uint32_t uint32_t * format
Definition main.py:1