Fixes for Android GN build input/outputs
[chromium-blink-merge.git] / mojo / tools / generate_mojo_shell_assets_list.py
blob1a55af43e6f3f1bced184706bda9830983d35689
1 #!/usr/bin/env python
3 # Copyright 2015 The Chromium 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.
7 """Generates the assets_list file from a directory."""
9 import argparse
10 import os
11 import sys
13 def main():
14 parser = argparse.ArgumentParser(usage="--dir <directory>")
16 parser.add_argument('--dir', help='Directory read files from.', required=True)
18 options, _ = parser.parse_known_args()
20 if not os.path.exists(options.dir) or not os.path.isdir(options.dir):
21 print 'Directory does not exist, or path is not a directory', options.dir
22 return -1
24 root_dir = os.path.abspath(options.dir)
25 all_files = []
26 for current_root, _, files in os.walk(options.dir):
27 current_root_absolute = os.path.abspath(current_root)
28 if len(current_root_absolute) < len(root_dir):
29 print 'unexpected directory', current_root_absolute
30 return -1
31 rel_root = current_root_absolute[len(root_dir):]
32 if len(rel_root) and rel_root.startswith(os.sep):
33 rel_root = rel_root[len(os.sep):]
34 if len(rel_root) and not rel_root.endswith(os.sep):
35 rel_root += os.sep
36 all_files.extend([rel_root + f for f in files])
38 with open(os.path.join(options.dir, 'assets_list'), 'w') as f:
39 for a_file in all_files:
40 f.write(a_file + '\n')
42 return 0
44 if __name__ == '__main__':
45 sys.exit(main())