Upstream version 9.38.205.0
[platform/framework/web/crosswalk.git] / src / xwalk / build / android / generate_xwalk_core_library_aar.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2014 Intel Corporation. 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.
6
7 import optparse
8 import os
9 import sys
10 import zipfile
11
12
13 def main():
14   option_parser = optparse.OptionParser()
15   option_parser.add_option('-t', dest='target',
16                            help='Product out target directory.')
17   options, _ = option_parser.parse_args()
18
19   # The first entry of each tuple is the source file/directory that will be
20   # copied (and must exist), the second entry is its relative path inside the
21   # AAR file.
22   dirs = (
23     (os.path.join(options.target, 'xwalk_core_library', 'libs'),
24      'jni'),
25     (os.path.join(options.target, 'xwalk_core_library', 'res'),
26      'res'),
27   )
28   files = (
29     (os.path.join(options.target, 'gen', 'xwalk_core_internal_java', 'java_R',
30                   'R.txt'),
31      'R.txt'),
32     (os.path.join(options.target, 'xwalk_core_library', 'AndroidManifest.xml'),
33      'AndroidManifest.xml'),
34     (os.path.join(options.target, 'xwalk_core_library', 'libs',
35                   'xwalk_core_library_java.jar'),
36      'classes.jar'),
37   )
38   # This is a list of files that will not be packaged: mostly a blacklist of
39   # files within |dirs|.
40   exclude_files = (
41     os.path.join(options.target, 'xwalk_core_library', 'libs',
42                  'xwalk_core_library_java.jar'),
43   )
44
45   aar_path = os.path.join(options.target, 'xwalk_core_library.aar')
46   with zipfile.ZipFile(aar_path, 'w') as aar_file:
47     for src, dest in files:
48       aar_file.write(src, dest)
49     for src, dest in dirs:
50       for root, _, files in os.walk(src):
51         for f in files:
52           real_path = os.path.join(root, f)
53           zip_path = os.path.join(dest, os.path.relpath(root, src), f)
54           if real_path in exclude_files:
55             continue
56           aar_file.write(real_path, zip_path)
57
58   return 0
59
60
61 if __name__ == '__main__':
62   sys.exit(main())