Flutter Engine
The Flutter Engine
list_dart_files_as_depfile.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5"""Tool for listing Dart source files.
6
7If the first argument is 'relative', the script produces paths relative to the
8current working directory. If the first argument is 'absolute', the script
9produces absolute paths.
10
11Usage:
12 python3 tools/list_dart_files_as_depfile.py <depfile> <directory> <pattern>
13"""
14
15import os
16import re
17import sys
18
19
20def main(argv):
21 depfile = argv[1]
22 directory = argv[2]
23 if not os.path.isabs(directory):
24 directory = os.path.realpath(directory)
25
26 pattern = None
27 if len(argv) > 3:
28 pattern = re.compile(argv[3])
29
30 # Output a GN/Ninja depfile, whose format is a Makefile with one target.
31 out = open(depfile, 'w')
32 out.write(os.path.relpath(depfile))
33 out.write(":")
34
35 for root, directories, files in os.walk(directory):
36 # We only care about actual source files, not generated code or tests.
37 for skip_dir in ['.git', 'gen', 'test']:
38 if skip_dir in directories:
39 directories.remove(skip_dir)
40
41 # If we are looking at the root directory, filter the immediate
42 # subdirectories by the given pattern.
43 if pattern and root == directory:
44 directories[:] = filter(pattern.match, directories)
45
46 for filename in files:
47 if filename.endswith(
48 '.dart') and not filename.endswith('_test.dart'):
49 fullname = os.path.join(directory, root, filename)
50 fullname = fullname.replace(os.sep, '/')
51 out.write(" \"")
52 out.write(fullname)
53 out.write("\"")
54
55 out.write("\n")
56 out.close()
57
58
59if __name__ == '__main__':
60 sys.exit(main(sys.argv))
Definition: main.py:1