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
Beispiel #2
0
def buildSRC(src=None, dest=None, build_json=None):
    if not os.path.exists(src):
        LOG.info("+Src dir does not exist, skip build src process ...")
        return True

    if not utils.doCopy(src, dest):
        return False
    if "blacklist" in build_json:
        if build_json["blacklist"].count("") > 0:
            build_json["blacklist"].remove("")
        black_file_list = []
        for i_black in build_json["blacklist"]:
            black_file_list = black_file_list + glob.glob(os.path.join(dest, i_black))

        black_file_list = list(set(black_file_list))
        if not utils.doRemove(black_file_list):
            return False
    if "copylist" in build_json:
        for i_s_key in build_json["copylist"].keys():
            if i_s_key and build_json["copylist"][i_s_key]:
                (src_updated, dest_updated) = updateCopylistPrefix(src, dest, i_s_key, build_json["copylist"][i_s_key])
                if not utils.doCopy(src_updated, dest_updated):
                    return False

    return True
Beispiel #3
0
def buildSRC(src=None, dest=None, build_json=None):
    if not os.path.exists(src):
        LOG.info("+Src dir does not exist, skip build src process ...")
        return True

    if not utils.doCopy(src, dest):
        return False
    if "blacklist" in build_json:
        if build_json["blacklist"].count("") > 0:
            build_json["blacklist"].remove("")
        black_file_list = []
        for i_black in build_json["blacklist"]:
            black_file_list = black_file_list + \
                glob.glob(os.path.join(dest, i_black))

        black_file_list = list(set(black_file_list))
        if not utils.doRemove(black_file_list):
            return False
    if "copylist" in build_json:
        for i_s_key in build_json["copylist"].keys():
            if i_s_key and build_json["copylist"][i_s_key]:
                (src_updated, dest_updated) = updateCopylistPrefix(
                    src, dest, i_s_key, build_json["copylist"][i_s_key])
                if not utils.doCopy(src_updated, dest_updated):
                    return False

    return True
def 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 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
Beispiel #6
0
def prepareBuildRoot():
    LOG.info("+Preparing build root folder ...")
    global BUILD_ROOT
    global BUILD_ROOT_SRC
    global BUILD_ROOT_SRC_PKG
    global BUILD_ROOT_SRC_PKG_APP
    global BUILD_ROOT_SRC_SUB_APP
    global BUILD_ROOT_PKG
    global BUILD_ROOT_PKG_APP

    while True:
        BUILD_ROOT = os.path.join("/tmp", utils.getRandomStr())
        if os.path.exists(BUILD_ROOT):
            continue
        else:
            break

    BUILD_ROOT_SRC = os.path.join(BUILD_ROOT, PKG_NAME)
    BUILD_ROOT_SRC_PKG = os.path.join(BUILD_ROOT, "pkg")
    BUILD_ROOT_SRC_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app")
    BUILD_ROOT_SRC_SUB_APP = os.path.join(BUILD_ROOT, "sub-app")
    BUILD_ROOT_PKG = os.path.join(BUILD_ROOT, "pkg", "opt", PKG_NAME)
    BUILD_ROOT_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app", "opt", PKG_NAME)

    if not utils.doCopy(BUILD_PARAMETERS.srcdir, BUILD_ROOT_SRC):
        return False
    else:
        utils.replaceUserString(BUILD_ROOT_SRC, "*", "TESTER-HOME-DIR", "/home/%s" % BUILD_PARAMETERS.user)

    if not utils.doRemove(glob.glob(os.path.join(BUILD_ROOT_SRC, "%s*.zip" % PKG_NAME))):
        return False

    return True
Beispiel #7
0
def prepareBuildRoot():
    LOG.info("+Preparing build root folder ...")
    global BUILD_ROOT
    global BUILD_ROOT_SRC
    global BUILD_ROOT_SRC_PKG
    global BUILD_ROOT_SRC_PKG_APP
    global BUILD_ROOT_SRC_SUB_APP
    global BUILD_ROOT_PKG
    global BUILD_ROOT_PKG_APP

    while True:
        BUILD_ROOT = os.path.join("/tmp", utils.getRandomStr())
        if os.path.exists(BUILD_ROOT):
            continue
        else:
            break

    BUILD_ROOT_SRC = os.path.join(BUILD_ROOT, PKG_NAME)
    BUILD_ROOT_SRC_PKG = os.path.join(BUILD_ROOT, "pkg")
    BUILD_ROOT_SRC_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app")
    BUILD_ROOT_SRC_SUB_APP = os.path.join(BUILD_ROOT, "sub-app")
    BUILD_ROOT_PKG = os.path.join(BUILD_ROOT, "pkg", "opt", PKG_NAME)
    BUILD_ROOT_PKG_APP = os.path.join(BUILD_ROOT, "pkg-app", "opt", PKG_NAME)

    if not utils.doCopy(BUILD_PARAMETERS.srcdir, BUILD_ROOT_SRC):
        return False
    else:
        utils.replaceUserString(BUILD_ROOT_SRC, '*', 'TESTER-HOME-DIR',
                                "/home/%s" % BUILD_PARAMETERS.user)

    if not utils.doRemove(
            glob.glob(os.path.join(BUILD_ROOT_SRC, "%s*.zip" % PKG_NAME))):
        return False

    return True
def 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 packIOS(build_json = None, app_src = None, app_dest = None, app_name = None):
    '''
    Build iOS ipa via crosswalk-app, currently crosswalk-pkg for iOS does not
    support yet.
    '''
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")

    package_id = 'org.xwalk.{app_name}'.format(
                            app_name = app_name.replace('-', ''))
    create_cmd = 'crosswalk-app create {package_id} --platform=ios'.format(
                                        package_id = package_id)

    orig_dir = os.getcwd()
    os.chdir(BUILD_ROOT)
    if not utils.doCMD(create_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    move_app_cmd =  'mv -fv {app_src}/* ' \
                    '{BUILD_ROOT}/{package_id}/app/'.format(
                        app_src = app_src,
                        BUILD_ROOT = BUILD_ROOT,
                        package_id = package_id)
    if not utils.doCMD(move_app_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    os.chdir(package_id)
    create_cmd = 'crosswalk-app build'
    if not utils.doCMD(create_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    ipa_files = glob.glob(os.path.join(BUILD_ROOT, package_id, "*.ipa"))
    if ipa_files:
        rename_app_name = app_name.replace('-', '_')
        if not utils.doCopy(ipa_files[0],
                            os.path.join(
                                app_dest,
                                "{app_name}.ipa".format(
                                    app_name = rename_app_name)
                            )):
            os.chdir(orig_dir)
            return False
    else:
        LOG.error("Fail to find the ipa file")
        os.chdir(orig_dir)
        return False

    return True
Beispiel #10
0
def packIOS(build_json=None, app_src=None, app_dest=None, app_name=None):
    '''
    Build iOS ipa via crosswalk-app, currently crosswalk-pkg for iOS does not
    support yet.
    '''
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")

    package_id = 'org.xwalk.{app_name}'.format(
        app_name=app_name.replace('-', ''))
    create_cmd = 'crosswalk-app create {package_id} --platform=ios'.format(
        package_id=package_id)

    orig_dir = os.getcwd()
    os.chdir(BUILD_ROOT)
    if not utils.doCMD(create_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    move_app_cmd =  'mv -fv {app_src}/* ' \
                    '{BUILD_ROOT}/{package_id}/app/'.format(
                        app_src = app_src,
                        BUILD_ROOT = BUILD_ROOT,
                        package_id = package_id)
    if not utils.doCMD(move_app_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    os.chdir(package_id)
    create_cmd = 'crosswalk-app build'
    if not utils.doCMD(create_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    ipa_files = glob.glob(os.path.join(BUILD_ROOT, package_id, "*.ipa"))
    if ipa_files:
        rename_app_name = app_name.replace('-', '_')
        if not utils.doCopy(
                ipa_files[0],
                os.path.join(app_dest, "{app_name}.ipa".format(
                    app_name=rename_app_name))):
            os.chdir(orig_dir)
            return False
    else:
        LOG.error("Fail to find the ipa file")
        os.chdir(orig_dir)
        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 packCordova_cli(
        build_json=None, app_src=None, app_dest=None, app_name=None):
    BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS")
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")
    CROSSWALK_BRANCH= varshop.getValue("CROSSWALK_BRANCH")
    CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION")
    DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT")
    app_name = app_name.replace("-", "_")
    project_root = os.path.join(BUILD_ROOT, app_name)

    output = commands.getoutput("cordova -v")
    output_version = int(output[0])
    if output_version < 5:
        LOG.error(
            "Cordova 4.x build requires the latest Cordova CLI, and must >= 5.0.0, install with command: '$ sudo npm install cordova -g'")
        return False

    plugin_tool = os.path.join(BUILD_ROOT, "cordova_plugins")
    plugin_source = os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins")
    if not os.path.exists(plugin_tool):
        if os.path.exists(plugin_source):
            if not utils.doCopy(
                    os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins"),
                    plugin_tool):
                return False
    extra_plugins = os.path.join(BUILD_ROOT, "extra_plugins")
    if os.path.exists(extra_plugins):
        if not utils.doCopy(extra_plugins, plugin_tool):
            return False

    orig_dir = os.getcwd()
    os.chdir(BUILD_ROOT)
    pack_cmd = "cordova create %s org.xwalk.%s %s" % (
        app_name, app_name, app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    # Set activity name as app_name
    utils.replaceUserString(
        project_root,
        'config.xml',
        '<widget',
        '<widget android-activityName="%s"' %
        app_name)
    # Workaround for XWALK-3679
    utils.replaceUserString(
        project_root,
        'config.xml',
        '</widget>',
        '    <allow-navigation href="*" />\n</widget>')

    if not utils.doRemove([os.path.join(project_root, "www")]):
        return False
    if not utils.doCopy(app_src, os.path.join(project_root, "www")):
        os.chdir(orig_dir)
        return False

    os.chdir(project_root)
    pack_cmd = "cordova platform add android"
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    pkg_mode_tmp = "shared"
    if BUILD_PARAMETERS.pkgmode == "embedded":
        pkg_mode_tmp = "core"

    xwalk_version = "%s" % CROSSWALK_VERSION
    if CROSSWALK_BRANCH == "beta":
        xwalk_version = "org.xwalk:xwalk_%s_library_beta:%s" % (pkg_mode_tmp, CROSSWALK_VERSION)

    webview_plugin_name = "cordova-plugin-crosswalk-webview"
    plugin_dirs = os.listdir(plugin_tool)
    for i_dir in plugin_dirs:
        install_variable_cmd = ""
        i_plugin_dir = os.path.join(plugin_tool, i_dir)
        plugin_crosswalk_source = i_plugin_dir
        if i_dir == webview_plugin_name:
            if BUILD_PARAMETERS.packtype == "npm":
                plugin_crosswalk_source = webview_plugin_name
            install_variable_cmd = "--variable XWALK_MODE=\"%s\" --variable XWALK_VERSION=\"%s\"" \
                    % (BUILD_PARAMETERS.pkgmode, xwalk_version)

        plugin_install_cmd = "cordova plugin add %s %s" % (plugin_crosswalk_source, install_variable_cmd)
        if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False

    ANDROID_HOME = "echo $(dirname $(dirname $(which android)))"
    os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME)

    apk_name_arch = "armv7"
    pack_arch_tmp = "arm"
    if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch != "arm":
        apk_name_arch = BUILD_PARAMETERS.pkgarch
        if BUILD_PARAMETERS.pkgarch == "x86":
            pack_arch_tmp = "x86"
        elif BUILD_PARAMETERS.pkgarch == "x86_64":
            pack_arch_tmp = "x86 --xwalk64bit"
        elif BUILD_PARAMETERS.pkgarch == "arm64":
            pack_arch_tmp = "arm --xwalk64bit"

    pack_cmd = "cordova build android -- --gradleArg=-PcdvBuildArch=%s" % pack_arch_tmp

    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    outputs_dir = os.path.join(
        project_root,
        "platforms",
        "android",
        "build",
        "outputs",
        "apk")

    cordova_tmp_path = os.path.join(
        outputs_dir,
        "android-%s-debug.apk" %
            apk_name_arch)
    if not os.path.exists(cordova_tmp_path):
        cordova_tmp_path = os.path.join(
            outputs_dir,
            "%s-%s-debug.apk" %
            (app_name, apk_name_arch))
        if not os.path.exists(cordova_tmp_path):
            cordova_tmp_path = os.path.join(
                outputs_dir,
                "android-debug.apk")
            if not os.path.exists(cordova_tmp_path):
                cordova_tmp_path = os.path.join(
                    outputs_dir,
                    "%s-debug.apk" %
                    app_name)
    if not utils.doCopy(
            cordova_tmp_path, os.path.join(app_dest, "%s.apk" % app_name)):
        os.chdir(orig_dir)
        return False
    os.chdir(orig_dir)
    return True
def 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 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 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")
    DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT")
    pack_tool = os.path.join(BUILD_ROOT, "cordova")
    app_name = app_name.replace("-", "_")
    if not os.path.exists(pack_tool):
        if not utils.doCopy(
                os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova"),
                pack_tool):
            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(pack_tool)

    if BUILD_PARAMETERS.pkgmode == "shared":
        pack_cmd = "bin/create %s org.xwalk.%s %s --xwalk-shared-library" % (
            app_name, app_name, app_name)
    else:
        pack_cmd = "bin/create %s org.xwalk.%s %s --shared" % (
            app_name, app_name, app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    os.chdir(os.path.join(pack_tool, app_name))
    plugin_dirs = os.listdir(plugin_tool)
    for i_dir in plugin_dirs:
        i_plugin_dir = os.path.join(plugin_tool, i_dir)
        plugin_install_cmd = "plugman install --platform android --project " \
                             "./ --plugin %s" % i_plugin_dir
        if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False
    os.chdir(pack_tool)

    if not utils.doCopy(app_src, os.path.join(pack_tool, app_name, "assets", "www")):
        os.chdir(orig_dir)
        return False
    os.chdir(os.path.join(BUILD_ROOT, "cordova", app_name))
    ANDROID_HOME = "echo $(dirname $(dirname $(which android)))"
    os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME)
    pack_cmd = "./cordova/build"

    if BUILD_PARAMETERS.subversion == '4.x':
        if BUILD_PARAMETERS.pkgarch == "x86":
            cordova_tmp_path = os.path.join(
                BUILD_ROOT,
                "cordova",
                app_name,
                "build",
                "outputs",
                "apk",
                "%s-x86-debug.apk" %
                app_name)
        else:
            cordova_tmp_path = os.path.join(
                BUILD_ROOT,
                "cordova",
                app_name,
                "build",
                "outputs",
                "apk",
                "%s-armv7-debug.apk" %
                app_name)
    else:
        cordova_tmp_path = os.path.join(
            BUILD_ROOT,
            "cordova",
            app_name,
            "bin",
            "%s-debug.apk" %
            app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        pack_cmd = "ant debug"
        if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False

    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
Beispiel #17
0
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 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 copy_resource(pkgtype):
    try:
        json_file = os.path.join(ROOT_DIR, "suite.json")
        if not os.path.exists(json_file):
            print "%s does not exist" % json_file
            sys.exit(1)

        print ">>>> suite.json: %s" % json_file
        print ">>>>   pkg type: %s" % pkgtype

        suite_json = None
        pkg_json = None
        try:
            with open(json_file, "rt") as suite_json_file:
                suite_json_raw = suite_json_file.read()
                suite_json_file.close()
                suite_json = json.loads(suite_json_raw)
        except Exception as e:
            print "Fail to read json file: %s, exit ..." % json_file
            sys.exit(1)

        all_pkg_string = suite_json["pkg-list"].keys()
        for i_pkg in all_pkg_string:
            i_pkg_list = i_pkg.strip().split(",")
            if pkgtype in i_pkg_list:
                pkg_json = suite_json["pkg-list"][i_pkg]
        if pkg_json is None:
            print "No %s type config in %s" % (pkgtype, json_file)

        # package copylist
        if "copylist" in pkg_json:
            main_copylist = pkg_json["copylist"]
            for i_s_key in main_copylist.keys():
                src_path = os.path.join(ROOT_DIR, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
                dest_path = os.path.join(ROOT_DIR, main_copylist[i_s_key])
                utils.doCopy(src_path, dest_path)

        # pkg-app copylist
        if "pkg-app" in pkg_json:
            pkg_app_json = pkg_json["pkg-app"]
            if "copylist" in pkg_app_json:
                pkg_app_copylist = pkg_app_json["copylist"]
                for i_s_key in pkg_app_copylist.keys():
                    src_path = os.path.join(ROOT_DIR, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
                    dest_path = os.path.join(ROOT_DIR, pkg_app_copylist[i_s_key])
                    utils.doCopy(src_path, dest_path)

        # subapp-list copylist
        if "subapp-list" in pkg_json:
            subapp_list_json = pkg_json["subapp-list"]
            for subapp_str in subapp_list_json.keys():
                subapp_json = subapp_list_json[subapp_str]
                subapp_path = os.path.join(ROOT_DIR, subapp_str)
                if "copylist" in subapp_json and os.path.exists(subapp_path):
                    subapp_copylist = subapp_json["copylist"]
                    for i_s_key in subapp_copylist.keys():
                        src_path = os.path.join(subapp_path, i_s_key).replace("PACK-TOOL-ROOT", "../../tools")
                        dest_path = os.path.join(subapp_path, subapp_copylist[i_s_key])
                        utils.doCopy(src_path, dest_path)
    except Exception as e:
        print "Get Exception: %s, exit ..." % e
        sys.exit(1)
def packEmbeddingAPI_maven(
        build_json=None, app_src=None, app_dest=None, app_name=None, app_version=None):
    BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS")
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")
    CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION")
    DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT")
    app_name = app_name.replace("-", "_")
    orig_dir = os.getcwd()
    LOG.info("app_src: %s" % app_src)
    LOG.info("app_dest: %s" % app_dest)

    os.chdir(BUILD_ROOT)
    utils.replaceUserString(
        app_src,
        'pom.xml',
        '{crosswalk.version}',
        CROSSWALK_VERSION)

    version_parts = CROSSWALK_VERSION.split('.')
    if len(version_parts) < 4:
        LOG.error("The crosswalk version is not configured exactly!")
        return False
    versionType = version_parts[3]

    if versionType == '0':
        utils.replaceUserString(
            app_src,
            'pom.xml',
            'xwalk_core_library_beta',
            'xwalk_core_library')

        username = commands.getoutput("echo $USER")
        repository_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s" % \
            (username, CROSSWALK_VERSION)
        repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.aar" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)
        repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.pom" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)

        if not os.path.exists(repository_aar_path) or not os.path.exists(repository_pom_path):
            wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/android" \
                "/canary/%s/crosswalk-%s.aar" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3):
                os.chdir(orig_dir)
                return False
            install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \
                "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \
                "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT):
                os.chdir(orig_dir)
                return False

        if not utils.doCopy(
                repository_aar_path,
                os.path.join(repository_path, "xwalk_core_library-%s-x86.aar" % CROSSWALK_VERSION)):
            os.chdir(orig_dir)
            return False
        if not utils.doCopy(
                repository_aar_path,
                os.path.join(repository_path, "xwalk_core_library-%s-arm.aar" % CROSSWALK_VERSION)):
            os.chdir(orig_dir)
            return False

        utils.replaceUserString(
            app_src,
            'pom.xml',
            'https://download.01.org/crosswalk/releases/crosswalk/android/maven2',
            'file:///home/%s/.m2/repository' % username)

    os.chdir(app_src)
    utils.replaceUserString(
        app_src,
        'AndroidManifest.xml',
        'android:versionCode=\"1\"',
        'android:versionCode=\"${app.version.code}\"')
    utils.replaceUserString(
        app_src,
        'AndroidManifest.xml',
        'android:versionName=\"1.0\"',
        'android:versionName=\"${app.version.name}\"')
    manifest_path = os.path.join(app_src, "AndroidManifest.xml")
    if not utils.doCopy(
            manifest_path, os.path.join(app_src, "src", "main", "AndroidManifest.xml")):
        return False
    if not utils.doRemove([manifest_path]):
        return False

    res_path = os.path.join(app_src, "res")
    if os.path.exists(res_path):
        if not utils.doCopy(res_path, os.path.join(app_src, "src", "main", "res")):
            return False
        if not utils.doRemove([res_path]):
            return False

    assets_path = os.path.join(app_src, "assets")
    if os.path.exists(assets_path):
        if not utils.doCopy(
                assets_path, os.path.join(app_src, "src", "main", "assets")):
            return False
        if not utils.doRemove([assets_path]):
            return False

    src_org_path = os.path.join(app_src, "src", "org")
    if not utils.doCopy(
            src_org_path, os.path.join(app_src, "src", "main", "java", "org")):
        return False
    if not utils.doRemove([src_org_path]):
        return False

    libs_path = os.path.join(app_src, "libs")
    if os.path.exists(libs_path):
        if not utils.doCopy(
                libs_path, os.path.join(app_src, "../libs")):
            return False
        if not utils.doRemove([libs_path]):
            return False

    if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm":
        if not utils.doCMD("mvn clean install -Parm", DEFAULT_CMD_TIMEOUT):
            return False
        if not utils.doCopy(
                os.path.join(
                    app_src,
                    "target",
                    "embeddingapi-tests-arm.apk"),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    else:
        if not utils.doCMD("mvn clean install -Px86", DEFAULT_CMD_TIMEOUT):
            return False
        if not utils.doCopy(
                os.path.join(app_src, "target", "embeddingapi-tests-x86.apk"),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    os.chdir(orig_dir)
    return True
def 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 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
Beispiel #23
0
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")
    DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT")
    pack_tool = os.path.join(BUILD_ROOT, "cordova")
    app_name = app_name.replace("-", "_")
    if not os.path.exists(pack_tool):
        if not utils.doCopy(
                os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova"),
                pack_tool):
            return False

    plugin_tool = os.path.join(BUILD_ROOT, "cordova_plugins")
    if not os.path.exists(plugin_tool):
        if not utils.doCopy(
                os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins"),
                plugin_tool):
            return False
    extra_plugins = os.path.join(BUILD_ROOT, "extra_plugins")
    if os.path.exists(extra_plugins):
        if not utils.doCopy(extra_plugins, plugin_tool):
            return False

    orig_dir = os.getcwd()
    os.chdir(pack_tool)

    if BUILD_PARAMETERS.pkgmode == "shared":
        pack_cmd = "bin/create %s org.xwalk.%s %s --xwalk-shared-library" % (
            app_name, app_name, app_name)
    else:
        pack_cmd = "bin/create %s org.xwalk.%s %s --shared" % (
            app_name, app_name, app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    os.chdir(os.path.join(pack_tool, app_name))
    plugin_dirs = os.listdir(plugin_tool)
    for i_dir in plugin_dirs:
        i_plugin_dir = os.path.join(plugin_tool, i_dir)
        plugin_install_cmd = "plugman install --platform android --project " \
                             "./ --plugin %s" % i_plugin_dir
        if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False
    os.chdir(pack_tool)

    if not utils.doCopy(app_src, os.path.join(pack_tool, app_name, "assets", "www")):
        os.chdir(orig_dir)
        return False
    os.chdir(os.path.join(BUILD_ROOT, "cordova", app_name))
    ANDROID_HOME = "echo $(dirname $(dirname $(which android)))"
    os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME)
    pack_cmd = "./cordova/build"

    if BUILD_PARAMETERS.subversion == '4.x':
        if BUILD_PARAMETERS.pkgarch == "x86":
            cordova_tmp_path = os.path.join(
                BUILD_ROOT,
                "cordova",
                app_name,
                "build",
                "outputs",
                "apk",
                "%s-x86-debug.apk" %
                app_name)
        else:
            cordova_tmp_path = os.path.join(
                BUILD_ROOT,
                "cordova",
                app_name,
                "build",
                "outputs",
                "apk",
                "%s-armv7-debug.apk" %
                app_name)
    else:
        cordova_tmp_path = os.path.join(
            BUILD_ROOT,
            "cordova",
            app_name,
            "bin",
            "%s-debug.apk" %
            app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        pack_cmd = "ant debug"
        if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False

    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
Beispiel #24
0
def copy_resource(pkgtype):
    try:
        json_file = os.path.join(ROOT_DIR, "suite.json")
        if not os.path.exists(json_file):
            print "%s does not exist" % json_file
            sys.exit(1)

        print ">>>> suite.json: %s" % json_file
        print ">>>>   pkg type: %s" % pkgtype

        suite_json = None
        pkg_json = None
        try:
            with open(json_file, "rt") as suite_json_file:
                suite_json_raw = suite_json_file.read()
                suite_json_file.close()
                suite_json = json.loads(suite_json_raw)
        except Exception as e:
            print "Fail to read json file: %s, exit ..." % json_file
            sys.exit(1)

        all_pkg_string = suite_json["pkg-list"].keys()
        for i_pkg in all_pkg_string:
            i_pkg_list = i_pkg.strip().split(",")
            if pkgtype in i_pkg_list:
                pkg_json = suite_json["pkg-list"][i_pkg]
        if pkg_json is None:
            print "No %s type config in %s" % (pkgtype, json_file)

        # package copylist
        if "copylist" in pkg_json:
            main_copylist = pkg_json["copylist"]
            for i_s_key in main_copylist.keys():
                src_path = os.path.join(ROOT_DIR, i_s_key).replace(
                    "PACK-TOOL-ROOT", "../../tools")
                dest_path = os.path.join(ROOT_DIR, main_copylist[i_s_key])
                utils.doCopy(src_path, dest_path)

        # pkg-app copylist
        if "pkg-app" in pkg_json:
            pkg_app_json = pkg_json["pkg-app"]
            if "copylist" in pkg_app_json:
                pkg_app_copylist = pkg_app_json["copylist"]
                for i_s_key in pkg_app_copylist.keys():
                    src_path = os.path.join(ROOT_DIR, i_s_key).replace(
                        "PACK-TOOL-ROOT", "../../tools")
                    dest_path = os.path.join(ROOT_DIR,
                                             pkg_app_copylist[i_s_key])
                    utils.doCopy(src_path, dest_path)

        # subapp-list copylist
        if "subapp-list" in pkg_json:
            subapp_list_json = pkg_json["subapp-list"]
            for subapp_str in subapp_list_json.keys():
                subapp_json = subapp_list_json[subapp_str]
                subapp_path = os.path.join(ROOT_DIR, subapp_str)
                if "copylist" in subapp_json and os.path.exists(subapp_path):
                    subapp_copylist = subapp_json["copylist"]
                    for i_s_key in subapp_copylist.keys():
                        src_path = os.path.join(subapp_path, i_s_key).replace(
                            "PACK-TOOL-ROOT", "../../tools")
                        dest_path = os.path.join(subapp_path,
                                                 subapp_copylist[i_s_key])
                        utils.doCopy(src_path, dest_path)
    except Exception as e:
        print "Get Exception: %s, exit ..." % e
        sys.exit(1)
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
Beispiel #26
0
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)
Beispiel #27
0
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
Beispiel #28
0
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_gradle(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_origin = app_name
    app_name = app_name.replace("-", "_")
    orig_dir = os.getcwd()
    LOG.info("app_src: %s" % app_src)
    LOG.info("app_dest: %s" % app_dest)

    os.chdir(BUILD_ROOT)
    utils.replaceUserString(app_src, 'build.gradle', '{crosswalk.version}',
                            CROSSWALK_VERSION)

    version_parts = CROSSWALK_VERSION.split('.')
    if len(version_parts) < 4:
        LOG.error("The crosswalk version is not configured exactly!")
        return False
    versionType = version_parts[3]
    if versionType == '0':
        utils.replaceUserString(app_src, 'build.gradle',
                                'xwalk_core_library_beta',
                                'xwalk_core_library')
        utils.replaceUserString(
            app_src, 'build.gradle',
            'maven {\n        url \'https://download.01.org/crosswalk/releases/crosswalk/android/maven2\'\n    }',
            '    mavenLocal()')

        username = commands.getoutput("echo $USER")
        repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.aar" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)
        repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.pom" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)

        if not os.path.exists(repository_aar_path) or not os.path.exists(
                repository_pom_path):
            wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/" \
                "android/canary/%s/crosswalk-%s.aar" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3):
                os.chdir(orig_dir)
                return False
            install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \
                "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \
                "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT):
                os.chdir(orig_dir)
                return False

    os.chdir(app_src)
    if not utils.doCMD("gradle build", DEFAULT_CMD_TIMEOUT):
        os.chdir("..")
        return False
    if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm":
        if not utils.doCopy(
                os.path.join(app_src, "build", "outputs", "apk",
                             "%s-armv7-debug.apk" % app_name_origin),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    else:
        if not utils.doCopy(
                os.path.join(app_src, "build", "outputs", "apk",
                             "%s-x86-debug.apk" % app_name_origin),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    os.chdir(orig_dir)
    return True
def packEmbeddingAPI_gradle(
        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_origin = app_name
    app_name = app_name.replace("-", "_")
    orig_dir = os.getcwd()
    LOG.info("app_src: %s" % app_src)
    LOG.info("app_dest: %s" % app_dest)

    os.chdir(BUILD_ROOT)
    utils.replaceUserString(
        app_src,
        'build.gradle',
        '{crosswalk.version}',
        CROSSWALK_VERSION)

    version_parts = CROSSWALK_VERSION.split('.')
    if len(version_parts) < 4:
        LOG.error("The crosswalk version is not configured exactly!")
        return False
    versionType = version_parts[3]
    if versionType == '0':
        utils.replaceUserString(
            app_src,
            'build.gradle',
            'xwalk_core_library_beta',
            'xwalk_core_library')
        utils.replaceUserString(
            app_src,
            'build.gradle',
            'maven {\n        url \'https://download.01.org/crosswalk/releases/crosswalk/android/maven2\'\n    }',
            '    mavenLocal()')

        username = commands.getoutput("echo $USER")
        repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.aar" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)
        repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.pom" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)

        if not os.path.exists(repository_aar_path) or not os.path.exists(repository_pom_path):
            wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/" \
                "android/canary/%s/crosswalk-%s.aar" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3):
                os.chdir(orig_dir)
                return False
            install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \
                "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \
                "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT):
                os.chdir(orig_dir)
                return False

    os.chdir(app_src)
    if not utils.doCMD("gradle build", DEFAULT_CMD_TIMEOUT):
        os.chdir("..")
        return False
    if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm":
        if not utils.doCopy(
                os.path.join(
                    app_src,
                    "build",
                    "outputs",
                    "apk",
                    "%s-armv7-debug.apk" %
                    app_name_origin),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    else:
        if not utils.doCopy(
                os.path.join(
                    app_src,
                    "build",
                    "outputs",
                    "apk",
                    "%s-x86-debug.apk" %
                    app_name_origin),
                os.path.join(app_dest, "%s.apk" % app_name)):
            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 packEmbeddingAPI_ant(build_json=None,
                         app_src=None,
                         app_dest=None,
                         app_name=None,
                         app_version=None):
    BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS")
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")
    CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION")
    DEFAULT_CMD_TIMEOUT = varshop.getValue("DEFAULT_CMD_TIMEOUT")
    app_name = app_name.replace("-", "_")

    library_dir_name = utils.safelyGetValue(build_json,
                                            "embeddingapi-library-name")
    if not library_dir_name:
        LOG.error("Fail to get embeddingapi-library-name ...")
        return False

    new_library_dir_name = "core_library"
    pack_tool = os.path.join(app_src, "..", new_library_dir_name)

    if os.path.exists(pack_tool):
        if not utils.doRemove([pack_tool]):
            return False

    if not utils.doCopy(
            os.path.join(BUILD_PARAMETERS.pkgpacktools, library_dir_name),
            pack_tool):
        return False

    if os.path.exists(os.path.join(pack_tool, "bin", "res", "crunch")):
        if not utils.doRemove(
            [os.path.join(pack_tool, "bin", "res", "crunch")]):
            return False

    orig_dir = os.getcwd()
    android_project_path = os.path.join(app_src, "android-project")
    try:
        os.makedirs(android_project_path)
    except Exception as e:
        LOG.error("Fail to create tmp project dir: %s" % e)
        return False

    (return_code, output) = utils.doCMDWithOutput("android list target",
                                                  DEFAULT_CMD_TIMEOUT)
    api_level = ""
    for line in output:
        if "API level:" in line:
            api_level = line.split(":")[1].strip()
    if not api_level:
        LOG.error("Fail to get Android API Level")
        os.chdir(orig_dir)
        return False

    android_project_cmd = "android create project --name %s --target " \
                          "android-%s --path %s --package com.%s " \
                          "--activity MainActivity" % (
                              app_name, api_level, android_project_path, app_name)
    if not utils.doCMD(android_project_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    try:
        update_file = open(
            os.path.join(android_project_path, "project.properties"), "a+")
        update_file.writelines("{0}\n".format(
            "android.library.reference.1=../%s" % new_library_dir_name))
        update_file.close()
    except Exception as e:
        LOG.error(
            "Fail to update %s: %s" %
            (os.path.join(android_project_path, "project.properties"), e))
        os.chdir(orig_dir)
        return False

    if not utils.doCopy(os.path.join(android_project_path, "build.xml"),
                        os.path.join(app_src, "build.xml")):
        os.chdir(orig_dir)
        return False

    if not utils.doCopy(
            os.path.join(android_project_path, "project.properties"),
            os.path.join(app_src, "project.properties")):
        os.chdir(orig_dir)
        return False

    if not utils.doCopy(os.path.join(android_project_path, "local.properties"),
                        os.path.join(app_src, "local.properties")):
        os.chdir(orig_dir)
        return False

    if not utils.doCopy(os.path.join(android_project_path, "local.properties"),
                        os.path.join(pack_tool, "local.properties")):
        os.chdir(orig_dir)
        return False

    release_mode_tmp = "release"
    if BUILD_PARAMETERS.bnotdebug:
        LOG.info("Package release mode pkg start ...")
        ant_cmd = ["ant", "release", '-f', os.path.join(app_src, 'build.xml')]
        key_store = os.path.join(BUILD_PARAMETERS.pkgpacktools, 'crosswalk',
                                 'xwalk-debug.keystore')
        if not os.path.exists(key_store):
            LOG.error(
                "Need to copy xwalk-debug.keystore file from Crosswalk-<version> to crosswalk-test-suite/tools/crosswalk"
            )
            return False
        ant_cmd.extend(['-Dkey.store=%s' % os.path.abspath(key_store)])
        ant_cmd.extend(['-Dkey.alias=xwalkdebugkey'])
        ant_cmd.extend(['-Dkey.store.password=xwalkdebug'])
        ant_cmd.extend(['-Dkey.alias.password=xwalkdebug'])
        ant_result = subprocess.call(ant_cmd)
        if ant_result != 0:
            os.chdir(orig_dir)
            return False
    else:
        LOG.info("Package debug mode pkg start ...")
        os.chdir(app_src)
        if not utils.doCMD("ant debug", DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False
        release_mode_tmp = "debug"

    if not utils.doCopy(
            os.path.join(app_src, "bin", "%s-%s.apk" %
                         (app_name, release_mode_tmp)),
            os.path.join(app_dest, "%s.apk" % app_name)):
        os.chdir(orig_dir)
        return False
    os.chdir(orig_dir)
    return True
def packEmbeddingAPI_maven(build_json=None,
                           app_src=None,
                           app_dest=None,
                           app_name=None,
                           app_version=None):
    BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS")
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")
    CROSSWALK_VERSION = varshop.getValue("CROSSWALK_VERSION")
    DEFAULT_CMD_TIMEOUT = varshop.getValue("DEFAULT_CMD_TIMEOUT")
    app_name = app_name.replace("-", "_")
    orig_dir = os.getcwd()
    LOG.info("app_src: %s" % app_src)
    LOG.info("app_dest: %s" % app_dest)

    os.chdir(BUILD_ROOT)
    utils.replaceUserString(app_src, 'pom.xml', '{crosswalk.version}',
                            CROSSWALK_VERSION)

    version_parts = CROSSWALK_VERSION.split('.')
    if len(version_parts) < 4:
        LOG.error("The crosswalk version is not configured exactly!")
        return False
    versionType = version_parts[3]

    if versionType == '0':
        utils.replaceUserString(app_src, 'pom.xml', 'xwalk_core_library_beta',
                                'xwalk_core_library')

        username = commands.getoutput("echo $USER")
        repository_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s" % \
            (username, CROSSWALK_VERSION)
        repository_aar_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.aar" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)
        repository_pom_path = "/home/%s/.m2/repository/org/xwalk/xwalk_core_library/%s/" \
            "xwalk_core_library-%s.pom" % \
            (username, CROSSWALK_VERSION, CROSSWALK_VERSION)

        if not os.path.exists(repository_aar_path) or not os.path.exists(
                repository_pom_path):
            wget_cmd = "wget https://download.01.org/crosswalk/releases/crosswalk/android" \
                "/canary/%s/crosswalk-%s.aar" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(wget_cmd, DEFAULT_CMD_TIMEOUT * 3):
                os.chdir(orig_dir)
                return False
            install_cmd = "mvn install:install-file -DgroupId=org.xwalk " \
                "-DartifactId=xwalk_core_library -Dversion=%s -Dpackaging=aar " \
                "-Dfile=crosswalk-%s.aar -DgeneratePom=true" % \
                (CROSSWALK_VERSION, CROSSWALK_VERSION)
            if not utils.doCMD(install_cmd, DEFAULT_CMD_TIMEOUT):
                os.chdir(orig_dir)
                return False

        if not utils.doCopy(
                repository_aar_path,
                os.path.join(
                    repository_path,
                    "xwalk_core_library-%s-x86.aar" % CROSSWALK_VERSION)):
            os.chdir(orig_dir)
            return False
        if not utils.doCopy(
                repository_aar_path,
                os.path.join(
                    repository_path,
                    "xwalk_core_library-%s-arm.aar" % CROSSWALK_VERSION)):
            os.chdir(orig_dir)
            return False

        utils.replaceUserString(
            app_src, 'pom.xml',
            'https://download.01.org/crosswalk/releases/crosswalk/android/maven2',
            'file:///home/%s/.m2/repository' % username)

    os.chdir(app_src)
    utils.replaceUserString(app_src, 'AndroidManifest.xml',
                            'android:versionCode=\"1\"',
                            'android:versionCode=\"${app.version.code}\"')
    utils.replaceUserString(app_src, 'AndroidManifest.xml',
                            'android:versionName=\"1.0\"',
                            'android:versionName=\"${app.version.name}\"')
    manifest_path = os.path.join(app_src, "AndroidManifest.xml")
    if not utils.doCopy(
            manifest_path,
            os.path.join(app_src, "src", "main", "AndroidManifest.xml")):
        return False
    if not utils.doRemove([manifest_path]):
        return False

    res_path = os.path.join(app_src, "res")
    if os.path.exists(res_path):
        if not utils.doCopy(res_path,
                            os.path.join(app_src, "src", "main", "res")):
            return False
        if not utils.doRemove([res_path]):
            return False

    assets_path = os.path.join(app_src, "assets")
    if os.path.exists(assets_path):
        if not utils.doCopy(assets_path,
                            os.path.join(app_src, "src", "main", "assets")):
            return False
        if not utils.doRemove([assets_path]):
            return False

    src_org_path = os.path.join(app_src, "src", "org")
    if not utils.doCopy(src_org_path,
                        os.path.join(app_src, "src", "main", "java", "org")):
        return False
    if not utils.doRemove([src_org_path]):
        return False

    libs_path = os.path.join(app_src, "libs")
    if os.path.exists(libs_path):
        if not utils.doCopy(libs_path, os.path.join(app_src, "../libs")):
            return False
        if not utils.doRemove([libs_path]):
            return False

    if BUILD_PARAMETERS.pkgarch and BUILD_PARAMETERS.pkgarch == "arm":
        if not utils.doCMD("mvn clean install -Parm", DEFAULT_CMD_TIMEOUT):
            return False
        if not utils.doCopy(
                os.path.join(app_src, "target", "embeddingapi-tests-arm.apk"),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    else:
        if not utils.doCMD("mvn clean install -Px86", DEFAULT_CMD_TIMEOUT):
            return False
        if not utils.doCopy(
                os.path.join(app_src, "target", "embeddingapi-tests-x86.apk"),
                os.path.join(app_dest, "%s.apk" % app_name)):
            return False
    os.chdir(orig_dir)
    return True
Beispiel #34
0
def packCordova_cli(
        build_json=None, app_src=None, app_dest=None, app_name=None):
    BUILD_PARAMETERS = varshop.getValue("BUILD_PARAMETERS")
    BUILD_ROOT = varshop.getValue("BUILD_ROOT")
    CROSSWALK_BRANCH= varshop.getValue("CROSSWALK_BRANCH")
    CROSSWALK_VERSION= varshop.getValue("CROSSWALK_VERSION")
    DEFAULT_CMD_TIMEOUT= varshop.getValue("DEFAULT_CMD_TIMEOUT")
    app_name = app_name.replace("-", "_")
    project_root = os.path.join(BUILD_ROOT, app_name)

    output = commands.getoutput("cordova -v")
    output_version = int(output[0])
    if output_version < 5:
        LOG.error(
            "Cordova 4.x build requires the latest Cordova CLI, and must >= 5.0.0, install with command: '$ sudo npm install cordova -g'")
        return False

    plugin_tool = os.path.join(BUILD_ROOT, "cordova_plugins")
    if not os.path.exists(plugin_tool):
        if not utils.doCopy(
                os.path.join(BUILD_PARAMETERS.pkgpacktools, "cordova_plugins"),
                plugin_tool):
            return False
    extra_plugins = os.path.join(BUILD_ROOT, "extra_plugins")
    if os.path.exists(extra_plugins):
        if not utils.doCopy(extra_plugins, plugin_tool):
            return False

    orig_dir = os.getcwd()
    os.chdir(BUILD_ROOT)
    pack_cmd = "cordova create %s org.xwalk.%s %s" % (
        app_name, app_name, app_name)
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    # Set activity name as app_name
    utils.replaceUserString(
        project_root,
        'config.xml',
        '<widget',
        '<widget android-activityName="%s"' %
        app_name)
    # Workaround for XWALK-3679
    utils.replaceUserString(
        project_root,
        'config.xml',
        '</widget>',
        '    <allow-navigation href="*" />\n</widget>')

    if not utils.doRemove([os.path.join(project_root, "www")]):
        return False
    if not utils.doCopy(app_src, os.path.join(project_root, "www")):
        os.chdir(orig_dir)
        return False

    os.chdir(project_root)
    pack_cmd = "cordova platform add android"
    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    pkg_mode_tmp = "shared"
    if BUILD_PARAMETERS.pkgmode == "embedded":
        pkg_mode_tmp = "core"

    xwalk_version = "%s" % CROSSWALK_VERSION
    if CROSSWALK_BRANCH == "beta":
        xwalk_version = "org.xwalk:xwalk_%s_library_beta:%s" % (pkg_mode_tmp, CROSSWALK_VERSION)

    webview_plugin_name = "cordova-plugin-crosswalk-webview"
    install_variable_cmd = ""
    plugin_dirs = os.listdir(plugin_tool)
    for i_dir in plugin_dirs:
        i_plugin_dir = os.path.join(plugin_tool, i_dir)
        plugin_crosswalk_source = i_plugin_dir
        if i_dir == webview_plugin_name:
            if BUILD_PARAMETERS.packtype == "npm":
                plugin_crosswalk_source = webview_plugin_name
            install_variable_cmd = "--variable XWALK_MODE=\"%s\" --variable XWALK_VERSION=\"%s\"" \
                    % (BUILD_PARAMETERS.pkgmode, xwalk_version)

        plugin_install_cmd = "cordova plugin add %s %s" % (plugin_crosswalk_source, install_variable_cmd)
        if not utils.doCMD(plugin_install_cmd, DEFAULT_CMD_TIMEOUT):
            os.chdir(orig_dir)
            return False

    ANDROID_HOME = "echo $(dirname $(dirname $(which android)))"
    os.environ['ANDROID_HOME'] = commands.getoutput(ANDROID_HOME)
    pack_cmd = "cordova build android"

    if not utils.doCMD(pack_cmd, DEFAULT_CMD_TIMEOUT):
        os.chdir(orig_dir)
        return False

    outputs_dir = os.path.join(
        project_root,
        "platforms",
        "android",
        "build",
        "outputs",
        "apk")

    if BUILD_PARAMETERS.pkgarch == "x86":
        cordova_tmp_path = os.path.join(
            outputs_dir,
            "%s-x86-debug.apk" %
            app_name)
        cordova_tmp_path_spare = os.path.join(
            outputs_dir,
            "android-x86-debug.apk")
    else:
        cordova_tmp_path = os.path.join(
            outputs_dir,
            "%s-armv7-debug.apk" %
            app_name)
        cordova_tmp_path_spare = os.path.join(
            outputs_dir,
            "android-armv7-debug.apk")

    if not os.path.exists(cordova_tmp_path):
        if not utils.doCopy(
                cordova_tmp_path_spare, os.path.join(app_dest, "%s.apk" % app_name)):
            os.chdir(orig_dir)
            return False
    else:
        if not utils.doCopy(
                cordova_tmp_path, os.path.join(app_dest, "%s.apk" % app_name)):
            os.chdir(orig_dir)
            return False
    os.chdir(orig_dir)
    return True
Beispiel #35
0
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