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
11 from common_function import RemoveUnusedFilesInReleaseMode
13 def Clean(dir_to_clean):
14 if os.path.isdir(dir_to_clean):
15 shutil.rmtree(dir_to_clean)
18 def PrepareFromChromium(target_dir):
19 gyp_dir = os.path.join(target_dir, 'scripts', 'gyp')
20 if not os.path.exists(gyp_dir):
22 shutil.copytree('../build/android/gyp/util', os.path.join(gyp_dir, 'util'))
25 def PrepareFromXwalk(src_dir, target_dir):
26 '''Prepare different files for app packaging tools. All resources are used by
29 # The version of yui compressor.
30 yui_compressor_version = '2.4.8'
32 # Get the dir of source code from src_dir: ../../.
33 source_code_dir = os.path.dirname(os.path.dirname(src_dir))
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')
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')
45 # The directory for source packaging tools.
46 tools_src_dir = os.path.join(source_code_dir, 'xwalk/app/tools/android')
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')
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),
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'),
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'),
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')),
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')),
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')),
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')),
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),
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)
117 for index in range(len(source_target_list)):
118 source_path, target_path = source_target_list[index]
121 if not os.path.exists(source_path):
122 print ('The source path "%s" does not exist.' % source_path)
125 source_is_file = os.path.isfile(source_path)
128 if source_is_file and not os.path.exists(target_path):
129 os.makedirs(target_path)
133 shutil.copy(source_path, target_path)
135 shutil.copytree(source_path, target_path)
137 # Remove unused files.
138 mode = os.path.basename(os.path.dirname(target_dir))
139 RemoveUnusedFilesInReleaseMode(mode, os.path.join(target_dir, 'native_libs'))
144 print 'You must provide only one argument: folder to update'
147 src_dir = os.path.dirname(target_dir)
149 PrepareFromChromium(target_dir)
150 PrepareFromXwalk(src_dir, target_dir)
153 if __name__ == '__main__':
154 sys.exit(main(sys.argv[1:]))