e501026611a035994d0347fe03fe1594a465d6c5
[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
43   # The directory for source packaging tools.
44   tools_src_dir = os.path.join(source_code_dir, 'xwalk/app/tools/android')
45
46   # The directories for source and target gyp.
47   gyp_src_dir =  os.path.join(tools_src_dir, 'gyp')
48   gyp_target_dir = os.path.join(target_dir, 'scripts/gyp')
49
50   # The source file/directory list to be copied and the target directory list.
51   source_target_list = [
52     (os.path.join(source_code_dir, 'xwalk/VERSION'), target_dir),
53
54     # This jar is needed for minifying and obfuscating the javascript and css.
55     (os.path.join(tools_src_dir,
56       'libs/yuicompressor-' + yui_compressor_version + '.jar'),
57         jar_target_dir),
58
59     # This jar is needed for 'javac' compile.
60     (os.path.join(jar_src_dir, 'xwalk_app_runtime_java.jar'), jar_target_dir),
61     (os.path.join(jar_src_dir, 'xwalk_runtime_embedded.dex.jar'),
62       jar_target_dir),
63
64     # Native library, like libxwalkcore.so.
65     (os.path.join(src_dir, 'xwalk_runtime_lib_apk/libs/x86'),
66      os.path.join(target_dir, 'native_libs/x86/libs/x86')),
67     (os.path.join(src_dir, 'xwalk_runtime_lib_apk/libs/armeabi-v7a'),
68      os.path.join(target_dir, 'native_libs/armeabi-v7a/libs/armeabi-v7a')),
69
70     # Native source package(xwalk.pak) and related js files for extension.
71     (os.path.join(src_dir, 'xwalk_runtime_lib/assets'),
72      os.path.join(target_dir, 'native_libs_res')),
73
74     # Various Java resources.
75     (os.path.join(source_code_dir, 'content/public/android/java/res'),
76      os.path.join(target_dir, 'libs_res/content')),
77     (os.path.join(source_code_dir, 'ui/android/java/res'),
78      os.path.join(target_dir, 'libs_res/ui')),
79     (os.path.join(source_code_dir, 'xwalk/runtime/android/core/res'),
80      os.path.join(target_dir, 'libs_res/runtime')),
81
82     (os.path.join(gen_res_src_dir, 'ui_java/java_R'),
83      os.path.join(gen_res_target_dir, 'ui_java/java_R')),
84     (os.path.join(gen_res_src_dir, 'ui_java/res_crunched'),
85      os.path.join(gen_res_target_dir, 'ui_java/res_crunched')),
86     (os.path.join(gen_res_src_dir, 'ui_java/res_grit'),
87      os.path.join(gen_res_target_dir, 'ui_java/res_grit')),
88     (os.path.join(gen_res_src_dir, 'ui_java/res_v14_compatibility'),
89      os.path.join(gen_res_target_dir, 'ui_java/res_v14_compatibility')),
90
91     (os.path.join(gen_res_src_dir, 'content_java/java_R'),
92      os.path.join(gen_res_target_dir, 'content_java/java_R')),
93     (os.path.join(gen_res_src_dir, 'content_java/res_crunched'),
94      os.path.join(gen_res_target_dir, 'content_java/res_crunched')),
95     (os.path.join(gen_res_src_dir, 'content_java/res_grit'),
96      os.path.join(gen_res_target_dir, 'content_java/res_grit')),
97     (os.path.join(gen_res_src_dir, 'content_java/res_v14_compatibility'),
98      os.path.join(gen_res_target_dir, 'content_java/res_v14_compatibility')),
99
100     (os.path.join(gen_res_src_dir, 'xwalk_core_java/java_R'),
101      os.path.join(gen_res_target_dir, 'xwalk_core_java/java_R')),
102     (os.path.join(gen_res_src_dir, 'xwalk_core_java/res_crunched'),
103      os.path.join(gen_res_target_dir, 'xwalk_core_java/res_crunched')),
104     (os.path.join(gen_res_src_dir, 'xwalk_core_java/res_grit'),
105      os.path.join(gen_res_target_dir, 'xwalk_core_java/res_grit')),
106     (os.path.join(gen_res_src_dir, 'xwalk_core_java/res_v14_compatibility'),
107      os.path.join(gen_res_target_dir, 'xwalk_core_java/res_v14_compatibility')),
108
109     # The app wrapper code. It's the template Java code.
110     (os.path.join(source_code_dir, 'xwalk/app/android/app_template'),
111      os.path.join(target_dir, 'app_src')),
112
113     # Copy below 7 files to overwrite the existing ones from Chromium.
114     (os.path.join(gyp_src_dir, 'util/build_utils.py'),
115      os.path.join(gyp_target_dir, 'util')),
116     (os.path.join(gyp_src_dir, 'util/md5_check.py'),
117      os.path.join(gyp_target_dir, 'util')),
118     (os.path.join(gyp_src_dir, 'ant.py'), gyp_target_dir),
119     (os.path.join(gyp_src_dir, 'dex.py'), gyp_target_dir),
120     (os.path.join(gyp_src_dir, 'finalize_apk.py'), gyp_target_dir),
121     (os.path.join(gyp_src_dir, 'jar.py'), gyp_target_dir),
122     (os.path.join(gyp_src_dir, 'javac.py'), gyp_target_dir),
123
124     # Build and python tools.
125     (os.path.join(tools_src_dir, 'ant'),
126      os.path.join(target_dir, 'scripts/ant')),
127     (os.path.join(tools_src_dir, 'compress_js_and_css.py'), target_dir),
128     (os.path.join(tools_src_dir, 'customize.py'), target_dir),
129     (os.path.join(tools_src_dir, 'customize_launch_screen.py'), target_dir),
130     (os.path.join(tools_src_dir, 'handle_permissions.py'), target_dir),
131     (os.path.join(tools_src_dir, 'handle_xml.py'), target_dir),
132     (os.path.join(tools_src_dir, 'make_apk.py'), target_dir),
133     (os.path.join(tools_src_dir, 'manifest_json_parser.py'), target_dir),
134     (os.path.join(tools_src_dir, 'parse_xpk.py'), target_dir)
135   ]
136
137   for index in range(len(source_target_list)):
138     source_path, target_path = source_target_list[index]
139
140     # Process source.
141     if not os.path.exists(source_path):
142       print ('The source path "%s" does not exist.' % source_path)
143       continue
144
145     source_is_file = os.path.isfile(source_path)
146
147     # Process target.
148     if source_is_file and not os.path.exists(target_path):
149       os.makedirs(target_path)
150
151     # Do copy.
152     if source_is_file:
153       shutil.copy(source_path, target_path)
154     else:
155       shutil.copytree(source_path, target_path)
156
157   # Remove unused files.
158   mode = os.path.basename(os.path.dirname(target_dir))
159   RemoveUnusedFilesInReleaseMode(mode, os.path.join(target_dir, 'native_libs'))
160
161
162 def main(args):
163   if len(args) != 1:
164     print 'You must provide only one argument: folder to update'
165     return 1
166   target_dir = args[0]
167   src_dir = os.path.dirname(target_dir)
168   Clean(target_dir)
169   PrepareFromChromium(target_dir)
170   PrepareFromXwalk(src_dir, target_dir)
171
172
173 if __name__ == '__main__':
174   sys.exit(main(sys.argv[1:]))