Upstream version 10.38.220.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, 'lib.java', 'xwalk_core_library_java.jar'),
35      'classes.jar'),
36   )
37   # This is a list of files that will not be packaged: mostly a blacklist of
38   # files within |dirs|.
39   exclude_files = (
40     os.path.join(options.target, 'xwalk_core_library', 'libs',
41                  'xwalk_core_library_java_app_part.jar'),
42     os.path.join(options.target, 'xwalk_core_library', 'libs',
43                  'xwalk_core_library_java_library_part.jar'),
44   )
45
46   aar_path = os.path.join(options.target, 'xwalk_core_library.aar')
47   with zipfile.ZipFile(aar_path, 'w', zipfile.ZIP_DEFLATED) as aar_file:
48     for src, dest in files:
49       aar_file.write(src, dest)
50     for src, dest in dirs:
51       for root, _, files in os.walk(src):
52         for f in files:
53           real_path = os.path.join(root, f)
54           zip_path = os.path.join(dest, os.path.relpath(root, src), f)
55           if real_path in exclude_files:
56             continue
57           aar_file.write(real_path, zip_path)
58
59   return 0
60
61
62 if __name__ == '__main__':
63   sys.exit(main())