Upstream version 9.38.204.0
[platform/framework/web/crosswalk.git] / src / xwalk / build / android / generate_app_packaging_tool.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2013 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 # pylint: disable=F0401
7
8 import os
9 import shutil
10 import sys
11 from common_function import RemoveUnusedFilesInReleaseMode
12
13 def Clean(dir_to_clean):
14   if os.path.isdir(dir_to_clean):
15     shutil.rmtree(dir_to_clean)
16
17
18 def PrepareFromXwalk(src_dir, target_dir):
19   '''Prepare different files for app packaging tools. All resources are used by
20   make_apk.py.
21   '''
22   # The version of yui compressor.
23   yui_compressor_version = '2.4.8'
24
25   # Get the dir of source code from src_dir: ../../.
26   source_code_dir = os.path.dirname(os.path.dirname(src_dir))
27
28   # The directory to copy libraries and code from.
29   jar_src_dir = os.path.join(src_dir, 'lib.java')
30   xwalk_core_library_dir = os.path.join(src_dir, 'xwalk_core_library')
31
32   # The directory to copy libraries, code and resources to.
33   app_target_dir = os.path.join(target_dir, 'template')
34   jar_target_dir = os.path.join(app_target_dir, 'libs')
35
36   # The directory for source packaging tools.
37   tools_src_dir = os.path.join(source_code_dir, 'xwalk/app/tools/android')
38
39   # The source file/directory list to be copied and the target directory list.
40   source_target_list = [
41     (os.path.join(source_code_dir, 'xwalk/VERSION'), target_dir),
42
43     # This jar is needed for minifying and obfuscating the javascript and css.
44     (os.path.join(tools_src_dir,
45                   'libs/yuicompressor-%s.jar' % yui_compressor_version),
46      target_dir),
47
48     # The app wrapper code. It's the template Java code.
49     (os.path.join(source_code_dir, 'xwalk/app/android/app_template'),
50      app_target_dir),
51
52     # Shared mode uses xwalk_app_runtime_java.jar only.
53     # Embedded mode needs both.
54     (os.path.join(jar_src_dir, 'xwalk_app_runtime_java.jar'), jar_target_dir),
55     (os.path.join(jar_src_dir, 'xwalk_runtime_java.jar'), jar_target_dir),
56
57     # XWalk Core Library
58     (xwalk_core_library_dir, os.path.join(target_dir, 'xwalk_core_library')),
59
60     # Build and python tools.
61     (os.path.join(tools_src_dir, 'ant', 'xwalk-debug.keystore'), target_dir),
62     (os.path.join(tools_src_dir, 'app_info.py'), target_dir),
63     (os.path.join(tools_src_dir, 'compress_js_and_css.py'), target_dir),
64     (os.path.join(tools_src_dir, 'customize.py'), target_dir),
65     (os.path.join(tools_src_dir, 'customize_launch_screen.py'), target_dir),
66     (os.path.join(tools_src_dir, 'extension_manager.py'), target_dir),
67     (os.path.join(tools_src_dir, 'handle_permissions.py'), target_dir),
68     (os.path.join(tools_src_dir, 'handle_xml.py'), target_dir),
69     (os.path.join(tools_src_dir, 'make_apk.py'), target_dir),
70     (os.path.join(tools_src_dir, 'manifest_json_parser.py'), target_dir),
71     (os.path.join(tools_src_dir, 'parse_xpk.py'), target_dir),
72     (os.path.join(tools_src_dir, 'util.py'), target_dir)
73   ]
74
75   for index in range(len(source_target_list)):
76     source_path, target_path = source_target_list[index]
77
78     # Process source.
79     if not os.path.exists(source_path):
80       print ('The source path "%s" does not exist.' % source_path)
81       continue
82
83     source_is_file = os.path.isfile(source_path)
84
85     # Process target.
86     if source_is_file and not os.path.exists(target_path):
87       os.makedirs(target_path)
88     if not source_is_file and os.path.isdir(target_path):
89       shutil.rmtree(target_path)
90
91     # Do copy.
92     if source_is_file:
93       shutil.copy(source_path, target_path)
94     else:
95       shutil.copytree(source_path, target_path)
96
97   # Remove unused files.
98   mode = os.path.basename(os.path.dirname(target_dir))
99   RemoveUnusedFilesInReleaseMode(mode, os.path.join(target_dir, 'native_libs'))
100
101
102 def main(args):
103   if len(args) != 1:
104     print 'You must provide only one argument: folder to update'
105     return 1
106   target_dir = args[0]
107   src_dir = os.path.dirname(target_dir)
108   Clean(target_dir)
109   PrepareFromXwalk(src_dir, target_dir)
110
111
112 if __name__ == '__main__':
113   sys.exit(main(sys.argv[1:]))