def packExtension(build_json=None, app_src=None, app_dest=None, app_name=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") BUILD_ROOT_SRC = varshop.getValue("BUILD_ROOT_SRC") BUILD_TIME= varshop.getValue("BUILD_TIME") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") PKG_MODES= varshop.getValue("PKG_MODES") PKG_ARCHS= varshop.getValue("PKG_ARCHS") app_name = app_name.replace("-", "_") if not os.path.exists(os.path.join(BUILD_ROOT, "crosswalk")): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "crosswalk"), os.path.join(BUILD_ROOT, "crosswalk")): return False files = glob.glob(os.path.join(BUILD_ROOT, "crosswalk", "*.apk")) if files: if not utils.doRemove(files): return False ext_src = "" ext_output = "" ext_jar_name = "" tmp_opt = utils.safelyGetValue(build_json, "apk-ext-src") if tmp_opt: ext_src = os.path.join(BUILD_ROOT_SRC, tmp_opt) if not os.path.exists(os.path.join(ext_src, "libs")): try: os.makedirs(os.path.join(ext_src, "libs")) except Exception as e: LOG.error("Fail to init extension libs dir: %s" % e) return False tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_output = os.path.join(app_src, tmp_opt) if not os.path.exists(ext_output): try: os.makedirs(ext_output) except Exception as e: LOG.error("Fail to init extension output dir: %s" % e) return False ext_jar_name = ext_output.split("/")[-1] if not os.path.exists(os.path.join(BUILD_ROOT, "crosswalk", "xwalk_core_library", "libs", "xwalk_core_library_java.jar")): return False if not utils.doCopy( os.path.join(BUILD_ROOT, "crosswalk", "xwalk_core_library", "libs", "xwalk_core_library_java.jar"), os.path.join(ext_src, "libs")): return False orig_dir = os.getcwd() os.chdir(ext_src) (return_code, output) = utils.doCMDWithOutput("android list target", DEFAULT_CMD_TIMEOUT) api_level = "" for line in output: if "API level:" in line: api_level = line.split(":")[1].strip() if not api_level: LOG.error("Fail to get Android API Level") os.chdir(orig_dir) return False android_project_cmd = "android update project --target android-%s --path %s" % ( api_level, ext_src) if not utils.doCMD(android_project_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False LOG.info("Extension release extension jar start ...") ant_cmd = "ant release -Dandroid.library=true" if not utils.doCMD(ant_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False if not os.path.exists(os.path.join(ext_src, "bin", "classes.jar")): LOG.error("Fail to release the extension jar file") os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(ext_src, "bin", "classes.jar"), os.path.join(ext_output, "%s.jar" % ext_jar_name)): os.chdir(orig_dir) return False if not os.path.exists(os.path.join(ext_src, "%s.json" % ext_jar_name)): os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(ext_src, "%s.json" % ext_jar_name), os.path.join(ext_output, "%s.json" % ext_jar_name)): os.chdir(orig_dir) return False if os.path.exists(os.path.join(ext_src, "js", "%s.js" % ext_jar_name)): if not utils.doCopy( os.path.join(ext_src, "js", "%s.js" % ext_jar_name), os.path.join(ext_output, "%s.js" % ext_jar_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packEmbeddingAPI_ant(build_json=None, app_src=None, app_dest=None, app_name=None, app_version=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION") DEFAULT_CMD_TIMEOUT = varshop.getValue("DEFAULT_CMD_TIMEOUT") app_name = app_name.replace("-", "_") library_dir_name = utils.safelyGetValue(build_json, "embeddingapi-library-name") if not library_dir_name: LOG.error("Fail to get embeddingapi-library-name ...") return False new_library_dir_name = "core_library" pack_tool = os.path.join(app_src, "..", new_library_dir_name) if os.path.exists(pack_tool): if not utils.doRemove([pack_tool]): return False if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, library_dir_name), pack_tool): return False if os.path.exists(os.path.join(pack_tool, "bin", "res", "crunch")): if not utils.doRemove( [os.path.join(pack_tool, "bin", "res", "crunch")]): return False orig_dir = os.getcwd() android_project_path = os.path.join(app_src, "android-project") try: os.makedirs(android_project_path) except Exception as e: LOG.error("Fail to create tmp project dir: %s" % e) return False (return_code, output) = utils.doCMDWithOutput("android list target", DEFAULT_CMD_TIMEOUT) api_level = "" for line in output: if "API level:" in line: api_level = line.split(":")[1].strip() if not api_level: LOG.error("Fail to get Android API Level") os.chdir(orig_dir) return False android_project_cmd = "android create project --name %s --target " \ "android-%s --path %s --package com.%s " \ "--activity MainActivity" % ( app_name, api_level, android_project_path, app_name) if not utils.doCMD(android_project_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False try: update_file = open( os.path.join(android_project_path, "project.properties"), "a+") update_file.writelines("{0}\n".format( "android.library.reference.1=../%s" % new_library_dir_name)) update_file.close() except Exception as e: LOG.error( "Fail to update %s: %s" % (os.path.join(android_project_path, "project.properties"), e)) os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(android_project_path, "build.xml"), os.path.join(app_src, "build.xml")): os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(android_project_path, "project.properties"), os.path.join(app_src, "project.properties")): os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(android_project_path, "local.properties"), os.path.join(app_src, "local.properties")): os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(android_project_path, "local.properties"), os.path.join(pack_tool, "local.properties")): os.chdir(orig_dir) return False release_mode_tmp = "release" if BUILD_PARAMETERS.bnotdebug: LOG.info("Package release mode pkg start ...") ant_cmd = ["ant", "release", '-f', os.path.join(app_src, 'build.xml')] key_store = os.path.join(BUILD_PARAMETERS.pkgpacktools, 'crosswalk', 'xwalk-debug.keystore') if not os.path.exists(key_store): LOG.error( "Need to copy xwalk-debug.keystore file from Crosswalk-<version> to crosswalk-test-suite/tools/crosswalk" ) return False ant_cmd.extend(['-Dkey.store=%s' % os.path.abspath(key_store)]) ant_cmd.extend(['-Dkey.alias=xwalkdebugkey']) ant_cmd.extend(['-Dkey.store.password=xwalkdebug']) ant_cmd.extend(['-Dkey.alias.password=xwalkdebug']) ant_result = subprocess.call(ant_cmd) if ant_result != 0: os.chdir(orig_dir) return False else: LOG.info("Package debug mode pkg start ...") os.chdir(app_src) if not utils.doCMD("ant debug", DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False release_mode_tmp = "debug" if not utils.doCopy( os.path.join(app_src, "bin", "%s-%s.apk" % (app_name, release_mode_tmp)), os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packEmbeddingAPI_ant( build_json=None, app_src=None, app_dest=None, app_name=None, app_version=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") app_name = app_name.replace("-", "_") library_dir_name = utils.safelyGetValue(build_json, "embeddingapi-library-name") if not library_dir_name: LOG.error("Fail to get embeddingapi-library-name ...") return False new_library_dir_name = "core_library" pack_tool = os.path.join(app_src, "..", new_library_dir_name) if os.path.exists(pack_tool): if not utils.doRemove([pack_tool]): return False if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, library_dir_name), pack_tool): return False if os.path.exists(os.path.join(pack_tool, "bin", "res", "crunch")): if not utils.doRemove([os.path.join(pack_tool, "bin", "res", "crunch")]): return False orig_dir = os.getcwd() android_project_path = os.path.join(app_src, "android-project") try: os.makedirs(android_project_path) except Exception as e: LOG.error("Fail to create tmp project dir: %s" % e) return False (return_code, output) = utils.doCMDWithOutput("android list target", DEFAULT_CMD_TIMEOUT) api_level = "" for line in output: if "API level:" in line: api_level = line.split(":")[1].strip() if not api_level: LOG.error("Fail to get Android API Level") os.chdir(orig_dir) return False android_project_cmd = "android create project --name %s --target " \ "android-%s --path %s --package com.%s " \ "--activity MainActivity" % ( app_name, api_level, android_project_path, app_name) if not utils.doCMD(android_project_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False try: update_file = open( os.path.join(android_project_path, "project.properties"), "a+") update_file.writelines( "{0}\n".format( "android.library.reference.1=../%s" % new_library_dir_name)) update_file.close() except Exception as e: LOG.error( "Fail to update %s: %s" % (os.path.join( android_project_path, "project.properties"), e)) os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(android_project_path, "build.xml"), os.path.join(app_src, "build.xml")): os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(android_project_path, "project.properties"), os.path.join(app_src, "project.properties")): os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(android_project_path, "local.properties"), os.path.join(app_src, "local.properties")): os.chdir(orig_dir) return False if not utils.doCopy( os.path.join(android_project_path, "local.properties"), os.path.join(pack_tool, "local.properties")): os.chdir(orig_dir) return False release_mode_tmp = "release" if BUILD_PARAMETERS.bnotdebug: LOG.info("Package release mode pkg start ...") ant_cmd = ["ant", "release", '-f', os.path.join(app_src, 'build.xml')] key_store = os.path.join(BUILD_PARAMETERS.pkgpacktools, 'crosswalk', 'xwalk-debug.keystore') if not os.path.exists(key_store): LOG.error("Need to copy xwalk-debug.keystore file from Crosswalk-<version> to crosswalk-test-suite/tools/crosswalk") return False ant_cmd.extend(['-Dkey.store=%s' % os.path.abspath(key_store)]) ant_cmd.extend(['-Dkey.alias=xwalkdebugkey']) ant_cmd.extend(['-Dkey.store.password=xwalkdebug']) ant_cmd.extend(['-Dkey.alias.password=xwalkdebug']) ant_result = subprocess.call(ant_cmd) if ant_result != 0: os.chdir(orig_dir) return False else: LOG.info("Package debug mode pkg start ...") os.chdir(app_src) if not utils.doCMD("ant debug", DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False release_mode_tmp = "debug" if not utils.doCopy( os.path.join(app_src, "bin", "%s-%s.apk" % (app_name, release_mode_tmp)), os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packExtension(build_json=None, app_src=None, app_dest=None, app_name=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") BUILD_ROOT_SRC = varshop.getValue("BUILD_ROOT_SRC") BUILD_TIME = varshop.getValue("BUILD_TIME") DEFAULT_CMD_TIMEOUT = varshop.getValue("DEFAULT_CMD_TIMEOUT") PKG_MODES = varshop.getValue("PKG_MODES") PKG_ARCHS = varshop.getValue("PKG_ARCHS") app_name = app_name.replace("-", "_") if not os.path.exists(os.path.join(BUILD_ROOT, "crosswalk")): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "crosswalk"), os.path.join(BUILD_ROOT, "crosswalk")): return False files = glob.glob(os.path.join(BUILD_ROOT, "crosswalk", "*.apk")) if files: if not utils.doRemove(files): return False ext_src = "" ext_output = "" ext_jar_name = "" tmp_opt = utils.safelyGetValue(build_json, "apk-ext-src") if tmp_opt: ext_src = os.path.join(BUILD_ROOT_SRC, tmp_opt) if not os.path.exists(os.path.join(ext_src, "libs")): try: os.makedirs(os.path.join(ext_src, "libs")) except Exception as e: LOG.error("Fail to init extension libs dir: %s" % e) return False tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_output = os.path.join(app_src, tmp_opt) if not os.path.exists(ext_output): try: os.makedirs(ext_output) except Exception as e: LOG.error("Fail to init extension output dir: %s" % e) return False ext_jar_name = ext_output.split("/")[-1] if not os.path.exists( os.path.join(BUILD_ROOT, "crosswalk", "xwalk_core_library", "libs", "xwalk_core_library_java.jar")): return False if not utils.doCopy( os.path.join(BUILD_ROOT, "crosswalk", "xwalk_core_library", "libs", "xwalk_core_library_java.jar"), os.path.join(ext_src, "libs")): return False orig_dir = os.getcwd() os.chdir(ext_src) (return_code, output) = utils.doCMDWithOutput("android list target", DEFAULT_CMD_TIMEOUT) api_level = "" for line in output: if "API level:" in line: api_level = line.split(":")[1].strip() if not api_level: LOG.error("Fail to get Android API Level") os.chdir(orig_dir) return False android_project_cmd = "android update project --target android-%s --path %s" % ( api_level, ext_src) if not utils.doCMD(android_project_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False LOG.info("Extension release extension jar start ...") ant_cmd = "ant release -Dandroid.library=true" if not utils.doCMD(ant_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False if not os.path.exists(os.path.join(ext_src, "bin", "classes.jar")): LOG.error("Fail to release the extension jar file") os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(ext_src, "bin", "classes.jar"), os.path.join(ext_output, "%s.jar" % ext_jar_name)): os.chdir(orig_dir) return False if not os.path.exists(os.path.join(ext_src, "%s.json" % ext_jar_name)): os.chdir(orig_dir) return False if not utils.doCopy(os.path.join(ext_src, "%s.json" % ext_jar_name), os.path.join(ext_output, "%s.json" % ext_jar_name)): os.chdir(orig_dir) return False if os.path.exists(os.path.join(ext_src, "js", "%s.js" % ext_jar_name)): if not utils.doCopy( os.path.join(ext_src, "js", "%s.js" % ext_jar_name), os.path.join(ext_output, "%s.js" % ext_jar_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True