Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
find_resources.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright (c) 2020, 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
8# Finds files in the given directories and their subdirectories, and prints them
9# in the json format expected by GN fuchsia_component's resources arg:
10# [
11# {
12# "path": "path/to/file.dart",
13# "dest": "data/path/to/file.dart"
14# },
15# ...
16# ]
17
18import sys
19import os
20
21from os.path import join, abspath, relpath
22
23DART_DIR = abspath(join(__file__, '..', '..', '..'))
24
25
26def listFiles(path):
27 allFiles = []
28 for dirpath, dirs, files in os.walk(join(DART_DIR, path)):
29 allFiles += [
30 relpath(abspath(join(dirpath, p)), DART_DIR) for p in files
31 ]
32 return allFiles
33
34
35def printOutput(files):
36 print('[')
37 print(',\n'.join([
38 ' {\n "path": "%s",\n "dest": "data/%s"\n }' % (f, f)
39 for f in files
40 ]))
41 print(']')
42
43
44def main():
45 if len(sys.argv) < 2:
46 print('Expected at least 1 arg, the paths to search.')
47 return 1
48 allFiles = []
49 for directory in sys.argv[1:]:
50 files = listFiles(directory)
51 if len(files) == 0:
52 print('Did not find any files in the directory: ' + directory)
53 return 2
54 allFiles += files
55 printOutput(sorted(allFiles))
56 return 0
57
58
59if __name__ == '__main__':
60 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1