Beispiel #1
0
def parse_args(argv):
    argv = list(sys.argv[1:])
    argv = build_utils.expand_file_args(argv)
    parser = create_parser()
    args = parser.parse_args(argv)

    requires_options = [
        "android_sdk_jar", "aapt_path", "android_manifest",
        "dependency_res_zips", "resource_dirs", "resource_zip_out"
    ]
    build_utils.check_options(args, parser, required=requires_options)

    args.resource_dirs = build_utils.parse_gyp_list(args.resource_dirs)
    args.dependency_res_zips = build_utils.parse_gyp_list(
        args.dependency_res_zips)
    if args.extra_r_text_files:
        args.extra_r_text_files = build_utils.parse_gyp_list(
            args.extra_r_text_files)
    else:
        args.extra_r_text_files = []
    if args.extra_res_packages:
        args.extra_res_packages = build_utils.parse_gyp_list(
            args.extra_res_packages)
    else:
        args.extra_res_packages = []
    return args
Beispiel #2
0
def parse_options(argv):
    parser = create_parser()
    args = parser.parse_args(argv)
    build_utils.check_options(args, parser, required=("jar_path", "base_dir"))

    bootclasspath = []
    for arg in args.bootclasspath:
        bootclasspath += build_utils.parse_gyp_list(arg)
    args.bootclasspath = bootclasspath

    classpath = []
    for arg in args.classpath:
        classpath += build_utils.parse_gyp_list(arg)
    args.classpath = classpath

    java_srcjars = []
    for arg in args.java_srcjars:
        java_srcjars += build_utils.parse_gyp_list(arg)
    args.java_srcjars = java_srcjars

    if args.src_gendirs:
        args.src_gendirs = build_utils.parse_gyp_list(args.src_gendirs)

    args.javac_includes = build_utils.parse_gyp_list(args.javac_includes)
    args.jar_excluded_classes = build_utils.parse_gyp_list(
        args.jar_excluded_classes)
    return args
Beispiel #3
0
def parse_args(argv):
    parser = create_parser()
    args = parser.parse_args(argv)
    build_utils.check_options(args, parser,
                              required=("protoc", "proto_path"))
    if not args.java_out_dir and not args.srcjar:
        raise Exception("One of --java-out-dir or --srcjar must be specified.")

    return args
def parse_args():
    parser = create_parser()
    args = parser.parse_args()
    required_options = ("android_sdk_jar", "aapt_path", "configuration_name",
                        "android_manifest", "version_code", "version_name",
                        "apk_path")
    build_utils.check_options(args, parser, required=required_options)

    args.resource_zips = build_utils.parse_gyp_list(args.resource_zips)
    args.language_splits = build_utils.parse_gyp_list(args.language_splits)
    return args
def parse_args(args):
    parser = create_parser()
    args = parser.parse_args(args)

    required_options = [
        "name",
        "maven_depname",
        "root_dir",
        "m2_home",
        "aar_path",
        "json_path",
    ]
    build_utils.check_options(args, parser, required=required_options)
    return args
def main():
    parser = create_parser()
    args = parser.parse_args()

    build_utils.check_options(args, parser, required=['inputs'])
    inputs = build_utils.parse_gyp_list(args.inputs)

    if (args.output is None) == (args.outputs_zip is None):
        args.error('Exactly one of --output and --output-zip must be given')
    if args.output and len(inputs) != 1:
        args.error('--output cannot be used with multiple inputs')
    if args.outputs_zip and not args.inputs_base_dir:
        args.error('--inputs-base-dir must be given when --output-zip is used')

    variables = {}
    for v in build_utils.parse_gyp_list(args.variables):
        if '=' not in v:
            args.error('--variables argument must contain "=": ' + v)
        name, _, value = v.partition('=')
        variables[name] = value

    loader = RecordingFileSystemLoader(args.loader_base_dir)
    env = jinja2.Environment(loader=loader,
                             undefined=jinja2.StrictUndefined,
                             line_comment_prefix='##')
    if args.output:
        # 只处理单个文件
        process_file(env, inputs[0], args.loader_base_dir, args.output,
                     variables)
    else:
        # 处理多个文件
        process_files(env, inputs, args.loader_base_dir, args.inputs_base_dir,
                      args.outputs_zip, variables)

    if args.depfile:
        deps = loader.get_loaded_templates(
        ) + build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, deps)
    pass
Beispiel #7
0
def parse_args(parser, argv):
    argv = build_utils.expand_file_args(argv)
    args = parser.parse_args(argv)

    required_options = ("android_sdk_tools", )
    build_utils.check_options(args, parser, required=required_options)

    if args.multidex_configuration_path:
        with open(args.multidex_configuration_path) as multidex_config_file:
            multidex_config = json.load(multidex_config_file)
            args.multi_dex = multidex_config.get("enabled", False)
            pass

    # if args.multi_dex and not args.main_dex_list_path:
    #     print("multidex cannot be enabled without --main-dex-list-path")
    #     args.multi_dex = False
    elif args.main_dex_list_path and not args.multi_dex:
        print("--main-dex-list-path is unused if --multi-dex is not enabled")

    if args.inputs:
        args.inputs = build_utils.parse_gyp_list(args.inputs)
    if args.excluded_paths:
        args.excluded_paths = build_utils.parse_gyp_list(args.excluded_paths)
    return args
Beispiel #8
0
def main():
    parser = create_parser()
    args = parser.parse_args()

    requires_options_map = {
        "java_library": ["build_config", "jar_path", "srczip_path"],
        "java_binary": ["build_config", "jar_path"],
        "android_resources": ["build_config", "resources_zip"],
        "android_assets": ["build_config"],
        "android_native_libraries": ["build_config", "native_libs"],
        "android_apk": ["build_config", "apk_path", "dex_path"],
        "deps_dex": ["build_config", "dex_path"],
        "group": ["build_config"]
    }

    # 检查必须的选项
    requires_options = requires_options_map.get(args.type)
    if requires_options is None:
        raise Exception("Unknown type: %s" % args.type)

    build_utils.check_options(args, parser, required=requires_options)

    if type == "java_library":
        if args.supports_android and not args.dex_path:
            raise Exception(
                "--dex-path must be set if --supports-android is enabled")
        if args.requires_android and not args.supports_android:
            raise Exception(
                "--supports-android must be set is --requires-android is enabled")
        pass

    if args.possible_deps_configs is None:
        args.possible_deps_configs = []

    possible_deps_config_paths = args.possible_deps_configs

    allow_unknown_deps = (args.type in (
        "android_apk", "android_resources", "android_assets", "android_native_libraries"))
    unknown_deps = [
        c for c in possible_deps_config_paths if not os.path.exists(c)]
    if not allow_unknown_deps and unknown_deps:
        raise Exception("Unknown deps: %s" % str(unknown_deps))

    # 直接依赖
    direct_deps_config_paths = [c for c in possible_deps_config_paths
                                if c not in unknown_deps]
    direct_deps_config_paths = _filter_unwanted_deps_configs(args.type,
                                                             direct_deps_config_paths)
    deps = Deps(direct_deps_config_paths)
    all_inputs = deps.all_config_paths() + build_utils.get_python_dependencies()

    if args.has_alternative_locale_resource:
        # 移除其他的资源
        alternative = [c["path"] for c in deps.direct("android_resources")
                       if c["is_locale_resource"]]
        if len(alternative) != 1:
            raise Exception()
        unwanted = [c["path"] for c in deps.all("android_resources")
                    if c["is_locale_resource"]]
        for path in unwanted:
            if path != alternative[0]:
                deps.remove_non_direct_dep(unwanted)
        pass

    config = {
        "deps_info": {
            "name": os.path.basename(args.build_config),
            "path": args.build_config,
            "type": args.type,
            "deps_configs": direct_deps_config_paths
        }
    }
    deps_info = config["deps_info"]

    direct_library_deps = deps.direct("java_library")
    all_library_deps = deps.all("java_library")
    direct_resources_deps = deps.direct("android_resources")
    all_resources_deps = deps.all("android_resources")
    all_resources_deps.reverse()
    all_native_libraries_deps = deps.all("android_native_libraries")

    if args.type == "android_apk" and args.tested_apk_config:
        tested_apk_deps = Deps([args.tested_apk_config])
        tested_apk_resource_deps = tested_apk_deps.all("android_resources")
        direct_resources_deps = [d for d in direct_resources_deps
                                 if d not in tested_apk_resource_deps]
        all_resources_deps = [d for d in all_resources_deps
                              if d not in tested_apk_resource_deps]
        pass

    if args.type in ("java_library", "java_binary") and not args.bypass_platform_checks:
        deps_info["requires_android"] = args.requires_android
        deps_info["supports_android"] = args.supports_android

        deps_requires_android = [d["name"] for d in all_library_deps
                                 if d["requires_android"]]
        deps_not_supports_android = [d["name"] for d in all_library_deps
                                     if not d["supports_android"]]
        if not args.requires_android and deps_requires_android:
            raise Exception("Some deps requires building for the android platform: %s"
                            % " ".join(deps_requires_android))
        if args.supports_android and deps_not_supports_android:
            raise Exception("Some deps not supports running on the android platform: %s"
                            % " ".join(deps_not_supports_android))
        pass

    if args.type in ("java_library", "java_binary", "android_apk"):
        javac_classpath = [c["jar_path"] for c in direct_library_deps]
        java_full_classpath = [c["jar_path"] for c in all_library_deps]
        config["resources_deps"] = [c["path"] for c in all_resources_deps]
        deps_info["jar_path"] = args.jar_path
        deps_info["srczip_path"] = args.srczip_path
        if args.type == "android_apk" or args.supports_android:
            deps_info["dex_path"] = args.dex_path
        if args.type == "android_apk":
            deps_info["apk_path"] = args.apk_path
            deps_info["incremental_apk_path"] = args.incremental_apk_path
            deps_info["incremental_install_script_path"] = args.incremental_install_script_path

        config["javac"] = {}
        pass

    if args.type in ("java_binary", "java_library"):
        config["javac"]["srcjars"] = [c["srcjar"]
                                      for c in direct_resources_deps]
    if args.type == "android_apk":
        config["javac"]["srcjars"] = []

    if args.type == "android_assets":
        all_assets_sources = []
        if args.asset_renaming_sources:
            all_assets_sources.extend(args.asset_renaming_sources)
        if args.asset_sources:
            all_assets_sources.extend(args.asset_sources)
        deps_info["assets"] = {
            "sources": all_assets_sources,
        }

        all_assets_outputs = []
        if args.asset_renaming_destinations:
            all_assets_outputs.extend(args.asset_renaming_destinations)
        deps_info["assets"]["outputs"] = all_assets_outputs
        deps_info["assets"]["disable_compression"] = args.disable_asset_compression
        pass

    if args.type == "android_resources":
        deps_info["resources_zip"] = args.resources_zip
        deps_info["r_text"] = args.r_text
        deps_info["is_locale_resource"] = args.is_locale_resource
        if args.srcjar:
            deps_info["srcjar"] = args.srcjar
        if args.android_manifest:
            manifest = AndroidManifest(args.android_manifest)
            deps_info["package_name"] = manifest.get_package_name()
        if args.package_name:
            deps_info["package_name"] = args.package_name
        pass

    if args.type == "android_native_libraries":
        deps_info["native_libs"] = build_utils.parse_gyp_list(args.native_libs)
        pass

    if args.type in ("android_resources", "android_apk", "resources_rewriter"):
        config["resources"] = {}
        config["resources"]["dependency_zips"] = [d["resources_zip"]
                                                  for d in all_resources_deps]
        config["resources"]["extra_package_names"] = []
        config["resources"]["extra_r_text_files"] = []
        pass

    if args.type in ("android_apk", "android_resources", "resources_rewriter"):
        config["resources"]["extra_package_names"] = [c["package_name"] for c in all_resources_deps
                                                      if "package_name" in c]
        config["resources"]["extra_r_text_files"] = [c["r_text"] for c in all_resources_deps
                                                     if "r_text" in c]

    if args.type in ("android_apk", "deps_dex"):
        deps_dex_paths = [c["dex_path"] for c in all_library_deps]

    proguard_enabled = args.proguard_enabled
    if args.type == "android_apk":
        deps_info["proguard_enabled"] = proguard_enabled

    if proguard_enabled:
        deps_info["proguard_info"] = args.proguard_info
        config["proguard"] = {}
        proguard_config = config["proguard"]
        proguard_config["input_paths"] = [args.jar_path] + java_full_classpath

    if args.type in ("android_apk", "deps_dex"):
        config["final_dex"] = {}
        dex_config = config["final_dex"]
        dex_config["dependency_dex_files"] = deps_dex_paths
        pass

    if args.type in ("android_apk", "java_library", "java_binary"):
        config["javac"]["classpath"] = javac_classpath
        config["javac"]["interface_classpath"] = [as_interface_jar(path)
                                                  for path in javac_classpath]
        config["java"] = {
            "full_classpath": java_full_classpath
        }

    if args.type == "android_apk":
        dependency_jars = [c["jar_path"] for c in all_library_deps]
        all_interface_jars = [as_interface_jar(p)
                              for p in dependency_jars + [args.jar_path]]
        all_srczips = [c["srczip_path"] for c in all_library_deps]
        all_srczips.append(args.srczip_path)
        config["dist_jar"] = {
            "dependency_jars": dependency_jars,
            "all_interface_jars": all_interface_jars,
            "all_srczips": all_srczips,
        }

        manifest = AndroidManifest(args.android_manifest)
        deps_info["package_name"] = manifest.get_package_name()

        if not args.tested_apk_config and manifest.get_instrumentation():
            manifest.check_instrumentation(manifest.get_package_name())

        library_paths = []
        java_libraries_list_holder = [None]
        libraries = build_utils.parse_gyp_list(args.native_libs or '[]')
        for d in all_native_libraries_deps:
            libraries.extend(d["native_libs"])

        if libraries:
            all_deps = [path for path in libraries]
            library_paths = [path for path in all_deps]
            java_libraries_list_holder[0] = ("{%s}" % ",".join(
                ['"%s"' % s[3:-3] for s in library_paths]))
            pass

        all_inputs.extend(library_paths)
        config["native"] = {
            "libraries": library_paths,
            "java_libraries_list": java_libraries_list_holder[0]
        }

        config["assets"], config["uncompressed_assets"] = _merge_assets(
            deps.all("android_assets"))
        pass

    build_utils.write_json(config, args.build_config)
    if args.depfile:
        build_utils.write_dep_file(args.depfile, all_inputs)
    pass