Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / xwalk / build / android / generate_xwalk_core_library.py
index fee3ee5..61f8d43 100755 (executable)
@@ -11,6 +11,7 @@ import os
 import shutil
 import sys
 from common_function import RemoveUnusedFilesInReleaseMode
+from xml.dom.minidom import Document
 
 LIBRARY_PROJECT_NAME = 'xwalk_core_library'
 XWALK_CORE_SHELL_APK = 'xwalk_core_shell_apk'
@@ -24,8 +25,8 @@ def AddGeneratorOptions(option_parser):
                            type='string')
 
 
-def CleanLibraryProject(out_directory):
-  out_project_path = os.path.join(out_directory, LIBRARY_PROJECT_NAME)
+def CleanLibraryProject(out_dir):
+  out_project_path = os.path.join(out_dir, LIBRARY_PROJECT_NAME)
   if os.path.exists(out_project_path):
     for item in os.listdir(out_project_path):
       sub_path = os.path.join(out_project_path, item)
@@ -35,14 +36,14 @@ def CleanLibraryProject(out_directory):
         os.remove(sub_path)
 
 
-def CopyProjectFiles(project_source, out_directory):
+def CopyProjectFiles(project_source, out_dir):
   """cp xwalk/build/android/xwalkcore_library_template/<file>
         out/Release/xwalk_core_library/<file>
   """
 
   print 'Copying library project files...'
-  template_folder = os.path.join(project_source, 'xwalk', 'build', 'android',
-                                 'xwalkcore_library_template')
+  template_dir = os.path.join(project_source, 'xwalk', 'build', 'android',
+                              'xwalkcore_library_template')
   files_to_copy = [
       # AndroidManifest.xml from template.
       'AndroidManifest.xml',
@@ -54,22 +55,22 @@ def CopyProjectFiles(project_source, out_directory):
       'ant.properties',
   ]
   for f in files_to_copy:
-    source_file = os.path.join(template_folder, f)
-    target_file = os.path.join(out_directory, LIBRARY_PROJECT_NAME, f)
+    source_file = os.path.join(template_dir, f)
+    target_file = os.path.join(out_dir, LIBRARY_PROJECT_NAME, f)
 
     shutil.copy2(source_file, target_file)
 
 
-def CopyJavaSources(project_source, out_directory):
+def CopyJavaSources(project_source, out_dir):
   """cp <path>/java/src/<package>
         out/Release/xwalk_core_library/src/<package>
   """
 
   print 'Copying Java sources...'
-  target_source_directory = os.path.join(
-      out_directory, LIBRARY_PROJECT_NAME, 'src')
-  if not os.path.exists(target_source_directory):
-    os.makedirs(target_source_directory)
+  target_source_dir = os.path.join(
+      out_dir, LIBRARY_PROJECT_NAME, 'src')
+  if not os.path.exists(target_source_dir):
+    os.makedirs(target_source_dir)
 
   # FIXME(wang16): There is an assumption here the package names listed
   # here are all beginned with "org". If the assumption is broken in
@@ -103,7 +104,7 @@ def CopyJavaSources(project_source, out_directory):
       raise Exception('Invalid java source path: %s' % source)
     source_path = os.path.join(project_source, source)
     package_path = source[slash_org_pos+1:]
-    target_path = os.path.join(target_source_directory, package_path)
+    target_path = os.path.join(target_source_dir, package_path)
     if os.path.isfile(source_path):
       if not os.path.isdir(os.path.dirname(target_path)):
         os.makedirs(os.path.dirname(target_path))
@@ -112,20 +113,21 @@ def CopyJavaSources(project_source, out_directory):
       shutil.copytree(source_path, target_path)
 
 
-def CopyGeneratedSources(out_directory):
+def CopyGeneratedSources(out_dir):
   """cp out/Release/gen/templates/<path>
         out/Release/xwalk_core_library/src/<path>
      cp out/Release/xwalk_core_shell_apk/
             native_libraries_java/NativeLibraries.java
         out/Release/xwalk_core_library/src/org/
-            chromium/content/app/NativeLibraries.java
+            chromium/base/library_loader/NativeLibraries.java
   """
 
   print 'Copying generated source files...'
   generated_srcs_to_copy = [
       'org/chromium/base/ActivityState.java',
       'org/chromium/base/MemoryPressureLevelList.java',
-      'org/chromium/content/app/NativeLibraries.java',
+      'org/chromium/base/library_loader/NativeLibraries.java',
+      'org/chromium/content/browser/GestureEventType.java',
       'org/chromium/content/browser/input/PopupItemType.java',
       'org/chromium/content/browser/PageTransitionTypes.java',
       'org/chromium/content/browser/SpeechRecognitionError.java',
@@ -140,27 +142,27 @@ def CopyGeneratedSources(out_directory):
   ]
 
   for source in generated_srcs_to_copy:
-    source_file = os.path.join(out_directory, 'gen', 'templates', source)
+    source_file = os.path.join(out_dir, 'gen', 'templates', source)
     target_file = os.path.join(
-        out_directory, LIBRARY_PROJECT_NAME, 'src', source)
+        out_dir, LIBRARY_PROJECT_NAME, 'src', source)
     shutil.copyfile(source_file, target_file)
 
-  source_file = os.path.join(out_directory, XWALK_CORE_SHELL_APK,
+  source_file = os.path.join(out_dir, XWALK_CORE_SHELL_APK,
                              'native_libraries_java',
                              'NativeLibraries.java')
-  target_file = os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'src', 'org',
-                             'chromium', 'content',
-                             'app', 'NativeLibraries.java')
+  target_file = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'src', 'org',
+                             'chromium', 'base', 'library_loader',
+                             'NativeLibraries.java')
   shutil.copyfile(source_file, target_file)
 
-def CopyJSBindingFiles(project_source, out_directory):
+def CopyJSBindingFiles(project_source, out_dir):
   print 'Copying js binding files...'
-  jsapi_directory = os.path.join(out_directory,
-                                 LIBRARY_PROJECT_NAME,
-                                 'res',
-                                 'raw')
-  if not os.path.exists(jsapi_directory):
-    os.makedirs(jsapi_directory)
+  jsapi_dir = os.path.join(out_dir,
+                           LIBRARY_PROJECT_NAME,
+                           'res',
+                           'raw')
+  if not os.path.exists(jsapi_dir):
+    os.makedirs(jsapi_dir)
 
   jsfiles_to_copy = [
       'xwalk/experimental/launch_screen/launch_screen_api.js',
@@ -172,12 +174,12 @@ def CopyJSBindingFiles(project_source, out_directory):
   # Copy JS binding file to assets/jsapi folder.
   for jsfile in jsfiles_to_copy:
     source_file = os.path.join(project_source, jsfile)
-    target_file = os.path.join(jsapi_directory, os.path.basename(source_file))
+    target_file = os.path.join(jsapi_dir, os.path.basename(source_file))
     shutil.copyfile(source_file, target_file)
 
 
-def CopyBinaries(out_directory):
-  """cp out/Release/<asset> out/Release/xwalk_core_library/assets/<asset>
+def CopyBinaries(out_dir):
+  """cp out/Release/<pak> out/Release/xwalk_core_library/res/raw/<pak>
      cp out/Release/lib.java/<lib> out/Release/xwalk_core_library/libs/<lib>
      cp out/Release/xwalk_core_shell_apk/libs/*
         out/Release/xwalk_core_library/libs
@@ -185,23 +187,41 @@ def CopyBinaries(out_directory):
 
   print 'Copying binaries...'
   # Copy assets.
-  asset_directory = os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'assets')
-  if not os.path.exists(asset_directory):
-    os.mkdir(asset_directory)
-
-  assets_to_copy = [
+  res_raw_dir = os.path.join(
+      out_dir, LIBRARY_PROJECT_NAME, 'res', 'raw')
+  res_value_dir = os.path.join(
+      out_dir, LIBRARY_PROJECT_NAME, 'res', 'values')
+  if not os.path.exists(res_raw_dir):
+    os.mkdir(res_raw_dir)
+  if not os.path.exists(res_value_dir):
+    os.mkdir(res_value_dir)
+
+  paks_to_copy = [
       'xwalk.pak',
   ]
 
-  for asset in assets_to_copy:
-    source_file = os.path.join(out_directory, asset)
-    target_file = os.path.join(asset_directory, asset)
+  pak_list_xml = Document()
+  resources_node = pak_list_xml.createElement('resources')
+  string_array_node = pak_list_xml.createElement('string-array')
+  string_array_node.setAttribute('name', 'xwalk_resources_list')
+  pak_list_xml.appendChild(resources_node)
+  resources_node.appendChild(string_array_node)
+  for pak in paks_to_copy:
+    source_file = os.path.join(out_dir, pak)
+    target_file = os.path.join(res_raw_dir, pak)
     shutil.copyfile(source_file, target_file)
+    item_node = pak_list_xml.createElement('item')
+    item_node.appendChild(pak_list_xml.createTextNode(pak))
+    string_array_node.appendChild(item_node)
+  pak_list_file = open(os.path.join(res_value_dir,
+                                    'xwalk_resources_list.xml'), 'w')
+  pak_list_xml.writexml(pak_list_file, newl='\n', encoding='utf-8')
+  pak_list_file.close()
 
   # Copy jar files to libs.
-  libs_directory = os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'libs')
-  if not os.path.exists(libs_directory):
-    os.mkdir(libs_directory)
+  libs_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'libs')
+  if not os.path.exists(libs_dir):
+    os.mkdir(libs_dir)
 
   libs_to_copy = [
       'eyesfree_java.jar',
@@ -210,13 +230,13 @@ def CopyBinaries(out_directory):
   ]
 
   for lib in libs_to_copy:
-    source_file = os.path.join(out_directory, 'lib.java', lib)
-    target_file = os.path.join(libs_directory, lib)
+    source_file = os.path.join(out_dir, 'lib.java', lib)
+    target_file = os.path.join(libs_dir, lib)
     shutil.copyfile(source_file, target_file)
 
   # Copy native libraries.
-  source_dir = os.path.join(out_directory, XWALK_CORE_SHELL_APK, 'libs')
-  target_dir = libs_directory
+  source_dir = os.path.join(out_dir, XWALK_CORE_SHELL_APK, 'libs')
+  target_dir = libs_dir
   distutils.dir_util.copy_tree(source_dir, target_dir)
 
 
@@ -243,11 +263,11 @@ def CopyDirAndPrefixDuplicates(input_dir, output_dir, prefix):
       shutil.copyfile(src_file, target_file)
 
 
-def CopyResources(project_source, out_directory):
+def CopyResources(project_source, out_dir):
   print 'Copying resources...'
-  res_directory = os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'res')
-  if os.path.exists(res_directory):
-    shutil.rmtree(res_directory)
+  res_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'res')
+  if os.path.exists(res_dir):
+    shutil.rmtree(res_dir)
 
   # All resources should be in specific folders in res_directory.
   # Since there might be some resource files with same names from
@@ -264,22 +284,25 @@ def CopyResources(project_source, out_directory):
   # they are res_grit and res_v14_compatibility.
   for res, prefix in res_to_copy:
     res_path_src = os.path.join(project_source, res)
-    res_path_grit = os.path.join(out_directory,
+    res_path_grit = os.path.join(out_dir,
         'gen', '%s_java' % prefix, 'res_grit')
-    res_path_v14 = os.path.join(out_directory,
+    res_path_v14 = os.path.join(out_dir,
         'gen', '%s_java' % prefix, 'res_v14_compatibility')
 
     for res_path in [res_path_src, res_path_grit, res_path_v14]:
-      CopyDirAndPrefixDuplicates(res_path, res_directory, prefix)
+      CopyDirAndPrefixDuplicates(res_path, res_dir, prefix)
 
 
-def PostCopyLibraryProject(out_directory):
+def PostCopyLibraryProject(out_dir):
   print 'Post Copy Library Project...'
-  common_aidl_file = os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'src',
-                                  'org', 'chromium', 'content', 'common',
-                                  'common.aidl')
-  if os.path.exists(common_aidl_file):
-    os.remove(common_aidl_file)
+  aidls_to_remove = [
+      'org/chromium/content/common/common.aidl',
+      'org/chromium/net/IRemoteAndroidKeyStoreInterface.aidl',
+  ]
+  for aidl in aidls_to_remove:
+    aidl_file = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'src', aidl)
+    if os.path.exists(aidl_file):
+      os.remove(aidl_file)
 
 
 def main(argv):
@@ -291,33 +314,33 @@ def main(argv):
   if not os.path.exists(options.source):
     print 'Source project does not exist, please provide correct directory.'
     sys.exit(1)
-  out_directory = options.target
+  out_dir = options.target
 
   # Clean directory for project first.
-  CleanLibraryProject(out_directory)
+  CleanLibraryProject(out_dir)
 
-  out_project_directory = os.path.join(out_directory, LIBRARY_PROJECT_NAME)
-  if not os.path.exists(out_project_directory):
-    os.mkdir(out_project_directory)
+  out_project_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME)
+  if not os.path.exists(out_project_dir):
+    os.mkdir(out_project_dir)
 
   # Copy Eclipse project files of library project.
-  CopyProjectFiles(options.source, out_directory)
+  CopyProjectFiles(options.source, out_dir)
   # Copy Java sources of chromium and xwalk.
-  CopyJavaSources(options.source, out_directory)
-  CopyGeneratedSources(out_directory)
+  CopyJavaSources(options.source, out_dir)
+  CopyGeneratedSources(out_dir)
   # Copy binaries and resuorces.
-  CopyBinaries(out_directory)
-  CopyResources(options.source, out_directory)
+  CopyResources(options.source, out_dir)
+  CopyBinaries(out_dir)
   # Copy JS API binding files.
-  CopyJSBindingFiles(options.source, out_directory)
+  CopyJSBindingFiles(options.source, out_dir)
   # Post copy library project.
-  PostCopyLibraryProject(out_directory)
+  PostCopyLibraryProject(out_dir)
   # Remove unused files.
-  mode = os.path.basename(os.path.normpath(out_directory))
+  mode = os.path.basename(os.path.normpath(out_dir))
   RemoveUnusedFilesInReleaseMode(mode,
-        os.path.join(out_directory, LIBRARY_PROJECT_NAME, 'libs'))
+      os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'libs'))
   print 'Your Android library project has been created at %s' % (
-      out_project_directory)
+      out_project_dir)
 
 if __name__ == '__main__':
   sys.exit(main(sys.argv))