2021-04-15 10:10:20 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-07-15 20:44:06 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2020, 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Finds files in the given directories and their subdirectories, and prints them
|
|
|
|
# in the json format expected by GN fuchsia_component's resources arg:
|
|
|
|
# [
|
|
|
|
# {
|
|
|
|
# "path": "path/to/file.dart",
|
|
|
|
# "dest": "data/path/to/file.dart"
|
|
|
|
# },
|
|
|
|
# ...
|
|
|
|
# ]
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
from os.path import join, abspath, relpath
|
|
|
|
|
|
|
|
DART_DIR = abspath(join(__file__, '..', '..', '..'))
|
|
|
|
|
|
|
|
|
|
|
|
def listFiles(path):
|
2021-04-15 10:10:20 +00:00
|
|
|
allFiles = []
|
|
|
|
for dirpath, dirs, files in os.walk(join(DART_DIR, path)):
|
|
|
|
allFiles += [
|
|
|
|
relpath(abspath(join(dirpath, p)), DART_DIR) for p in files
|
|
|
|
]
|
|
|
|
return allFiles
|
2020-07-15 20:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def printOutput(files):
|
2021-04-15 10:10:20 +00:00
|
|
|
print('[')
|
|
|
|
print(',\n'.join([
|
|
|
|
' {\n "path": "%s",\n "dest": "data/%s"\n }' % (f, f)
|
|
|
|
for f in files
|
|
|
|
]))
|
|
|
|
print(']')
|
2020-07-15 20:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-04-15 10:10:20 +00:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print('Expected at least 1 arg, the paths to search.')
|
|
|
|
return 1
|
|
|
|
allFiles = []
|
|
|
|
for directory in sys.argv[1:]:
|
|
|
|
files = listFiles(directory)
|
|
|
|
if len(files) == 0:
|
|
|
|
print('Did not find any files in the directory: ' + directory)
|
|
|
|
return 2
|
|
|
|
allFiles += files
|
|
|
|
printOutput(sorted(allFiles))
|
|
|
|
return 0
|
2020-07-15 20:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-04-15 10:10:20 +00:00
|
|
|
sys.exit(main())
|