Upstream version 10.38.208.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     (os.path.join(jar_src_dir, 'xwalk_app_runtime_java.jar'), jar_target_dir),
53
54     # XWalk Core Library
55     (xwalk_core_library_dir, os.path.join(target_dir, 'xwalk_core_library')),
56
57     # Build and python tools.
58     (os.path.join(tools_src_dir, 'ant', 'xwalk-debug.keystore'), target_dir),
59     (os.path.join(tools_src_dir, 'app_info.py'), target_dir),
60     (os.path.join(tools_src_dir, 'compress_js_and_css.py'), target_dir),
61     (os.path.join(tools_src_dir, 'customize.py'), target_dir),
62     (os.path.join(tools_src_dir, 'customize_launch_screen.py'), target_dir),
63     (os.path.join(tools_src_dir, 'extension_manager.py'), target_dir),
64     (os.path.join(tools_src_dir, 'handle_permissions.py'), target_dir),
65     (os.path.join(tools_src_dir, 'handle_xml.py'), target_dir),
66     (os.path.join(tools_src_dir, 'make_apk.py'), target_dir),
67     (os.path.join(tools_src_dir, 'manifest_json_parser.py'), target_dir),
68     (os.path.join(tools_src_dir, 'parse_xpk.py'), target_dir),
69     (os.path.join(tools_src_dir, 'util.py'), target_dir)
70   ]
71
72   for index in range(len(source_target_list)):
73     source_path, target_path = source_target_list[index]
74
75     # Process source.
76     if not os.path.exists(source_path):
77       print ('The source path "%s" does not exist.' % source_path)
78       continue
79
80     source_is_file = os.path.isfile(source_path)
81
82     # Process target.
83     if source_is_file and not os.path.exists(target_path):
84       os.makedirs(target_path)
85     if not source_is_file and os.path.isdir(target_path):
86       shutil.rmtree(target_path)
87
88     # Do copy.
89     if source_is_file:
90       shutil.copy(source_path, target_path)
91     else:
92       shutil.copytree(source_path, target_path)
93
94   # Remove unused files.
95   mode = os.path.basename(os.path.dirname(target_dir))
96   RemoveUnusedFilesInReleaseMode(mode, os.path.join(target_dir, 'native_libs'))
97
98
99 def main(args):
100   if len(args) != 1:
101     print 'You must provide only one argument: folder to update'
102     return 1
103   target_dir = args[0]
104   src_dir = os.path.dirname(target_dir)
105   Clean(target_dir)
106   PrepareFromXwalk(src_dir, target_dir)
107
108
109 if __name__ == '__main__':
110   sys.exit(main(sys.argv[1:]))