def buildPKGAPP(build_json=None): LOG.info("+Building package APP ...") if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": if not os.path.exists(os.path.join(BUILD_ROOT_SRC, "manifest.json")): LOG.error("Not found manifest.json in suite folder, please check!") sys.exit(1) if not utils.doCopy( os.path.join(BUILD_ROOT_SRC, "manifest.json"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "manifest.json") ): return False if not utils.doCopy(os.path.join(BUILD_ROOT_SRC, "icon.png"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "icon.png")): return False hosted_app = False if utils.safelyGetValue(build_json, "hosted-app") == "true": hosted_app = True if not createIndexFile(os.path.join(BUILD_ROOT_SRC_PKG_APP, "index.html"), hosted_app): return False if not hosted_app: if "blacklist" not in build_json: build_json.update({"blacklist": []}) build_json["blacklist"].extend(PKG_BLACK_LIST) if not buildSRC(BUILD_ROOT_SRC, BUILD_ROOT_PKG_APP, build_json): return False if "subapp-list" in build_json: for i_sub_app in build_json["subapp-list"].keys(): if not buildSubAPP(i_sub_app, build_json["subapp-list"][i_sub_app], BUILD_ROOT_PKG_APP): return False if not packAPP(build_json, BUILD_ROOT_SRC_PKG_APP, BUILD_ROOT_PKG, PKG_NAME): return False return True
def buildSubAPP(app_dir=None, build_json=None, app_dest_default=None): app_dir_inside = utils.safelyGetValue(build_json, "app-dir") if app_dir_inside: app_dir = app_dir_inside LOG.info("+Building sub APP(s) from %s ..." % app_dir) app_dir = os.path.join(BUILD_ROOT_SRC, app_dir) app_name = utils.safelyGetValue(build_json, "app-name") if not app_name: app_name = os.path.basename(app_dir) app_src = os.path.join(BUILD_ROOT_SRC_SUB_APP, app_name) if buildSRC(app_dir, app_src, build_json): app_dest = utils.safelyGetValue(build_json, "install-path") if app_dest: app_dest = os.path.join(app_dest_default, app_dest) else: app_dest = app_dest_default if utils.safelyGetValue(build_json, "all-apps") == "true": app_dirs = os.listdir(app_src) apps_num = 0 for i_app_dir in app_dirs: if os.path.isdir(os.path.join(app_src, i_app_dir)): i_app_name = os.path.basename(i_app_dir) if not packAPP(build_json, os.path.join( app_src, i_app_name), app_dest, i_app_name): return False else: apps_num = apps_num + 1 if apps_num > 0: LOG.info("Totally packed %d apps in %s" % (apps_num, app_dir)) return True else: return packAPP(build_json, app_src, app_dest, app_name) return False
def buildSubAPP(app_dir=None, build_json=None, app_dest_default=None): app_dir_inside = utils.safelyGetValue(build_json, "app-dir") if app_dir_inside: app_dir = app_dir_inside LOG.info("+Building sub APP(s) from %s ..." % app_dir) app_dir = os.path.join(BUILD_ROOT_SRC, app_dir) app_name = utils.safelyGetValue(build_json, "app-name") if not app_name: app_name = os.path.basename(app_dir) app_src = os.path.join(BUILD_ROOT_SRC_SUB_APP, app_name) if buildSRC(app_dir, app_src, build_json): app_dest = utils.safelyGetValue(build_json, "install-path") if app_dest: app_dest = os.path.join(app_dest_default, app_dest) else: app_dest = app_dest_default if utils.safelyGetValue(build_json, "all-apps") == "true": app_dirs = os.listdir(app_src) apps_num = 0 for i_app_dir in app_dirs: if os.path.isdir(os.path.join(app_src, i_app_dir)): i_app_name = os.path.basename(i_app_dir) if not packAPP(build_json, os.path.join(app_src, i_app_name), app_dest, i_app_name): return False else: apps_num = apps_num + 1 if apps_num > 0: LOG.info("Totally packed %d apps in %s" % (apps_num, app_dir)) return True else: return packAPP(build_json, app_src, app_dest, app_name) return False
def buildPKGAPP(build_json=None): LOG.info("+Building package APP ...") if utils.safelyGetValue(build_json, "apk-type") == "MANIFEST": if not os.path.exists(os.path.join(BUILD_ROOT_SRC, "manifest.json")): LOG.error("Not found manifest.json in suite folder, please check!") sys.exit(1) if not utils.doCopy( os.path.join(BUILD_ROOT_SRC, "manifest.json"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "manifest.json")): return False if not utils.doCopy( os.path.join(BUILD_ROOT_SRC, "package.json"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "package.json")): return False if os.path.exists(os.path.join(BUILD_ROOT_SRC, "icon.png")): if not utils.doCopy(os.path.join(BUILD_ROOT_SRC, "icon.png"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "icon.png")): return False if os.path.exists(os.path.join(BUILD_ROOT_SRC, "icon.ico")): if not utils.doCopy(os.path.join(BUILD_ROOT_SRC, "icon.ico"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "icon.ico")): return False hosted_app = False if utils.safelyGetValue(build_json, "hosted-app") == "true": hosted_app = True if not createIndexFile(os.path.join(BUILD_ROOT_SRC_PKG_APP, "index.html"), hosted_app): return False if not hosted_app: if "blacklist" not in build_json: build_json.update({"blacklist": []}) build_json["blacklist"].extend(PKG_BLACK_LIST) if not buildSRC(BUILD_ROOT_SRC, BUILD_ROOT_PKG_APP, build_json): return False if "subapp-list" in build_json: for i_sub_app in build_json["subapp-list"].keys(): if not buildSubAPP(i_sub_app, build_json["subapp-list"][i_sub_app], BUILD_ROOT_PKG_APP): return False if not packAPP(build_json, BUILD_ROOT_SRC_PKG_APP, BUILD_ROOT_PKG, PKG_NAME): return False return True
def packAPP(build_json=None, app_src=None, app_dest=None, app_name=None): LOG.info("Packing %s(%s)" % (app_name, app_src)) if not os.path.exists(app_dest): try: os.makedirs(app_dest) except Exception as e: LOG.error("Fail to init package install dest dir: %s" % e) return False app_tpye = utils.safelyGetValue(build_json, "app-type") if utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye == "EXTENSION": if not build_extension.packExtension(build_json, app_src, app_dest, app_name): return False if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye != "EMBEDDINGAPI": if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "CORDOVA"): if BUILD_PARAMETERS.subversion == "4.x": if not build_cordova.packCordova_cli(build_json, app_src, app_dest, app_name): return False else: if not build_cordova.packCordova(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "EMBEDDINGAPI") or app_tpye == "EMBEDDINGAPI": app_version = None if "_" in app_name: index_flag = app_name.index("_") app_version = app_name[index_flag + 1 :] if app_version: utils.replaceUserString( app_src, "AndroidManifest.xml", "org.xwalk.embedding.test", "org.xwalk.embedding.test." + app_version ) utils.replaceUserString( app_src, "AndroidManifest.xml", "EmbeddingApiTestUnit", "EmbeddingApiTestUnit" + app_version ) main_dest = os.path.join(app_src, "src/org/xwalk/embedding") utils.replaceUserString( main_dest, "MainActivity.java", "org.xwalk.embedding.test", "org.xwalk.embedding.test." + app_version ) if BUILD_PARAMETERS.packtype and utils.checkContains(BUILD_PARAMETERS.packtype, "GRADLE"): if not build_embeddingapi.packEmbeddingAPI_gradle(build_json, app_src, app_dest, app_name, app_version): return False elif BUILD_PARAMETERS.packtype and utils.checkContains(BUILD_PARAMETERS.packtype, "MAVEN"): if not build_embeddingapi.packEmbeddingAPI_maven(build_json, app_src, app_dest, app_name, app_version): return False else: if not build_embeddingapi.packEmbeddingAPI_ant(build_json, app_src, app_dest, app_name, app_version): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "DEB"): if not build_deb.packDeb(build_json, app_src, app_dest, app_name): return False else: LOG.error("Got wrong pkg type: %s" % BUILD_PARAMETERS.pkgtype) return False LOG.info("Success to pack APP: %s" % app_name) return True
def buildPKGAPP(build_json=None): LOG.info("+Building package APP ...") if not utils.doCopy(os.path.join(BUILD_ROOT_SRC, "icon.png"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "icon.png")): return False hosted_app = False if utils.safelyGetValue(build_json, "hosted-app") == "true": hosted_app = True if not createIndexFile(os.path.join(BUILD_ROOT_SRC_PKG_APP, "index.html"), hosted_app): return False if not hosted_app: if "blacklist" not in build_json: build_json.update({"blacklist": []}) build_json["blacklist"].extend(PKG_BLACK_LIST) if not buildSRC(BUILD_ROOT_SRC, BUILD_ROOT_PKG_APP, build_json): return False if "subapp-list" in build_json: for i_sub_app in build_json["subapp-list"].keys(): if not buildSubAPP(i_sub_app, build_json["subapp-list"][i_sub_app], BUILD_ROOT_PKG_APP): return False if not packAPP(build_json, BUILD_ROOT_SRC_PKG_APP, BUILD_ROOT_PKG, PKG_NAME): return False return True
def buildPKGAPP(build_json=None): LOG.info("+Building package APP ...") if not utils.doCopy(os.path.join(BUILD_ROOT_SRC, "icon.png"), os.path.join(BUILD_ROOT_SRC_PKG_APP, "icon.png")): return False hosted_app = False if utils.safelyGetValue(build_json, "hosted-app") == "true": hosted_app = True if not createIndexFile( os.path.join(BUILD_ROOT_SRC_PKG_APP, "index.html"), hosted_app): return False if not hosted_app: if "blacklist" not in build_json: build_json.update({"blacklist": []}) build_json["blacklist"].extend(PKG_BLACK_LIST) if not buildSRC(BUILD_ROOT_SRC, BUILD_ROOT_PKG_APP, build_json): return False if "subapp-list" in build_json: for i_sub_app in build_json["subapp-list"].keys(): if not buildSubAPP( i_sub_app, build_json["subapp-list"][i_sub_app], BUILD_ROOT_PKG_APP): return False if not packAPP( build_json, BUILD_ROOT_SRC_PKG_APP, BUILD_ROOT_PKG, PKG_NAME): return False return True
def packWGT(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") if not utils.zipDir(app_src, os.path.join(app_dest, "%s.wgt" % app_name)): return False if BUILD_PARAMETERS.signature == True: if utils.safelyGetValue(build_json, "sign-flag") == "true": if not os.path.exists(os.path.join(BUILD_ROOT, "signing")): if not utils.doCopy( os.path.join(BUILD_PARAMETERS.pkgpacktools, "signing"), os.path.join(BUILD_ROOT, "signing")): return False signing_cmd = "%s --dist platform %s" % ( os.path.join(BUILD_ROOT, "signing", "sign-widget.sh"), os.path.join(app_dest, "%s.wgt" % app_name)) if not utils.doCMD(signing_cmd, DEFAULT_CMD_TIMEOUT): return False return True
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 main(): global LOG LOG = utils.getLogger("pack-tool") try: usage = "Usage: ./pack.py -t apk -m shared -a x86" opts_parser = OptionParser(usage=usage) opts_parser.add_option("-c", "--cfg", dest="pkgcfg", help="specify the path of config json file") opts_parser.add_option("-t", "--type", dest="pkgtype", help="specify the pkg type, e.g. apk, xpk, wgt ...") opts_parser.add_option( "-m", "--mode", dest="pkgmode", help="specify the apk mode, not for embeddingapi, e.g. shared, embedded" ) opts_parser.add_option( "-a", "--arch", dest="pkgarch", help="specify the apk arch, not for embeddingapi, cordova version 3.6, e.g. x86, arm", ) opts_parser.add_option( "-d", "--dest", dest="destdir", help="specify the installation folder for packed package" ) opts_parser.add_option("-s", "--src", dest="srcdir", help="specify the path of pkg resource for packing") opts_parser.add_option("--tools", dest="pkgpacktools", help="specify the parent folder of pack tools") opts_parser.add_option( "--notclean", dest="bnotclean", action="store_true", help="disable the build root clean after the packing" ) opts_parser.add_option( "--sign", dest="signature", action="store_true", help="signature operation will be done when packing wgt" ) opts_parser.add_option("-v", "--version", dest="bversion", action="store_true", help="show this tool's version") opts_parser.add_option("-u", "--user", dest="user", help="specify the user in inst.py") opts_parser.add_option( "--sub-version", dest="subversion", help="specify the embeddingapi, cordova sub version, e.g. v1, v2, v3 ...", ) opts_parser.add_option("--pkg-version", dest="pkgversion", help="specify the pkg version, e.g. 0.0.0.1") opts_parser.add_option("--pack-type", dest="packtype", help="specify the pack type, e.g. gradle, maven") opts_parser.add_option( "--notdebug", dest="bnotdebug", action="store_true", help="specify the packed pkg is not debug mode" ) if len(sys.argv) == 1: sys.argv.append("-h") global BUILD_PARAMETERS (BUILD_PARAMETERS, args) = opts_parser.parse_args() except Exception as e: LOG.error("Got wrong options: %s, exit ..." % e) sys.exit(1) if BUILD_PARAMETERS.bversion: print "Version: %s" % TOOL_VERSION sys.exit(0) if not BUILD_PARAMETERS.srcdir: BUILD_PARAMETERS.srcdir = os.getcwd() BUILD_PARAMETERS.srcdir = os.path.expanduser(BUILD_PARAMETERS.srcdir) if not BUILD_PARAMETERS.user: BUILD_PARAMETERS.user = "******" if not os.path.exists(os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", VERSION_FILE)): if not os.path.exists(os.path.join(BUILD_PARAMETERS.srcdir, "..", VERSION_FILE)): if not os.path.exists(os.path.join(BUILD_PARAMETERS.srcdir, VERSION_FILE)): LOG.info("Not found pkg version file, try to use option --pkg-version") pkg_version_file_path = None else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, VERSION_FILE) else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "..", VERSION_FILE) else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", VERSION_FILE) try: pkg_main_version = 0 pkg_release_version = 1 if BUILD_PARAMETERS.pkgversion: LOG.info("Using %s as pkg version " % BUILD_PARAMETERS.pkgversion) pkg_main_version = BUILD_PARAMETERS.pkgversion else: if pkg_version_file_path is not None: LOG.info("Using pkg version file: %s" % pkg_version_file_path) with open(pkg_version_file_path, "rt") as pkg_version_file: pkg_version_raw = pkg_version_file.read() pkg_version_file.close() pkg_version_json = json.loads(pkg_version_raw) pkg_main_version = pkg_version_json["main-version"] pkg_release_version = pkg_version_json["release-version"] CROSSWALK_BRANCH = pkg_version_json["crosswalk-branch"] except Exception as e: LOG.error("Fail to read pkg version file: %s, exit ..." % e) sys.exit(1) CROSSWALK_VERSION = pkg_main_version if not BUILD_PARAMETERS.pkgtype: LOG.error("No pkg type provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgtype in PKG_TYPES: LOG.error("Wrong pkg type, only support: %s, exit ..." % PKG_TYPES) sys.exit(1) if BUILD_PARAMETERS.pkgtype == "apk" or BUILD_PARAMETERS.pkgtype == "apk-aio": if not BUILD_PARAMETERS.pkgmode: LOG.error("No pkg mode option provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgmode in PKG_MODES: LOG.error("Wrong pkg mode option provided, only support:%s, exit ..." % PKG_MODES) sys.exit(1) if not BUILD_PARAMETERS.pkgarch: LOG.error("No pkg arch option provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgarch in PKG_ARCHS: LOG.error("Wrong pkg arch option provided, only support:%s, exit ..." % PKG_ARCHS) sys.exit(1) if BUILD_PARAMETERS.pkgtype == "apk-aio" or BUILD_PARAMETERS.pkgtype == "cordova-aio": if not BUILD_PARAMETERS.destdir or not os.path.exists(BUILD_PARAMETERS.destdir): LOG.error("No all-in-one installation dest dir found, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.destdir: BUILD_PARAMETERS.destdir = BUILD_PARAMETERS.srcdir BUILD_PARAMETERS.destdir = os.path.expanduser(BUILD_PARAMETERS.destdir) if not BUILD_PARAMETERS.pkgpacktools: BUILD_PARAMETERS.pkgpacktools = os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", "tools") BUILD_PARAMETERS.pkgpacktools = os.path.expanduser(BUILD_PARAMETERS.pkgpacktools) config_json = None if BUILD_PARAMETERS.pkgcfg: config_json_file_path = BUILD_PARAMETERS.pkgcfg else: config_json_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "suite.json") try: LOG.info("Using config json file: %s" % config_json_file_path) with open(config_json_file_path, "rt") as config_json_file: config_raw = config_json_file.read() config_json_file.close() config_json = json.loads(config_raw) except Exception as e: LOG.error("Fail to read config json file: %s, exit ..." % e) sys.exit(1) global PKG_NAME PKG_NAME = utils.safelyGetValue(config_json, "pkg-name") if not PKG_NAME: PKG_NAME = os.path.basename(BUILD_PARAMETERS.srcdir) LOG.warning("Fail to read pkg name from json, " "using src dir name as pkg name ...") LOG.info("================= %s (%s-%s) ================" % (PKG_NAME, pkg_main_version, pkg_release_version)) if not utils.safelyGetValue(config_json, "pkg-list"): LOG.error("Fail to read pkg-list, exit ...") sys.exit(1) pkg_json = None global parameters_type parameters_type = None cordova_subv_list = ["4.x", "3.6"] if BUILD_PARAMETERS.pkgtype == "cordova" or BUILD_PARAMETERS.pkgtype == "cordova-aio": if BUILD_PARAMETERS.pkgarch and not BUILD_PARAMETERS.pkgarch in PKG_ARCHS: LOG.error("Wrong pkg-arch, only support: %s, exit ..." % PKG_ARCHS) sys.exit(1) if BUILD_PARAMETERS.pkgmode and not BUILD_PARAMETERS.pkgmode in PKG_MODES: LOG.error("Wrong pkg-mode, only support: %s, exit ..." % PKG_MODES) sys.exit(1) if BUILD_PARAMETERS.subversion: if not str(BUILD_PARAMETERS.subversion) in cordova_subv_list: LOG.error("The argument of cordova --sub-version can only be '3.6' or '4.x' , exit ...") sys.exit(1) parameters_type = BUILD_PARAMETERS.pkgtype + BUILD_PARAMETERS.subversion if ( BUILD_PARAMETERS.subversion == "4.x" and BUILD_PARAMETERS.packtype ) and not BUILD_PARAMETERS.packtype in CORDOVA_PACK_TYPES: LOG.error("cordova packtype can only be npm, local") sys.exit(1) if (BUILD_PARAMETERS.subversion == "3.6" or not BUILD_PARAMETERS.subversion) and BUILD_PARAMETERS.packtype: LOG.error("cordova packtype is only for cordova version 4.x") sys.exit(1) if (BUILD_PARAMETERS.subversion == "3.6" or not BUILD_PARAMETERS.subversion) and BUILD_PARAMETERS.pkgarch: LOG.error("Command -a is not for cordova version 3.6") sys.exit(1) if BUILD_PARAMETERS.pkgtype == "embeddingapi": if BUILD_PARAMETERS.packtype and not BUILD_PARAMETERS.packtype in PACK_TYPES: LOG.error("embeddingapi packtype can only be gradle, maven or ant") sys.exit(1) if BUILD_PARAMETERS.subversion: BUILD_PARAMETERS.pkgtype = BUILD_PARAMETERS.pkgtype + BUILD_PARAMETERS.subversion all_pkg_string = "".join(config_json["pkg-list"].keys()) if parameters_type and parameters_type in all_pkg_string: for i_pkg in config_json["pkg-list"].keys(): i_pkg_list = i_pkg.replace(" ", "").split(",") if parameters_type in i_pkg_list: pkg_json = config_json["pkg-list"][i_pkg] break elif BUILD_PARAMETERS.pkgtype in all_pkg_string: for i_pkg in config_json["pkg-list"].keys(): i_pkg_list = i_pkg.replace(" ", "").split(",") if BUILD_PARAMETERS.pkgtype in i_pkg_list: pkg_json = config_json["pkg-list"][i_pkg] break if pkg_json == config_json["pkg-list"].get("apk") and BUILD_PARAMETERS.subversion is not None: pkg_json = config_json["pkg-list"][BUILD_PARAMETERS.subversion] if not pkg_json: LOG.error("Fail to read pkg json, exit ...") sys.exit(1) if not prepareBuildRoot(): exitHandler(1) if "pkg-blacklist" in config_json: PKG_BLACK_LIST.extend(config_json["pkg-blacklist"]) try: varshop.setValue("BUILD_PARAMETERS", BUILD_PARAMETERS) varshop.setValue("BUILD_ROOT", BUILD_ROOT) varshop.setValue("BUILD_ROOT_SRC", BUILD_ROOT_SRC) varshop.setValue("BUILD_TIME", BUILD_TIME) varshop.setValue("CROSSWALK_BRANCH", CROSSWALK_BRANCH) varshop.setValue("CROSSWALK_VERSION", CROSSWALK_VERSION) varshop.setValue("DEFAULT_CMD_TIMEOUT", DEFAULT_CMD_TIMEOUT) varshop.setValue("PKG_MODES", PKG_MODES) varshop.setValue("PKG_ARCHS", PKG_ARCHS) except Exception as e: LOG.error("Fail to set global vars: %s, exit ..." % e) sys.exit(1) if not buildPKG(pkg_json): exitHandler(1) LOG.info("+Building package ...") if BUILD_PARAMETERS.pkgtype == "apk-aio" or BUILD_PARAMETERS.pkgtype == "cordova-aio": pkg_file_list = os.listdir(os.path.join(BUILD_ROOT, "pkg")) for i_file in pkg_file_list: if not utils.doCopy( os.path.join(BUILD_ROOT, "pkg", i_file), os.path.join(BUILD_PARAMETERS.destdir, i_file) ): exitHandler(1) elif BUILD_PARAMETERS.pkgtype == "embeddingapi" and BUILD_PARAMETERS.subversion: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s-%s.%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.subversion, BUILD_PARAMETERS.pkgtype), ) LOG.info("pkg_file: %s" % pkg_file) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1) elif BUILD_PARAMETERS.pkgtype.startswith("embeddingapi") and BUILD_PARAMETERS.packtype: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s.%s-%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.pkgtype, BUILD_PARAMETERS.packtype), ) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1) else: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s.%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.pkgtype), ) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1)
def packAPP(build_json=None, app_src=None, app_dest=None, app_name=None): LOG.info("Packing %s(%s)" % (app_name, app_src)) if not os.path.exists(app_dest): try: os.makedirs(app_dest) except Exception as e: LOG.error("Fail to init package install dest dir: %s" % e) return False app_tpye = utils.safelyGetValue(build_json, 'app-type') if utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye == "EXTENSION": if not build_extension.packExtension(build_json, app_src, app_dest, app_name): return False if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye != "EMBEDDINGAPI": if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "CORDOVA"): if BUILD_PARAMETERS.subversion == '4.x': if not build_cordova.packCordova_cli(build_json, app_src, app_dest, app_name): return False else: if not build_cordova.packCordova(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "EMBEDDINGAPI") or app_tpye == "EMBEDDINGAPI": app_version = None if "_" in app_name: index_flag = app_name.index("_") app_version = app_name[index_flag + 1:] if app_version: utils.replaceUserString(app_src, 'AndroidManifest.xml', 'org.xwalk.embedding.test', "org.xwalk.embedding.test." + app_version) utils.replaceUserString(app_src, 'AndroidManifest.xml', 'EmbeddingApiTestUnit', "EmbeddingApiTestUnit" + app_version) main_dest = os.path.join(app_src, "src/org/xwalk/embedding") utils.replaceUserString(main_dest, 'MainActivity.java', 'org.xwalk.embedding.test', "org.xwalk.embedding.test." + app_version) if BUILD_PARAMETERS.packtype and utils.checkContains( BUILD_PARAMETERS.packtype, "GRADLE"): if not build_embeddingapi.packEmbeddingAPI_gradle( build_json, app_src, app_dest, app_name, app_version): return False elif BUILD_PARAMETERS.packtype and utils.checkContains( BUILD_PARAMETERS.packtype, "MAVEN"): if not build_embeddingapi.packEmbeddingAPI_maven( build_json, app_src, app_dest, app_name, app_version): return False else: if not build_embeddingapi.packEmbeddingAPI_ant( build_json, app_src, app_dest, app_name, app_version): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "DEB"): if not build_deb.packDeb(build_json, app_src, app_dest, app_name): return False else: LOG.error("Got wrong pkg type: %s" % BUILD_PARAMETERS.pkgtype) return False LOG.info("Success to pack APP: %s" % app_name) 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 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 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 packCordova(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 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 version_opt = utils.safelyGetValue(build_json, "apk-version-opt") if version_opt: utils.replaceUserString( project_root, "config.xml", 'id="org.xwalk.%s" version="0.0.1"' % app_name, 'id="org.xwalk.%s" version="%s"' % (app_name, version_opt), ) # 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 = "core" if BUILD_PARAMETERS.pkgmode == "shared": pkg_mode_tmp = "shared" 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 version_parameter = "XWALK_VERSION" install_variable_cmd = '--variable XWALK_MODE="%s" --variable %s="%s"' % ( BUILD_PARAMETERS.pkgmode, version_parameter, 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 --minSdkVersion=16" % 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 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 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 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 packAPP(build_json=None, app_src=None, app_dest=None, app_name=None): LOG.info("Packing %s(%s)" % (app_name, app_src)) if not os.path.exists(app_dest): try: os.makedirs(app_dest) except Exception as e: LOG.error("Fail to init package install dest dir: %s" % e) return False app_tpye = utils.safelyGetValue(build_json, 'app-type') if utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye == "EXTENSION": if not build_extension.packExtension(build_json, app_src, app_dest, app_name): return False if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "APK") and app_tpye != "EMBEDDINGAPI": if not build_android.packAPK(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "CORDOVA"): if not build_cordova.packCordova(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "EMBEDDINGAPI") or app_tpye == "EMBEDDINGAPI": app_version = None if "_" in app_name: index_flag = app_name.index("_") app_version = app_name[index_flag + 1:] if app_version: utils.replaceUserString( app_src, 'AndroidManifest.xml', 'org.xwalk.embedding.test', "org.xwalk.embedding.test." + app_version) utils.replaceUserString( app_src, 'AndroidManifest.xml', 'org.xwalk.embedding.asynctest', "org.xwalk.embedding.asynctest." + app_version) utils.replaceUserString( app_src, 'AndroidManifest.xml', 'EmbeddingApiTestUnit', "EmbeddingApiTestUnit" + app_version) utils.replaceUserString( app_src, 'AndroidManifest.xml', 'EmbeddingApiAsynctestUnit', "EmbeddingApiAsynctestUnit" + app_version) if app_version != "v6": utils.replaceUserString( app_src, 'AndroidManifest.xml', '<provider android:name=\"org.xwalk.embedding.base.TestContentProvider\"' + ' android:authorities=\"org.xwalk.embedding.base.TestContentProvider\" />', "") main_dest = os.path.join(app_src, "src/org/xwalk/embedding") utils.replaceUserString( main_dest, 'MainActivity.java', 'org.xwalk.embedding.test', "org.xwalk.embedding.test." + app_version) utils.replaceUserString( main_dest, 'MainActivity.java', 'org.xwalk.embedding.asynctest', "org.xwalk.embedding.asynctest." + app_version) if BUILD_PARAMETERS.packtype and utils.checkContains( BUILD_PARAMETERS.packtype, "GRADLE"): if not build_embeddingapi.packEmbeddingAPI_gradle( build_json, app_src, app_dest, app_name, app_version): return False elif BUILD_PARAMETERS.packtype and utils.checkContains(BUILD_PARAMETERS.packtype, "MAVEN"): if not build_embeddingapi.packEmbeddingAPI_maven( build_json, app_src, app_dest, app_name, app_version): return False else: if not build_embeddingapi.packEmbeddingAPI_ant( build_json, app_src, app_dest, app_name, app_version): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "DEB"): if not build_deb.packDeb(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "MSI"): if not build_msi.packMsi(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "ios"): if not build_ios.packIOS(build_json, app_src, app_dest, app_name): return False elif utils.checkContains(BUILD_PARAMETERS.pkgtype, "iot"): if not build_iot.packIoT(build_json, app_src, app_dest, app_name): return False else: LOG.error("Got wrong pkg type: %s" % BUILD_PARAMETERS.pkgtype) return False LOG.info("Success to pack APP: %s" % app_name) 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 packCordova(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 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 version_opt = utils.safelyGetValue(build_json, "apk-version-opt") if version_opt: utils.replaceUserString( project_root, 'config.xml', 'id="org.xwalk.%s" version="1.0.0"' % app_name, 'id="org.xwalk.%s" version="%s"' % (app_name, version_opt)) # 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 = "core" if BUILD_PARAMETERS.pkgmode == "shared": pkg_mode_tmp = "shared" 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 version_parameter = "XWALK_VERSION" install_variable_cmd = "--variable XWALK_MODE=\"%s\" --variable %s=\"%s\"" \ % (BUILD_PARAMETERS.pkgmode, version_parameter, 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 main(): global LOG LOG = utils.getLogger("pack-tool") try: usage = "Usage: ./pack.py -t apk -m shared -a x86" opts_parser = OptionParser(usage=usage) opts_parser.add_option("-c", "--cfg", dest="pkgcfg", help="specify the path of config json file") opts_parser.add_option( "-t", "--type", dest="pkgtype", help="specify the pkg type, e.g. apk, cordova ...") opts_parser.add_option( "-m", "--mode", dest="pkgmode", help= "specify the apk mode, not for embeddingapi, e.g. shared, embedded" ) opts_parser.add_option( "-a", "--arch", dest="pkgarch", help= "specify the apk arch, not for embeddingapi, cordova version 3.6, e.g. x86, arm" ) opts_parser.add_option( "-d", "--dest", dest="destdir", help="specify the installation folder for packed package") opts_parser.add_option( "-s", "--src", dest="srcdir", help="specify the path of pkg resource for packing") opts_parser.add_option("--tools", dest="pkgpacktools", help="specify the parent folder of pack tools") opts_parser.add_option( "--notclean", dest="bnotclean", action="store_true", help="disable the build root clean after the packing") opts_parser.add_option("-v", "--version", dest="bversion", action="store_true", help="show this tool's version") opts_parser.add_option("-u", "--user", dest="user", help="specify the user in inst.py") opts_parser.add_option( "--sub-version", dest="subversion", help= "specify the embeddingapi, cordova sub version, e.g. v1, v2, v3 ..." ) opts_parser.add_option("--pkg-version", dest="pkgversion", help="specify the pkg version, e.g. 0.0.0.1") opts_parser.add_option( "--pack-type", dest="packtype", help="specify the pack type, e.g. gradle, maven") opts_parser.add_option("--notdebug", dest="bnotdebug", action="store_true", help="specify the packed pkg is not debug mode") if len(sys.argv) == 1: sys.argv.append("-h") global BUILD_PARAMETERS (BUILD_PARAMETERS, args) = opts_parser.parse_args() except Exception as e: LOG.error("Got wrong options: %s, exit ..." % e) sys.exit(1) if BUILD_PARAMETERS.bversion: print "Version: %s" % TOOL_VERSION sys.exit(0) if not BUILD_PARAMETERS.srcdir: BUILD_PARAMETERS.srcdir = os.getcwd() BUILD_PARAMETERS.srcdir = os.path.expanduser(BUILD_PARAMETERS.srcdir) if not BUILD_PARAMETERS.user: BUILD_PARAMETERS.user = "******" if not os.path.exists( os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", VERSION_FILE)): if not os.path.exists( os.path.join(BUILD_PARAMETERS.srcdir, "..", VERSION_FILE)): if not os.path.exists( os.path.join(BUILD_PARAMETERS.srcdir, VERSION_FILE)): LOG.info( "Not found pkg version file, try to use option --pkg-version" ) pkg_version_file_path = None else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, VERSION_FILE) else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "..", VERSION_FILE) else: pkg_version_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", VERSION_FILE) try: pkg_main_version = 0 pkg_release_version = 1 if BUILD_PARAMETERS.pkgversion: LOG.info("Using %s as pkg version " % BUILD_PARAMETERS.pkgversion) pkg_main_version = BUILD_PARAMETERS.pkgversion CROSSWALK_BRANCH = "master" else: if pkg_version_file_path is not None: LOG.info("Using pkg version file: %s" % pkg_version_file_path) with open(pkg_version_file_path, "rt") as pkg_version_file: pkg_version_raw = pkg_version_file.read() pkg_version_file.close() pkg_version_json = json.loads(pkg_version_raw) pkg_main_version = pkg_version_json["main-version"] pkg_release_version = pkg_version_json["release-version"] CROSSWALK_BRANCH = pkg_version_json["crosswalk-branch"] except Exception as e: LOG.error("Fail to read pkg version file: %s, exit ..." % e) sys.exit(1) CROSSWALK_VERSION = pkg_main_version if not BUILD_PARAMETERS.pkgtype: LOG.error("No pkg type provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgtype in PKG_TYPES: LOG.error("Wrong pkg type, only support: %s, exit ..." % PKG_TYPES) sys.exit(1) if BUILD_PARAMETERS.pkgtype == "apk" or \ BUILD_PARAMETERS.pkgtype == "apk-aio": if not BUILD_PARAMETERS.pkgmode: LOG.error("No pkg mode option provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgmode in PKG_MODES: LOG.error( "Wrong pkg mode option provided, only support:%s, exit ..." % PKG_MODES) sys.exit(1) if not BUILD_PARAMETERS.pkgarch: LOG.error("No pkg arch option provided, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.pkgarch in PKG_ARCHS: LOG.error( "Wrong pkg arch option provided, only support:%s, exit ..." % PKG_ARCHS) sys.exit(1) if BUILD_PARAMETERS.pkgtype == "apk-aio" or \ BUILD_PARAMETERS.pkgtype == "cordova-aio": if not BUILD_PARAMETERS.destdir or not os.path.exists( BUILD_PARAMETERS.destdir): LOG.error("No all-in-one installation dest dir found, exit ...") sys.exit(1) elif not BUILD_PARAMETERS.destdir: BUILD_PARAMETERS.destdir = BUILD_PARAMETERS.srcdir BUILD_PARAMETERS.destdir = os.path.expanduser(BUILD_PARAMETERS.destdir) if not BUILD_PARAMETERS.pkgpacktools: BUILD_PARAMETERS.pkgpacktools = os.path.join(BUILD_PARAMETERS.srcdir, "..", "..", "tools") BUILD_PARAMETERS.pkgpacktools = os.path.expanduser( BUILD_PARAMETERS.pkgpacktools) config_json = None if BUILD_PARAMETERS.pkgcfg: config_json_file_path = BUILD_PARAMETERS.pkgcfg else: config_json_file_path = os.path.join(BUILD_PARAMETERS.srcdir, "suite.json") try: LOG.info("Using config json file: %s" % config_json_file_path) with open(config_json_file_path, "rt") as config_json_file: config_raw = config_json_file.read() config_json_file.close() config_json = json.loads(config_raw) except Exception as e: LOG.error("Fail to read config json file: %s, exit ..." % e) sys.exit(1) global PKG_NAME PKG_NAME = utils.safelyGetValue(config_json, "pkg-name") if not PKG_NAME: PKG_NAME = os.path.basename(BUILD_PARAMETERS.srcdir) LOG.warning("Fail to read pkg name from json, " "using src dir name as pkg name ...") LOG.info("================= %s (%s-%s) ================" % (PKG_NAME, pkg_main_version, pkg_release_version)) if not utils.safelyGetValue(config_json, "pkg-list"): LOG.error("Fail to read pkg-list, exit ...") sys.exit(1) pkg_json = None global parameters_type parameters_type = None cordova_subv_list = ['4.x', '3.6'] if BUILD_PARAMETERS.pkgtype == "cordova" or BUILD_PARAMETERS.pkgtype == "cordova-aio": if BUILD_PARAMETERS.pkgarch and not BUILD_PARAMETERS.pkgarch in PKG_ARCHS: LOG.error("Wrong pkg-arch, only support: %s, exit ..." % PKG_ARCHS) sys.exit(1) if BUILD_PARAMETERS.pkgmode and not BUILD_PARAMETERS.pkgmode in PKG_MODES: LOG.error("Wrong pkg-mode, only support: %s, exit ..." % PKG_MODES) sys.exit(1) if BUILD_PARAMETERS.subversion: if not str(BUILD_PARAMETERS.subversion) in cordova_subv_list: LOG.error( "The argument of cordova --sub-version can only be '3.6' or '4.x' , exit ..." ) sys.exit(1) parameters_type = BUILD_PARAMETERS.pkgtype + \ BUILD_PARAMETERS.subversion if (BUILD_PARAMETERS.subversion == '4.x' and BUILD_PARAMETERS.packtype ) and not BUILD_PARAMETERS.packtype in CORDOVA_PACK_TYPES: LOG.error("cordova packtype can only be npm, local") sys.exit(1) if (BUILD_PARAMETERS.subversion == '3.6' or not BUILD_PARAMETERS.subversion) and BUILD_PARAMETERS.packtype: LOG.error("cordova packtype is only for cordova version 4.x") sys.exit(1) if (BUILD_PARAMETERS.subversion == '3.6' or not BUILD_PARAMETERS.subversion) and BUILD_PARAMETERS.pkgarch: LOG.error("Command -a is not for cordova version 3.6") sys.exit(1) if BUILD_PARAMETERS.pkgtype == "embeddingapi": if BUILD_PARAMETERS.packtype and not BUILD_PARAMETERS.packtype in PACK_TYPES: LOG.error("embeddingapi packtype can only be gradle, maven or ant") sys.exit(1) if BUILD_PARAMETERS.subversion: BUILD_PARAMETERS.pkgtype = BUILD_PARAMETERS.pkgtype + \ BUILD_PARAMETERS.subversion all_pkg_string = "".join(config_json["pkg-list"].keys()) if parameters_type and parameters_type in all_pkg_string: for i_pkg in config_json["pkg-list"].keys(): i_pkg_list = i_pkg.replace(" ", "").split(",") if parameters_type in i_pkg_list: pkg_json = config_json["pkg-list"][i_pkg] break elif BUILD_PARAMETERS.pkgtype in all_pkg_string: for i_pkg in config_json["pkg-list"].keys(): i_pkg_list = i_pkg.replace(" ", "").split(",") if BUILD_PARAMETERS.pkgtype in i_pkg_list: pkg_json = config_json["pkg-list"][i_pkg] break if pkg_json == config_json['pkg-list'].get( 'apk') and BUILD_PARAMETERS.subversion is not None: pkg_json = config_json["pkg-list"][BUILD_PARAMETERS.subversion] if not pkg_json: LOG.error("Fail to read pkg json, exit ...") sys.exit(1) if not prepareBuildRoot(): exitHandler(1) if "pkg-blacklist" in config_json: PKG_BLACK_LIST.extend(config_json["pkg-blacklist"]) try: varshop.setValue("BUILD_PARAMETERS", BUILD_PARAMETERS) varshop.setValue("BUILD_ROOT", BUILD_ROOT) varshop.setValue("BUILD_ROOT_SRC", BUILD_ROOT_SRC) varshop.setValue("BUILD_TIME", BUILD_TIME) varshop.setValue("CROSSWALK_BRANCH", CROSSWALK_BRANCH) varshop.setValue("CROSSWALK_VERSION", CROSSWALK_VERSION) varshop.setValue("DEFAULT_CMD_TIMEOUT", DEFAULT_CMD_TIMEOUT) varshop.setValue("PKG_MODES", PKG_MODES) varshop.setValue("PKG_ARCHS", PKG_ARCHS) except Exception as e: LOG.error("Fail to set global vars: %s, exit ..." % e) sys.exit(1) if not buildPKG(pkg_json): exitHandler(1) LOG.info("+Building package ...") if BUILD_PARAMETERS.pkgtype == "apk-aio" or \ BUILD_PARAMETERS.pkgtype == "cordova-aio": pkg_file_list = os.listdir(os.path.join(BUILD_ROOT, "pkg")) for i_file in pkg_file_list: if not utils.doCopy(os.path.join(BUILD_ROOT, "pkg", i_file), os.path.join(BUILD_PARAMETERS.destdir, i_file)): exitHandler(1) elif BUILD_PARAMETERS.pkgtype == "embeddingapi" and BUILD_PARAMETERS.subversion: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s-%s.%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.subversion, BUILD_PARAMETERS.pkgtype)) LOG.info("pkg_file: %s" % pkg_file) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1) elif BUILD_PARAMETERS.pkgtype.startswith( "embeddingapi") and BUILD_PARAMETERS.packtype: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s.%s-%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.pkgtype, BUILD_PARAMETERS.packtype)) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1) else: pkg_file = os.path.join( BUILD_PARAMETERS.destdir, "%s-%s-%s.%s.zip" % (PKG_NAME, pkg_main_version, pkg_release_version, BUILD_PARAMETERS.pkgtype)) if not utils.zipDir(os.path.join(BUILD_ROOT, "pkg"), pkg_file): exitHandler(1)
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