def buildSRC(src=None, dest=None, build_json=None): if not os.path.exists(src): LOG.info("+Src dir does not exist, skip build src process ...") return True if not utils.doCopy(src, dest): return False if "blacklist" in build_json: if build_json["blacklist"].count("") > 0: build_json["blacklist"].remove("") black_file_list = [] for i_black in build_json["blacklist"]: black_file_list = black_file_list + glob.glob(os.path.join(dest, i_black)) black_file_list = list(set(black_file_list)) if not utils.doRemove(black_file_list): return False if "copylist" in build_json: for i_s_key in build_json["copylist"].keys(): if i_s_key and build_json["copylist"][i_s_key]: (src_updated, dest_updated) = updateCopylistPrefix(src, dest, i_s_key, build_json["copylist"][i_s_key]) if not utils.doCopy(src_updated, dest_updated): return False return True
def prepareBuildRoot(): LOG.info("+Preparing build root folder ...") global BUILD_ROOT global BUILD_ROOT_SRC global BUILD_ROOT_SRC_PKG global BUILD_ROOT_SRC_PKG_APP global BUILD_ROOT_SRC_SUB_APP global BUILD_ROOT_PKG global BUILD_ROOT_PKG_APP while True: BUILD_ROOT = os.path.join("/tmp", utils.getRandomStr()) if os.path.exists(BUILD_ROOT): continue else: break BUILD_ROOT_SRC = os.path.join(BUILD_ROOT, PKG_NAME) BUILD_ROOT_SRC_PKG = os.path.join(BUILD_ROOT, "pkg") BUILD_ROOT_SRC_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app") BUILD_ROOT_SRC_SUB_APP = os.path.join(BUILD_ROOT, "sub-app") BUILD_ROOT_PKG = os.path.join(BUILD_ROOT, "pkg", "opt", PKG_NAME) BUILD_ROOT_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app", "opt", PKG_NAME) if not utils.doCopy(BUILD_PARAMETERS.srcdir, BUILD_ROOT_SRC): return False else: utils.replaceUserString(BUILD_ROOT_SRC, '*', 'TESTER-HOME-DIR', "/home/%s" % BUILD_PARAMETERS.user) if not utils.doRemove( glob.glob(os.path.join(BUILD_ROOT_SRC, "%s*.zip" % PKG_NAME))): return False return True
def buildSRC(src=None, dest=None, build_json=None): if not os.path.exists(src): LOG.info("+Src dir does not exist, skip build src process ...") return True if not utils.doCopy(src, dest): return False if "blacklist" in build_json: if build_json["blacklist"].count("") > 0: build_json["blacklist"].remove("") black_file_list = [] for i_black in build_json["blacklist"]: black_file_list = black_file_list + \ glob.glob(os.path.join(dest, i_black)) black_file_list = list(set(black_file_list)) if not utils.doRemove(black_file_list): return False if "copylist" in build_json: for i_s_key in build_json["copylist"].keys(): if i_s_key and build_json["copylist"][i_s_key]: (src_updated, dest_updated) = updateCopylistPrefix( src, dest, i_s_key, build_json["copylist"][i_s_key]) if not utils.doCopy(src_updated, dest_updated): return False return True
def prepareBuildRoot(): LOG.info("+Preparing build root folder ...") global BUILD_ROOT global BUILD_ROOT_SRC global BUILD_ROOT_SRC_PKG global BUILD_ROOT_SRC_PKG_APP global BUILD_ROOT_SRC_SUB_APP global BUILD_ROOT_PKG global BUILD_ROOT_PKG_APP while True: BUILD_ROOT = os.path.join("/tmp", utils.getRandomStr()) if os.path.exists(BUILD_ROOT): continue else: break BUILD_ROOT_SRC = os.path.join(BUILD_ROOT, PKG_NAME) BUILD_ROOT_SRC_PKG = os.path.join(BUILD_ROOT, "pkg") BUILD_ROOT_SRC_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app") BUILD_ROOT_SRC_SUB_APP = os.path.join(BUILD_ROOT, "sub-app") BUILD_ROOT_PKG = os.path.join(BUILD_ROOT, "pkg", "opt", PKG_NAME) BUILD_ROOT_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app", "opt", PKG_NAME) if not utils.doCopy(BUILD_PARAMETERS.srcdir, BUILD_ROOT_SRC): return False else: utils.replaceUserString(BUILD_ROOT_SRC, "*", "TESTER-HOME-DIR", "/home/%s" % BUILD_PARAMETERS.user) if not utils.doRemove(glob.glob(os.path.join(BUILD_ROOT_SRC, "%s*.zip" % PKG_NAME))): return False return True
def exitHandler(return_code=1): LOG.info("+Cleaning build root folder ...") if not BUILD_PARAMETERS.bnotclean and os.path.exists(BUILD_ROOT): if not utils.doRemove([BUILD_ROOT]): LOG.error("Fail to clean build root, exit ...") sys.exit(1) if return_code == 0: LOG.info("================ DONE ================") else: LOG.error("================ Found Something Wrong !!! ================") sys.exit(return_code)
def exitHandler(return_code=1): LOG.info("+Cleaning build root folder ...") if not BUILD_PARAMETERS.bnotclean and os.path.exists(BUILD_ROOT): if not utils.doRemove([BUILD_ROOT]): LOG.error("Fail to clean build root, exit ...") sys.exit(1) if return_code == 0: LOG.info("================ DONE ================") else: LOG.error( "================ Found Something Wrong !!! ================") sys.exit(return_code)
def packXPK(build_json=None, app_src=None, app_dest=None, app_name=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") pack_tool = os.path.join(BUILD_ROOT, "make_xpk.py") if not os.path.exists(pack_tool): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "make_xpk.py"), pack_tool): return False orig_dir = os.getcwd() os.chdir(BUILD_ROOT) if os.path.exists("key.file"): if not utils.doRemove(["key.file"]): os.chdir(orig_dir) return False key_file = utils.safelyGetValue(build_json, "key-file") if key_file == "key.file": LOG.error( "\"key.file\" is reserved name for default key file, " "pls change the key file name ...") os.chdir(orig_dir) return False if key_file: pack_cmd = "python make_xpk.py %s %s -o %s" % ( app_src, key_file, os.path.join(app_dest, "%s.xpk" % app_name)) else: pack_cmd = "python make_xpk.py %s key.file -o %s" % ( app_src, os.path.join(app_dest, "%s.xpk" % app_name)) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packDeb(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") app_name = app_name.replace("-", "_") files = glob.glob(os.path.join(BUILD_ROOT, "*.deb")) if files: if not utils.doRemove(files): return False url_opt = "" pkg_opt = "" tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "%s" % tmp_opt manifest_opt = {} manifest_opt["name"] = "%s" % app_name print app_name + "test" if pkg_opt: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % pkg_opt else: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % app_name if url_opt: manifest_opt["start_url"] = url_opt else: manifest_opt["start_url"] = "index.html" manifest_opt = json.JSONEncoder().encode(manifest_opt) if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": pack_cmd = "crosswalk-pkg -p deb %s" % app_src else: pack_cmd = "crosswalk-pkg --manifest='%s' -p deb %s" % (manifest_opt, app_src) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT)) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT * 1.5): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "*.deb")) if files: rename_app_name = utils.safelyGetValue(build_json, "app-name") if not rename_app_name: rename_app_name = app_name if not utils.doCopy(files[0], os.path.join(app_dest, "%s.deb" % rename_app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the deb file") os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packCordova_cli( build_json=None, app_src=None, app_dest=None, app_name=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") CROSSWALK_BRANCH= varshop.getValue("CROSSWALK_BRANCH") CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") app_name = app_name.replace("-", "_") project_root = os.path.join(BUILD_ROOT, app_name) output = commands.getoutput("cordova -v") output_version = int(output[0]) if output_version < 5: LOG.error( "Cordova 4.x build requires the latest Cordova CLI, and must >= 5.0.0, install with command: '$ sudo npm install cordova -g'") return False plugin_tool = os.path.join(BUILD_ROOT, "cordova_plugins") plugin_source = os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins") if not os.path.exists(plugin_tool): if os.path.exists(plugin_source): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins"), plugin_tool): return False extra_plugins = os.path.join(BUILD_ROOT, "extra_plugins") if os.path.exists(extra_plugins): if not utils.doCopy(extra_plugins, plugin_tool): return False orig_dir = os.getcwd() os.chdir(BUILD_ROOT) pack_cmd = "cordova create %s org.xwalk.%s %s" % ( app_name, app_name, app_name) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False # Set activity name as app_name utils.replaceUserString( project_root, 'config.xml', '<widget', '<widget android-activityName="%s"' % app_name) # Workaround for XWALK-3679 utils.replaceUserString( project_root, 'config.xml', '</widget>', ' <allow-navigation href="*" />\n</widget>') if not utils.doRemove([os.path.join(project_root, "www")]): return False if not utils.doCopy(app_src, os.path.join(project_root, "www")): os.chdir(orig_dir) return False os.chdir(project_root) pack_cmd = "cordova platform add android" if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False pkg_mode_tmp = "shared" if BUILD_PARAMETERS.pkgmode == "embedded": pkg_mode_tmp = "core" xwalk_version = "%s" % CROSSWALK_VERSION if CROSSWALK_BRANCH == "beta": xwalk_version = "org.xwalk:xwalk_%s_library_beta:%s" % (pkg_mode_tmp, CROSSWALK_VERSION) webview_plugin_name = "cordova-plugin-crosswalk-webview" plugin_dirs = os.listdir(plugin_tool) for i_dir in plugin_dirs: install_variable_cmd = "" i_plugin_dir = os.path.join(plugin_tool, i_dir) plugin_crosswalk_source = i_plugin_dir if i_dir == webview_plugin_name: if BUILD_PARAMETERS.packtype == "npm": plugin_crosswalk_source = webview_plugin_name install_variable_cmd = "--variable XWALK_MODE=\"%s\" --variable XWALK_VERSION=\"%s\"" \ % (BUILD_PARAMETERS.pkgmode, xwalk_version) plugin_install_cmd = "cordova plugin add %s %s" % (plugin_crosswalk_source, install_variable_cmd) if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False ANDROID_HOME = "echo $(dirname $(dirname $(which android)))" os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME) apk_name_arch = "armv7" pack_arch_tmp = "arm" if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch != "arm": apk_name_arch = BUILD_PARAMETERS.pkgarch if BUILD_PARAMETERS.pkgarch == "x86": pack_arch_tmp = "x86" elif BUILD_PARAMETERS.pkgarch == "x86_64": pack_arch_tmp = "x86 --xwalk64bit" elif BUILD_PARAMETERS.pkgarch == "arm64": pack_arch_tmp = "arm --xwalk64bit" pack_cmd = "cordova build android -- --gradleArg=-PcdvBuildArch=%s" % pack_arch_tmp if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False outputs_dir = os.path.join( project_root, "platforms", "android", "build", "outputs", "apk") cordova_tmp_path = os.path.join( outputs_dir, "android-%s-debug.apk" % apk_name_arch) if not os.path.exists(cordova_tmp_path): cordova_tmp_path = os.path.join( outputs_dir, "%s-%s-debug.apk" % (app_name, apk_name_arch)) if not os.path.exists(cordova_tmp_path): cordova_tmp_path = os.path.join( outputs_dir, "android-debug.apk") if not os.path.exists(cordova_tmp_path): cordova_tmp_path = os.path.join( outputs_dir, "%s-debug.apk" % app_name) if not utils.doCopy( cordova_tmp_path, os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packMsi(build_json=None, app_src=None, app_dest=None, app_name=None): if os.path.exists(os.path.join(app_src, "icon.png")): if not utils.doCopy(os.path.join(app_src, "icon.png"), os.path.join(app_src, "icon.ico")): return False pkg_name = "org.xwalk." + app_name.replace("-", "") 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") CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") PKG_MODES= varshop.getValue("PKG_MODES") PKG_ARCHS= varshop.getValue("PKG_ARCHS") get_real_arch = {"x86": "x86", "x86_64": "x86_64", "arm": "armeabi-v7a", "arm64": "arm64-v8a"} windows_opt = "" ext_opt = [] cmd_opt = "" url_opt = "" mode_opt = "" arch_opt = "" icon_opt = "" icons_opt = [] version_opt = "" pkg_opt = "" version_code_opt = "" fullscreen_opt = "" orientation_opt = "" screenOn_opt = "" animatableView_opt = "" webp_opt = "" shortName_opt = "" permissions_opt = [] tmp_opt = utils.safelyGetValue(build_json, "google-api-key") if tmp_opt: source_keys_file = os.path.join(BUILD_PARAMETERS.pkgpacktools, "resources", "keys", "crosswalk-app-tools-keys.json") userName = os.getenv("USERNAME") dest_keys_file = "C:\\Users\\%s\\.crosswalk-app-tools-keys.json" % userName if not utils.doCopy( source_keys_file, dest_keys_file): return False windows_opt = "-w google-api-key:%s" % tmp_opt common_opts = utils.safelyGetValue(build_json, "apk-common-opts") if common_opts is None: common_opts = " -r " else: common_opts_array = common_opts.split() if "-r" in common_opts_array: pass elif "--enable-remote-debugging" in common_opts_array: common_opts = common_opts.replace('--enable-remote-debugging', '') else: common_opts += " -r " #workaround for XWALK-4042 #common_opts = common_opts.replace(' -r ','') tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_opt = tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-version-opt") if tmp_opt: version_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-fullscreen-opt") if tmp_opt: fullscreen_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-cmd-opt") if tmp_opt: cmd_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-orientation-opt") if tmp_opt: orientation_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-screenOn-opt") if tmp_opt: screenOn_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-animatableView-opt") if tmp_opt: animatableView_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-webp-opt") if tmp_opt: webp_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-shortName-opt") if tmp_opt: shortName_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-permissions-opt") if tmp_opt: permissions_opt = [tmp_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-mode-opt") if tmp_opt: if tmp_opt in PKG_MODES: mode_opt = "--android=\"%s\"" % tmp_opt if tmp_opt == "embedded": mode_opt = "" else: LOG.error("Got wrong app mode: %s" % tmp_opt) return False else: mode_opt = "--android=\"%s\"" % BUILD_PARAMETERS.pkgmode if BUILD_PARAMETERS.pkgmode == "embedded": mode_opt = "" tmp_opt = utils.safelyGetValue(build_json, "apk-arch-opt") if tmp_opt: if tmp_opt in PKG_ARCHS: arch_opt = "%s" % tmp_opt else: LOG.error("Got wrong app arch: %s" % tmp_opt) return False else: arch_opt = "%s" % BUILD_PARAMETERS.pkgarch if not arch_opt: arch_opt = get_real_arch[arch_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-icon-opt") if tmp_opt: icon_opt = "%s" % tmp_opt icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] elif tmp_opt == "": pass else: icon_opt = "icon.ico" icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] manifest_opt = {} manifest_opt["name"] = "%s" % app_name if pkg_opt: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % pkg_opt else: manifest_opt["xwalk_package_id"] = pkg_name if url_opt: manifest_opt["start_url"] = url_opt else: manifest_opt["start_url"] = "index.html" if ext_opt: manifest_opt["xwalk_extensions"] = ext_opt if cmd_opt: manifest_opt["xwalk_command_line"] = cmd_opt if fullscreen_opt: manifest_opt["display"] = fullscreen_opt if version_opt: manifest_opt["xwalk_app_version"] = version_opt if icons_opt and \ utils.safelyGetValue(build_json, "apk-type") != "MANIFEST": manifest_opt["icons"] = icons_opt if orientation_opt: manifest_opt["orientation"] = orientation_opt if screenOn_opt: manifest_opt["xwalk_android_keep_screen_on"] = screenOn_opt if animatableView_opt: manifest_opt["xwalk_android_animatable_view"] = animatableView_opt if webp_opt: manifest_opt["xwalk_android_webp"] = webp_opt if shortName_opt: manifest_opt["short_name"] = shortName_opt if permissions_opt: manifest_opt["xwalk_android_permissions"] = permissions_opt manifest_opt = json.JSONEncoder().encode(manifest_opt) manifest_opt = manifest_opt.replace("\"", "\"\"\"") manifest_opt = manifest_opt.replace("\"\"\"src\"\"\"", "\"\"src\"\"") manifest_opt = manifest_opt.replace("\"\"\"icon.ico\"\"\"", "\"\"icon.ico\"\"") manifest_opt = manifest_opt.replace("\"\"\"sizes\"\"\"", "\"\"sizes\"\"") manifest_opt = manifest_opt.replace("\"\"\"72x72\"\"\"", "\"\"72x72\"\"") manifest_opt = manifest_opt.replace("{\"\"\"", "\"{\"\"\"") manifest_opt = manifest_opt.replace("\"\"\"}", "\"\"\"}\"") print manifest_opt orig_dir = os.getcwd() if not os.path.exists( os.path.join(BUILD_ROOT, "crosswalk64-%s.zip" % CROSSWALK_VERSION)): if not utils.doCopy(os.path.join(BUILD_PARAMETERS.pkgpacktools, "crosswalk64-%s.zip" % CROSSWALK_VERSION), os.path.join(BUILD_ROOT, "crosswalk64-%s.zip" % CROSSWALK_VERSION)): return False os.chdir(BUILD_ROOT) crosswalk_app_tools = os.getenv("CROSSWALK_APP_TOOLS") if crosswalk_app_tools == None: LOG.error("Pls add an environment variable named 'CROSSWALK_APP_TOOLS', and set the crosswalk-app-tools path to this environment variable") os.chdir(orig_dir) return False if not utils.safelyGetValue(build_json, "apk-type") or utils.safelyGetValue(build_json, "apk-type") != "MANIFEST": if os.path.exists(os.path.join(app_src, "manifest.json")): if not utils.doRemove([os.path.join(app_src, "manifest.json")]): os.chdir(orig_dir) return False build_cmd = "node %s/src/crosswalk-pkg -c crosswalk64-%s.zip --platforms=windows -m %s %s %s %s" \ % (crosswalk_app_tools, CROSSWALK_VERSION, manifest_opt, common_opts, windows_opt, app_src) else: build_cmd = "node %s/src/crosswalk-pkg -c crosswalk64-%s.zip --platforms=windows %s %s %s" % (crosswalk_app_tools, CROSSWALK_VERSION, common_opts, windows_opt, app_src) print build_cmd if not utils.doCMD(build_cmd, DEFAULT_CMD_TIMEOUT): LOG.error("Fail to pack: %s" % build_cmd) # After build successfully, copy the .msi file from project_root to app_dest time.sleep(5) files = glob.glob(os.path.join(BUILD_ROOT, "*.msi")) if not utils.doCopy( files[0], os.path.join(app_dest, "%s.msi" % app_name)): return False if not utils.doRemove([files[0]]): return False os.chdir(orig_dir) return True
def packAPK(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") CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION") 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("-", "_") get_real_arch = {"x86": "x86", "x86_64": "x86_64", "arm": "armeabi-v7a", "arm64": "arm64-v8a"} files = glob.glob(os.path.join(BUILD_ROOT, "*.apk")) if files: if not utils.doRemove(files): return False ext_opt = [] cmd_opt = "" url_opt = "" mode_opt = "" arch_opt = "" icon_opt = "" icons_opt = [] version_opt = "" pkg_opt = "" version_code_opt = "" fullscreen_opt = "" orientation_opt = "" screenOn_opt = "" animatableView_opt = "" webp_opt = "" shortName_opt = "" permissions_opt = [] common_opts = utils.safelyGetValue(build_json, "apk-common-opts") if common_opts is None: common_opts = " -r " else: common_opts_array = common_opts.split() if "-r" in common_opts_array: pass elif "--enable-remote-debugging" in common_opts_array: common_opts = common_opts.replace('--enable-remote-debugging', '') else: common_opts += " -r " #workaround for XWALK-4042 common_opts = common_opts.replace(' -r ','') tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_opt = [os.path.join(BUILD_ROOT_SRC, tmp_opt)] tmp_opt = utils.safelyGetValue(build_json, "apk-version-opt") if tmp_opt: version_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-fullscreen-opt") if tmp_opt: fullscreen_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-cmd-opt") if tmp_opt: cmd_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-orientation-opt") if tmp_opt: orientation_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-screenOn-opt") if tmp_opt: screenOn_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-animatableView-opt") if tmp_opt: animatableView_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-webp-opt") if tmp_opt: webp_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-shortName-opt") if tmp_opt: shortName_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-permissions-opt") if tmp_opt: permissions_opt = [tmp_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-mode-opt") if tmp_opt: if tmp_opt in PKG_MODES: mode_opt = "--android=\"%s\"" % tmp_opt if tmp_opt == "embedded": mode_opt = "" else: LOG.error("Got wrong app mode: %s" % tmp_opt) return False else: mode_opt = "--android=\"%s\"" % BUILD_PARAMETERS.pkgmode if BUILD_PARAMETERS.pkgmode == "embedded": mode_opt = "" tmp_opt = utils.safelyGetValue(build_json, "apk-arch-opt") if tmp_opt: if tmp_opt in PKG_ARCHS: arch_opt = "%s" % tmp_opt else: LOG.error("Got wrong app arch: %s" % tmp_opt) return False else: arch_opt = "%s" % BUILD_PARAMETERS.pkgarch arch_opt = get_real_arch[arch_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-icon-opt") if tmp_opt: icon_opt = "%s" % tmp_opt icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] elif tmp_opt == "": pass else: icon_opt = "icon.png" icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] manifest_opt = {} manifest_opt["name"] = "%s" % app_name if pkg_opt: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % pkg_opt else: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % app_name if url_opt: manifest_opt["start_url"] = url_opt else: manifest_opt["start_url"] = "index.html" if ext_opt: manifest_opt["xwalk_extensions"] = ext_opt if cmd_opt: manifest_opt["xwalk_command_line"] = cmd_opt if fullscreen_opt: manifest_opt["display"] = fullscreen_opt if version_opt: manifest_opt["xwalk_app_version"] = version_opt if icons_opt and \ utils.safelyGetValue(build_json, "apk-type") != "MANIFEST": manifest_opt["icons"] = icons_opt if orientation_opt: manifest_opt["orientation"] = orientation_opt if screenOn_opt: manifest_opt["xwalk_android_keep_screen_on"] = screenOn_opt if animatableView_opt: manifest_opt["xwalk_android_animatable_view"] = animatableView_opt if webp_opt: manifest_opt["xwalk_android_webp"] = webp_opt if shortName_opt: manifest_opt["short_name"] = shortName_opt if permissions_opt: manifest_opt["xwalk_android_permissions"] = permissions_opt manifest_opt = json.JSONEncoder().encode(manifest_opt) crosswalk_version_opt = CROSSWALK_VERSION app_tools_dir = os.environ.get('CROSSWALK_APP_TOOLS_CACHE_DIR') if app_tools_dir: if "64" in arch_opt and os.path.exists(os.path.join(app_tools_dir, "crosswalk-%s-64bit.zip" % CROSSWALK_VERSION)): crosswalk_version_opt = os.path.join(app_tools_dir, "crosswalk-%s-64bit.zip" % CROSSWALK_VERSION) elif os.path.exists(os.path.join(app_tools_dir, "crosswalk-%s.zip" % CROSSWALK_VERSION)): crosswalk_version_opt = os.path.join(app_tools_dir, "crosswalk-%s.zip" % CROSSWALK_VERSION) else: crosswalk_version_opt = CROSSWALK_VERSION if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": pack_cmd = "crosswalk-pkg %s --crosswalk=%s " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, arch_opt, common_opts, app_src) else: pack_cmd = "crosswalk-pkg %s --crosswalk=%s --manifest='%s' " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, manifest_opt, arch_opt, common_opts, app_src) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT)) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT * 1.5): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "*.apk")) if files: rename_app_name = utils.safelyGetValue(build_json, "app-name") if not rename_app_name: rename_app_name = getNameById(files[0]) rename_app_name = rename_app_name.replace("-", "_") if not utils.doCopy(files[0], os.path.join(app_dest, "%s.apk" % rename_app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the apk file") 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
def packAPK(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") CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION") 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("-", "_") get_real_arch = { "x86": "x86", "x86_64": "x86_64", "arm": "armeabi-v7a", "arm64": "arm64-v8a" } files = glob.glob(os.path.join(BUILD_ROOT, "*.apk")) if files: if not utils.doRemove(files): return False ext_opt = [] cmd_opt = "" url_opt = "" mode_opt = "" arch_opt = "" icon_opt = "" icons_opt = [] version_opt = "" pkg_opt = "" version_code_opt = "" fullscreen_opt = "" orientation_opt = "" screenOn_opt = "" animatableView_opt = "" webp_opt = "" shortName_opt = "" permissions_opt = [] common_opts = utils.safelyGetValue(build_json, "apk-common-opts") if common_opts is None: common_opts = " -r " else: common_opts_array = common_opts.split() if "-r" in common_opts_array: pass elif "--enable-remote-debugging" in common_opts_array: common_opts = common_opts.replace('--enable-remote-debugging', '') else: common_opts += " -r " #workaround for XWALK-4042 common_opts = common_opts.replace(' -r ', '') tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_opt = [os.path.join(BUILD_ROOT_SRC, tmp_opt)] tmp_opt = utils.safelyGetValue(build_json, "apk-version-opt") if tmp_opt: version_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-fullscreen-opt") if tmp_opt: fullscreen_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-cmd-opt") if tmp_opt: cmd_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-orientation-opt") if tmp_opt: orientation_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-screenOn-opt") if tmp_opt: screenOn_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-animatableView-opt") if tmp_opt: animatableView_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-webp-opt") if tmp_opt: webp_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-shortName-opt") if tmp_opt: shortName_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-permissions-opt") if tmp_opt: permissions_opt = [tmp_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-mode-opt") if tmp_opt: if tmp_opt in PKG_MODES: mode_opt = "--android=\"%s\"" % tmp_opt if tmp_opt == "embedded": mode_opt = "" else: LOG.error("Got wrong app mode: %s" % tmp_opt) return False else: mode_opt = "--android=\"%s\"" % BUILD_PARAMETERS.pkgmode if BUILD_PARAMETERS.pkgmode == "embedded": mode_opt = "" tmp_opt = utils.safelyGetValue(build_json, "apk-arch-opt") if tmp_opt: if tmp_opt in PKG_ARCHS: arch_opt = "%s" % tmp_opt else: LOG.error("Got wrong app arch: %s" % tmp_opt) return False else: arch_opt = "%s" % BUILD_PARAMETERS.pkgarch arch_opt = get_real_arch[arch_opt] tmp_opt = utils.safelyGetValue(build_json, "apk-icon-opt") if tmp_opt: icon_opt = "%s" % tmp_opt icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] elif tmp_opt == "": pass else: icon_opt = "icon.png" icon_set = {} icon_set["src"] = icon_opt icon_set["sizes"] = "72x72" icons_opt = [icon_set] manifest_opt = {} manifest_opt["name"] = "%s" % app_name if pkg_opt: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % pkg_opt else: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % app_name if url_opt: manifest_opt["start_url"] = url_opt else: manifest_opt["start_url"] = "index.html" if ext_opt: manifest_opt["xwalk_extensions"] = ext_opt if cmd_opt: manifest_opt["xwalk_command_line"] = cmd_opt if fullscreen_opt: manifest_opt["display"] = fullscreen_opt if version_opt: manifest_opt["xwalk_app_version"] = version_opt if icons_opt and \ utils.safelyGetValue(build_json, "apk-type") != "MANIFEST": manifest_opt["icons"] = icons_opt if orientation_opt: manifest_opt["orientation"] = orientation_opt if screenOn_opt: manifest_opt["xwalk_android_keep_screen_on"] = screenOn_opt if animatableView_opt: manifest_opt["xwalk_android_animatable_view"] = animatableView_opt if webp_opt: manifest_opt["xwalk_android_webp"] = webp_opt if shortName_opt: manifest_opt["short_name"] = shortName_opt if permissions_opt: manifest_opt["xwalk_android_permissions"] = permissions_opt manifest_opt = json.JSONEncoder().encode(manifest_opt) crosswalk_version_opt = CROSSWALK_VERSION app_tools_dir = os.environ.get('CROSSWALK_APP_TOOLS_CACHE_DIR') if app_tools_dir: if "64" in arch_opt and os.path.exists( os.path.join(app_tools_dir, "crosswalk-%s-64bit.zip" % CROSSWALK_VERSION)): crosswalk_version_opt = os.path.join( app_tools_dir, "crosswalk-%s-64bit.zip" % CROSSWALK_VERSION) elif os.path.exists( os.path.join(app_tools_dir, "crosswalk-%s.zip" % CROSSWALK_VERSION)): crosswalk_version_opt = os.path.join( app_tools_dir, "crosswalk-%s.zip" % CROSSWALK_VERSION) else: crosswalk_version_opt = CROSSWALK_VERSION #Only when building embedded mode apk, use arch_opt arch_opt = "" if "shared" in mode_opt else arch_opt if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": if platform.system() == "Windows": pack_cmd = "node %crosswalk-pkg% %s --crosswalk=%s " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, arch_opt, common_opts, app_src) else: pack_cmd = "crosswalk-pkg %s --crosswalk=%s " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, arch_opt, common_opts, app_src) else: if platform.system() == "Windows": pack_cmd = "node %crosswalk-pkg% %s --crosswalk=%s --manifest='%s' " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, manifest_opt, arch_opt, common_opts, app_src) else: pack_cmd = "crosswalk-pkg %s --crosswalk=%s --manifest='%s' " \ "-p android --targets=\"%s\" %s %s" % ( mode_opt, crosswalk_version_opt, manifest_opt, arch_opt, common_opts, app_src) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT)) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT * 1.5): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "*.apk")) if files: rename_app_name = utils.safelyGetValue(build_json, "app-name") if not rename_app_name: rename_app_name = getNameById(files[0]) rename_app_name = rename_app_name.replace("-", "_") if not utils.doCopy( files[0], os.path.join(app_dest, "%s.apk" % rename_app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the apk file") 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
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_maven( 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("-", "_") orig_dir = os.getcwd() LOG.info("app_src: %s" % app_src) LOG.info("app_dest: %s" % app_dest) os.chdir(BUILD_ROOT) utils.replaceUserString( app_src, 'pom.xml', '{crosswalk.version}', CROSSWALK_VERSION) version_parts = CROSSWALK_VERSION.split('.') if len(version_parts) < 4: LOG.error("The crosswalk version is not configured exactly!") return False versionType = version_parts[3] if versionType == '0': utils.replaceUserString( app_src, 'pom.xml', 'xwalk_core_library_beta', 'xwalk_core_library') username = commands.getoutput("echo $USER") repository_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s" % \ (username, CROSSWALK_VERSION) repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \ "xwalk_core_library-%s.aar" % \ (username, CROSSWALK_VERSION, CROSSWALK_VERSION) repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \ "xwalk_core_library-%s.pom" % \ (username, CROSSWALK_VERSION, CROSSWALK_VERSION) if not os.path.exists(repository_aar_path) or not os.path.exists(repository_pom_path): wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/android" \ "/canary/%s/crosswalk-%s.aar" % \ (CROSSWALK_VERSION, CROSSWALK_VERSION) if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3): os.chdir(orig_dir) return False install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \ "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \ "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \ (CROSSWALK_VERSION, CROSSWALK_VERSION) if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False if not utils.doCopy( repository_aar_path, os.path.join(repository_path, "xwalk_core_library-%s-x86.aar" % CROSSWALK_VERSION)): os.chdir(orig_dir) return False if not utils.doCopy( repository_aar_path, os.path.join(repository_path, "xwalk_core_library-%s-arm.aar" % CROSSWALK_VERSION)): os.chdir(orig_dir) return False utils.replaceUserString( app_src, 'pom.xml', 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2', 'file:///home/%s/.m2/repository' % username) os.chdir(app_src) utils.replaceUserString( app_src, 'AndroidManifest.xml', 'android:versionCode=\"1\"', 'android:versionCode=\"${app.version.code}\"') utils.replaceUserString( app_src, 'AndroidManifest.xml', 'android:versionName=\"1.0\"', 'android:versionName=\"${app.version.name}\"') manifest_path = os.path.join(app_src, "AndroidManifest.xml") if not utils.doCopy( manifest_path, os.path.join(app_src, "src", "main", "AndroidManifest.xml")): return False if not utils.doRemove([manifest_path]): return False res_path = os.path.join(app_src, "res") if os.path.exists(res_path): if not utils.doCopy(res_path, os.path.join(app_src, "src", "main", "res")): return False if not utils.doRemove([res_path]): return False assets_path = os.path.join(app_src, "assets") if os.path.exists(assets_path): if not utils.doCopy( assets_path, os.path.join(app_src, "src", "main", "assets")): return False if not utils.doRemove([assets_path]): return False src_org_path = os.path.join(app_src, "src", "org") if not utils.doCopy( src_org_path, os.path.join(app_src, "src", "main", "java", "org")): return False if not utils.doRemove([src_org_path]): return False libs_path = os.path.join(app_src, "libs") if os.path.exists(libs_path): if not utils.doCopy( libs_path, os.path.join(app_src, "../libs")): return False if not utils.doRemove([libs_path]): return False if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm": if not utils.doCMD("mvn clean install -Parm", DEFAULT_CMD_TIMEOUT): return False if not utils.doCopy( os.path.join( app_src, "target", "embeddingapi-tests-arm.apk"), os.path.join(app_dest, "%s.apk" % app_name)): return False else: if not utils.doCMD("mvn clean install -Px86", DEFAULT_CMD_TIMEOUT): return False if not utils.doCopy( os.path.join(app_src, "target", "embeddingapi-tests-x86.apk"), os.path.join(app_dest, "%s.apk" % app_name)): 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_maven(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("-", "_") orig_dir = os.getcwd() LOG.info("app_src: %s" % app_src) LOG.info("app_dest: %s" % app_dest) os.chdir(BUILD_ROOT) utils.replaceUserString(app_src, 'pom.xml', '{crosswalk.version}', CROSSWALK_VERSION) version_parts = CROSSWALK_VERSION.split('.') if len(version_parts) < 4: LOG.error("The crosswalk version is not configured exactly!") return False versionType = version_parts[3] if versionType == '0': utils.replaceUserString(app_src, 'pom.xml', 'xwalk_core_library_beta', 'xwalk_core_library') username = commands.getoutput("echo $USER") repository_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s" % \ (username, CROSSWALK_VERSION) repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \ "xwalk_core_library-%s.aar" % \ (username, CROSSWALK_VERSION, CROSSWALK_VERSION) repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \ "xwalk_core_library-%s.pom" % \ (username, CROSSWALK_VERSION, CROSSWALK_VERSION) if not os.path.exists(repository_aar_path) or not os.path.exists( repository_pom_path): wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/android" \ "/canary/%s/crosswalk-%s.aar" % \ (CROSSWALK_VERSION, CROSSWALK_VERSION) if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3): os.chdir(orig_dir) return False install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \ "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \ "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \ (CROSSWALK_VERSION, CROSSWALK_VERSION) if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False if not utils.doCopy( repository_aar_path, os.path.join( repository_path, "xwalk_core_library-%s-x86.aar" % CROSSWALK_VERSION)): os.chdir(orig_dir) return False if not utils.doCopy( repository_aar_path, os.path.join( repository_path, "xwalk_core_library-%s-arm.aar" % CROSSWALK_VERSION)): os.chdir(orig_dir) return False utils.replaceUserString( app_src, 'pom.xml', 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2', 'file:///home/%s/.m2/repository' % username) os.chdir(app_src) utils.replaceUserString(app_src, 'AndroidManifest.xml', 'android:versionCode=\"1\"', 'android:versionCode=\"${app.version.code}\"') utils.replaceUserString(app_src, 'AndroidManifest.xml', 'android:versionName=\"1.0\"', 'android:versionName=\"${app.version.name}\"') manifest_path = os.path.join(app_src, "AndroidManifest.xml") if not utils.doCopy( manifest_path, os.path.join(app_src, "src", "main", "AndroidManifest.xml")): return False if not utils.doRemove([manifest_path]): return False res_path = os.path.join(app_src, "res") if os.path.exists(res_path): if not utils.doCopy(res_path, os.path.join(app_src, "src", "main", "res")): return False if not utils.doRemove([res_path]): return False assets_path = os.path.join(app_src, "assets") if os.path.exists(assets_path): if not utils.doCopy(assets_path, os.path.join(app_src, "src", "main", "assets")): return False if not utils.doRemove([assets_path]): return False src_org_path = os.path.join(app_src, "src", "org") if not utils.doCopy(src_org_path, os.path.join(app_src, "src", "main", "java", "org")): return False if not utils.doRemove([src_org_path]): return False libs_path = os.path.join(app_src, "libs") if os.path.exists(libs_path): if not utils.doCopy(libs_path, os.path.join(app_src, "../libs")): return False if not utils.doRemove([libs_path]): return False if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm": if not utils.doCMD("mvn clean install -Parm", DEFAULT_CMD_TIMEOUT): return False if not utils.doCopy( os.path.join(app_src, "target", "embeddingapi-tests-arm.apk"), os.path.join(app_dest, "%s.apk" % app_name)): return False else: if not utils.doCMD("mvn clean install -Px86", DEFAULT_CMD_TIMEOUT): return False if not utils.doCopy( os.path.join(app_src, "target", "embeddingapi-tests-x86.apk"), os.path.join(app_dest, "%s.apk" % app_name)): return False os.chdir(orig_dir) return True
def packDeb(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") app_name = app_name.replace("-", "_") if '_' in app_name: app_name = app_name.replace('_', '') files = glob.glob(os.path.join(BUILD_ROOT, "*.deb")) if files: if not utils.doRemove(files): return False url_opt = "" pkg_opt = "" tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "%s" % tmp_opt manifest_opt = {} manifest_opt["name"] = "%s" % app_name print app_name + "test" if pkg_opt: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % pkg_opt else: manifest_opt["xwalk_package_id"] = "org.xwalk.%s" % app_name if url_opt: manifest_opt["start_url"] = url_opt else: manifest_opt["start_url"] = "index.html" manifest_opt = json.JSONEncoder().encode(manifest_opt) if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": pack_cmd = "crosswalk-pkg -p deb %s" % app_src else: pack_cmd = "crosswalk-pkg --manifest='%s' -p deb %s" % (manifest_opt, app_src) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT)) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT * 1.5): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "*.deb")) if files: rename_app_name = utils.safelyGetValue(build_json, "app-name") if not rename_app_name: rename_app_name = app_name if not utils.doCopy(files[0], os.path.join(app_dest, "%s.deb" % rename_app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the deb file") os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packAPK(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_opt = "" cmd_opt = "" url_opt = "" mode_opt = "" arch_opt = "" icon_opt = "" version_opt = "" pkg_opt = "" version_code_opt = "" fullscreen_opt = "" common_opts = utils.safelyGetValue(build_json, "apk-common-opts") if common_opts is None: common_opts = "" tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_opt = "--extensions='%s'" % os.path.join(BUILD_ROOT_SRC, tmp_opt) tmp_opt = utils.safelyGetValue(build_json, "apk-version-opt") if tmp_opt: version_opt = "--app-version='%s'" % ''.join([tmp_opt, BUILD_TIME]) version_code_opt = "--app-versionCode='%s'" % ''.join( ['6', BUILD_TIME]) tmp_opt = utils.safelyGetValue(build_json, "apk-fullscreen-opt") if tmp_opt: ext_opt = "--%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "--package='org.xwalk.%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-cmd-opt") if tmp_opt: cmd_opt = "--xwalk-command-line='%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "--app-url='%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-mode-opt") if tmp_opt: if tmp_opt in PKG_MODES: mode_opt = "--mode=%s" % tmp_opt else: LOG.error("Got wrong app mode: %s" % tmp_opt) return False else: mode_opt = "--mode=%s" % BUILD_PARAMETERS.pkgmode tmp_opt = utils.safelyGetValue(build_json, "apk-arch-opt") if tmp_opt: if tmp_opt in PKG_ARCHS: arch_opt = "--arch=%s" % tmp_opt else: LOG.error("Got wrong app arch: %s" % tmp_opt) return False else: arch_opt = "--arch=%s" % BUILD_PARAMETERS.pkgarch tmp_opt = utils.safelyGetValue(build_json, "apk-icon-opt") if tmp_opt: icon_opt = "--icon=%s" % tmp_opt elif tmp_opt == "": icon_opt = "" else: icon_opt = "--icon=%s/icon.png" % app_src if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": pack_cmd = "python make_apk.py --package=org.xwalk.%s " \ "--manifest=%s/manifest.json %s %s %s %s %s %s %s %s %s" % ( app_name, app_src, mode_opt, arch_opt, ext_opt, cmd_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) elif utils.safelyGetValue(build_json, "apk-type") == "HOSTEDAPP": if not url_opt: LOG.error( "Fail to find the key \"apk-url-opt\" for hosted APP packing") return False pack_cmd = "python make_apk.py --package=org.xwalk.%s --name=%s %s " \ "%s %s %s %s %s %s %s %s %s" % ( app_name, app_name, mode_opt, arch_opt, ext_opt, cmd_opt, url_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) else: pack_cmd = "python make_apk.py --package=org.xwalk.%s --name=%s " \ "--app-root=%s --app-local-path=index.html %s %s " \ "%s %s %s %s %s %s %s %s" % ( app_name, app_name, app_src, icon_opt, mode_opt, arch_opt, ext_opt, cmd_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT, "crosswalk")) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "crosswalk", "*.apk")) if files: if not utils.doCopy(files[0], os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the apk file") os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packCordova_cli( build_json=None, app_src=None, app_dest=None, app_name=None): BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS") BUILD_ROOT = varshop.getValue("BUILD_ROOT") CROSSWALK_BRANCH= varshop.getValue("CROSSWALK_BRANCH") CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION") DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT") app_name = app_name.replace("-", "_") project_root = os.path.join(BUILD_ROOT, app_name) output = commands.getoutput("cordova -v") output_version = int(output[0]) if output_version < 5: LOG.error( "Cordova 4.x build requires the latest Cordova CLI, and must >= 5.0.0, install with command: '$ sudo npm install cordova -g'") return False plugin_tool = os.path.join(BUILD_ROOT, "cordova_plugins") if not os.path.exists(plugin_tool): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins"), plugin_tool): return False extra_plugins = os.path.join(BUILD_ROOT, "extra_plugins") if os.path.exists(extra_plugins): if not utils.doCopy(extra_plugins, plugin_tool): return False orig_dir = os.getcwd() os.chdir(BUILD_ROOT) pack_cmd = "cordova create %s org.xwalk.%s %s" % ( app_name, app_name, app_name) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False # Set activity name as app_name utils.replaceUserString( project_root, 'config.xml', '<widget', '<widget android-activityName="%s"' % app_name) # Workaround for XWALK-3679 utils.replaceUserString( project_root, 'config.xml', '</widget>', ' <allow-navigation href="*" />\n</widget>') if not utils.doRemove([os.path.join(project_root, "www")]): return False if not utils.doCopy(app_src, os.path.join(project_root, "www")): os.chdir(orig_dir) return False os.chdir(project_root) pack_cmd = "cordova platform add android" if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False pkg_mode_tmp = "shared" if BUILD_PARAMETERS.pkgmode == "embedded": pkg_mode_tmp = "core" xwalk_version = "%s" % CROSSWALK_VERSION if CROSSWALK_BRANCH == "beta": xwalk_version = "org.xwalk:xwalk_%s_library_beta:%s" % (pkg_mode_tmp, CROSSWALK_VERSION) webview_plugin_name = "cordova-plugin-crosswalk-webview" install_variable_cmd = "" plugin_dirs = os.listdir(plugin_tool) for i_dir in plugin_dirs: i_plugin_dir = os.path.join(plugin_tool, i_dir) plugin_crosswalk_source = i_plugin_dir if i_dir == webview_plugin_name: if BUILD_PARAMETERS.packtype == "npm": plugin_crosswalk_source = webview_plugin_name install_variable_cmd = "--variable XWALK_MODE=\"%s\" --variable XWALK_VERSION=\"%s\"" \ % (BUILD_PARAMETERS.pkgmode, xwalk_version) plugin_install_cmd = "cordova plugin add %s %s" % (plugin_crosswalk_source, install_variable_cmd) if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False ANDROID_HOME = "echo $(dirname $(dirname $(which android)))" os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME) pack_cmd = "cordova build android" if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False outputs_dir = os.path.join( project_root, "platforms", "android", "build", "outputs", "apk") if BUILD_PARAMETERS.pkgarch == "x86": cordova_tmp_path = os.path.join( outputs_dir, "%s-x86-debug.apk" % app_name) cordova_tmp_path_spare = os.path.join( outputs_dir, "android-x86-debug.apk") else: cordova_tmp_path = os.path.join( outputs_dir, "%s-armv7-debug.apk" % app_name) cordova_tmp_path_spare = os.path.join( outputs_dir, "android-armv7-debug.apk") if not os.path.exists(cordova_tmp_path): if not utils.doCopy( cordova_tmp_path_spare, os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False else: if not utils.doCopy( cordova_tmp_path, os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False os.chdir(orig_dir) return True
def packAPK(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_opt = "" cmd_opt = "" url_opt = "" mode_opt = "" arch_opt = "" icon_opt = "" version_opt = "" pkg_opt = "" version_code_opt = "" fullscreen_opt = "" common_opts = utils.safelyGetValue(build_json, "apk-common-opts") if common_opts is None: common_opts = "" tmp_opt = utils.safelyGetValue(build_json, "apk-ext-opt") if tmp_opt: ext_opt = "--extensions='%s'" % os.path.join(BUILD_ROOT_SRC, tmp_opt) tmp_opt = utils.safelyGetValue(build_json, "apk-version-opt") if tmp_opt: version_opt = "--app-version='%s'" % ''.join([tmp_opt, BUILD_TIME]) version_code_opt = "--app-versionCode='%s'" % ''.join( ['6', BUILD_TIME]) tmp_opt = utils.safelyGetValue(build_json, "apk-fullscreen-opt") if tmp_opt: ext_opt = "--%s" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-pkg-opt") if tmp_opt: pkg_opt = "--package='org.xwalk.%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-cmd-opt") if tmp_opt: cmd_opt = "--xwalk-command-line='%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-url-opt") if tmp_opt: url_opt = "--app-url='%s'" % tmp_opt tmp_opt = utils.safelyGetValue(build_json, "apk-mode-opt") if tmp_opt: if tmp_opt in PKG_MODES: mode_opt = "--mode=%s" % tmp_opt else: LOG.error("Got wrong app mode: %s" % tmp_opt) return False else: mode_opt = "--mode=%s" % BUILD_PARAMETERS.pkgmode tmp_opt = utils.safelyGetValue(build_json, "apk-arch-opt") if tmp_opt: if tmp_opt in PKG_ARCHS: arch_opt = "--arch=%s" % tmp_opt else: LOG.error("Got wrong app arch: %s" % tmp_opt) return False else: arch_opt = "--arch=%s" % BUILD_PARAMETERS.pkgarch tmp_opt = utils.safelyGetValue(build_json, "apk-icon-opt") if tmp_opt: icon_opt = "--icon=%s" % tmp_opt elif tmp_opt == "": icon_opt = "" else: icon_opt = "--icon=%s/icon.png" % app_src if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": pack_cmd = "python make_apk.py --package=org.xwalk.%s " \ "--manifest=%s/manifest.json %s %s %s %s %s %s %s %s %s" % ( app_name, app_src, mode_opt, arch_opt, ext_opt, cmd_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) elif utils.safelyGetValue(build_json, "apk-type") == "HOSTEDAPP": if not url_opt: LOG.error( "Fail to find the key \"apk-url-opt\" for hosted APP packing") return False pack_cmd = "python make_apk.py --package=org.xwalk.%s --name=%s %s " \ "%s %s %s %s %s %s %s %s %s" % ( app_name, app_name, mode_opt, arch_opt, ext_opt, cmd_opt, url_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) else: pack_cmd = "python make_apk.py --package=org.xwalk.%s --name=%s " \ "--app-root=%s --app-local-path=index.html %s %s " \ "%s %s %s %s %s %s %s %s" % ( app_name, app_name, app_src, icon_opt, mode_opt, arch_opt, ext_opt, cmd_opt, common_opts, version_opt, pkg_opt, version_code_opt, fullscreen_opt) orig_dir = os.getcwd() os.chdir(os.path.join(BUILD_ROOT, "crosswalk")) if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT): os.chdir(orig_dir) return False files = glob.glob(os.path.join(BUILD_ROOT, "crosswalk", "*.apk")) if files: if not utils.doCopy(files[0], os.path.join(app_dest, "%s.apk" % app_name)): os.chdir(orig_dir) return False else: LOG.error("Fail to find the apk file") os.chdir(orig_dir) return False os.chdir(orig_dir) return True