blob: 84eddeec8c6d9c9cb215e6d3f24506bf25c98853 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright (c) 2016, 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.
"""Tool for listing Dart source files.
If the first argument is 'relative', the script produces paths relative to the
current working directory. If the first argument is 'absolute', the script
produces absolute paths.
python3 tools/ <depfile> <directory> <pattern>
import os
import re
import sys
def main(argv):
depfile = argv[1]
directory = argv[2]
if not os.path.isabs(directory):
directory = os.path.realpath(directory)
pattern = None
if len(argv) > 3:
pattern = re.compile(argv[3])
# Output a GN/Ninja depfile, whose format is a Makefile with one target.
out = open(depfile, 'w')
for root, directories, files in os.walk(directory):
# We only care about actual source files, not generated code or tests.
for skip_dir in ['.git', 'gen', 'test']:
if skip_dir in directories:
# If we are looking at the root directory, filter the immediate
# subdirectories by the given pattern.
if pattern and root == directory:
directories[:] = filter(pattern.match, directories)
for filename in files:
if filename.endswith(
'.dart') and not filename.endswith('_test.dart'):
fullname = os.path.join(directory, root, filename)
fullname = fullname.replace(os.sep, '/')
out.write(" \"")
if __name__ == '__main__':