Upstream version 8.37.180.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 PrepareFromChromium(target_dir):
19   gyp_dir =  os.path.join(target_dir, 'scripts', 'gyp')
20   if not os.path.exists(gyp_dir):
21     os.makedirs(gyp_dir)
22   shutil.copytree('../build/android/gyp/util', os.path.join(gyp_dir, 'util'))
23
24
25 def PrepareFromXwalk(src_dir, target_dir):
26   '''Prepare different files for app packaging tools. All resources are used by
27   make_apk.py.
28   '''
29   # The version of yui compressor.
30   yui_compressor_version = '2.4.8'
31
32   # Get the dir of source code from src_dir: ../../.
33   source_code_dir = os.path.dirname(os.path.dirname(src_dir))
34
35   # The directories for source and target .jar files.
36   jar_src_dir = os.path.join(src_dir, 'lib.java')
37   jar_target_dir = os.path.join(target_dir, 'libs')
38
39   # The directories for generated resources.
40   gen_res_src_dir = os.path.join(src_dir, 'gen')
41   gen_res_target_dir = os.path.join(target_dir, 'gen')
42   xwalk_core_library_res_dir = os.path.join(
43       src_dir, 'xwalk_core_library', 'res')
44
45   # The directory for source packaging tools.
46   tools_src_dir = os.path.join(source_code_dir, 'xwalk/app/tools/android')
47
48   # The directories for source and target gyp.
49   gyp_src_dir =  os.path.join(tools_src_dir, 'gyp')
50   gyp_target_dir = os.path.join(target_dir, 'scripts/gyp')
51
52   # The source file/directory list to be copied and the target directory list.
53   source_target_list = [
54     (os.path.join(source_code_dir, 'xwalk/VERSION'), target_dir),
55
56     # This jar is needed for minifying and obfuscating the javascript and css.
57     (os.path.join(tools_src_dir,
58       'libs/yuicompressor-' + yui_compressor_version + '.jar'),
59         jar_target_dir),
60
61     # This jar is needed for 'javac' compile.
62     (os.path.join(jar_src_dir, 'xwalk_app_runtime_java.jar'), jar_target_dir),
63     (os.path.join(jar_src_dir, 'xwalk_runtime_embedded.dex.jar'),
64       jar_target_dir),
65
66     # Native library, like libxwalkcore.so.
67     (os.path.join(src_dir, 'xwalk_runtime_lib_apk/libs/x86'),
68      os.path.join(target_dir, 'native_libs/x86/libs/x86')),
69     (os.path.join(src_dir, 'xwalk_runtime_lib_apk/libs/armeabi-v7a'),
70      os.path.join(target_dir, 'native_libs/armeabi-v7a/libs/armeabi-v7a')),
71
72     # Native source package(xwalk.pak) and related js files for extension.
73     (os.path.join(src_dir, 'xwalk_runtime_lib/assets'),
74      os.path.join(target_dir, 'native_libs_res')),
75
76     # Various Java resources.
77     # FIXME(wang16): Copy from the xwalk_core_library first. We need to
78     # consider refine the whole process of make_apk.
79     (os.path.join(gen_res_src_dir, 'ui_java/java_R'),
80      os.path.join(gen_res_target_dir, 'ui_java/java_R')),
81     (os.path.join(gen_res_src_dir, 'content_java/java_R'),
82      os.path.join(gen_res_target_dir, 'content_java/java_R')),
83     (os.path.join(gen_res_src_dir, 'xwalk_core_internal_java/java_R'),
84      os.path.join(gen_res_target_dir, 'xwalk_core_internal_java/java_R')),
85     (xwalk_core_library_res_dir,
86      os.path.join(target_dir, 'libs_res/xwalk_core_library')),
87
88     # The app wrapper code. It's the template Java code.
89     (os.path.join(source_code_dir, 'xwalk/app/android/app_template'),
90      os.path.join(target_dir, 'app_src')),
91
92     # Copy below 7 files to overwrite the existing ones from Chromium.
93     (os.path.join(gyp_src_dir, 'util/build_utils.py'),
94      os.path.join(gyp_target_dir, 'util')),
95     (os.path.join(gyp_src_dir, 'util/md5_check.py'),
96      os.path.join(gyp_target_dir, 'util')),
97     (os.path.join(gyp_src_dir, 'ant.py'), gyp_target_dir),
98     (os.path.join(gyp_src_dir, 'dex.py'), gyp_target_dir),
99     (os.path.join(gyp_src_dir, 'finalize_apk.py'), gyp_target_dir),
100     (os.path.join(gyp_src_dir, 'jar.py'), gyp_target_dir),
101     (os.path.join(gyp_src_dir, 'javac.py'), gyp_target_dir),
102
103     # Build and python tools.
104     (os.path.join(tools_src_dir, 'ant'),
105      os.path.join(target_dir, 'scripts/ant')),
106     (os.path.join(tools_src_dir, 'app_info.py'), target_dir),
107     (os.path.join(tools_src_dir, 'compress_js_and_css.py'), target_dir),
108     (os.path.join(tools_src_dir, 'customize.py'), target_dir),
109     (os.path.join(tools_src_dir, 'customize_launch_screen.py'), target_dir),
110     (os.path.join(tools_src_dir, 'handle_permissions.py'), target_dir),
111     (os.path.join(tools_src_dir, 'handle_xml.py'), target_dir),
112     (os.path.join(tools_src_dir, 'make_apk.py'), target_dir),
113     (os.path.join(tools_src_dir, 'manifest_json_parser.py'), target_dir),
114     (os.path.join(tools_src_dir, 'parse_xpk.py'), target_dir)
115   ]
116
117   for index in range(len(source_target_list)):
118     source_path, target_path = source_target_list[index]
119
120     # Process source.
121     if not os.path.exists(source_path):
122       print ('The source path "%s" does not exist.' % source_path)
123       continue
124
125     source_is_file = os.path.isfile(source_path)
126
127     # Process target.
128     if source_is_file and not os.path.exists(target_path):
129       os.makedirs(target_path)
130
131     # Do copy.
132     if source_is_file:
133       shutil.copy(source_path, target_path)
134     else:
135       shutil.copytree(source_path, target_path)
136
137   # Remove unused files.
138   mode = os.path.basename(os.path.dirname(target_dir))
139   RemoveUnusedFilesInReleaseMode(mode, os.path.join(target_dir, 'native_libs'))
140
141
142 def main(args):
143   if len(args) != 1:
144     print 'You must provide only one argument: folder to update'
145     return 1
146   target_dir = args[0]
147   src_dir = os.path.dirname(target_dir)
148   Clean(target_dir)
149   PrepareFromChromium(target_dir)
150   PrepareFromXwalk(src_dir, target_dir)
151
152
153 if __name__ == '__main__':
154   sys.exit(main(sys.argv[1:]))