예제 #1
0
def main(argv):
    args = parse_args(argv)

    base_dir = args.base_dir
    build_utils.delete_directory(base_dir)
    build_utils.make_directory(base_dir)

    # generator_args = [
    #     "optional_field_style=reftypes",
    #     "store_unknown_fields=true"
    # ]
    out_arg = "--java_out=" + base_dir
    cmds = [
        args.protoc,
        "--proto_path", args.proto_path,
        out_arg
    ] + args.paths
    build_utils.check_output(cmds)

    if args.java_out_dir:
        build_utils.delete_directory(args.java_out_dir)
        shutil.copytree(base_dir, args.java_out_dir)
    else:
        build_utils.zip_dir(args.srcjar, base_dir)

    if args.depfile:
        all_dep_paths = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
예제 #2
0
def _on_stale_md5(args, proguard_cmd, main_dex_list_cmd, paths,
                  main_dex_list_path):
    base_dir = args.base_dir
    if os.path.exists(base_dir):
        shutil.rmtree(base_dir)
        pass

    build_utils.make_directory(base_dir)
    paths_arg = build_utils.CLASSPATH_SEP.join(paths)
    main_dex_list = ''
    try:
        temp_jar_path = os.path.join(base_dir, "proguard.jar")
        proguard_cmd += ['-injars', paths_arg, '-outjars', temp_jar_path]
        build_utils.check_output(proguard_cmd, print_stderr=False)

        main_dex_list_cmd += [temp_jar_path, paths_arg]
        main_dex_list = build_utils.check_output(main_dex_list_cmd)
    except build_utils.CalledProcessError as e:
        if 'output jar is empty' in e.output:
            pass
        elif "input doesn't contain any classes" in e.output:
            pass
        else:
            raise

    with open(main_dex_list_path, 'w') as main_dex_list_file:
        main_dex_list_file.write(main_dex_list)
    pass
예제 #3
0
def crunch_directory(aapt, input_dir, output_dir):
    """
    """
    crunch_commands = [
        aapt, "crunch", "-C", output_dir, "-S", input_dir, "--ignore-assets",
        build_utils.AAPT_IGNORE_PATTERN
    ]
    build_utils.check_output(args=crunch_commands)
    pass
예제 #4
0
def _run_dx(args, dex_cmd, paths):
    base_dir = args.base_dir
    build_utils.make_directory(base_dir)
    build_utils.remove_subtree(base_dir)

    if args.multi_dex and args.main_dex_list_path:
        dex_cmd += [
            "--minimal-main-dex",
            "--main-dex-list=%s" % args.main_dex_list_path
        ]

    dex_cmd += paths
    build_utils.check_output(dex_cmd, print_stderr=False)

    if args.dex_path.endswith(".zip"):
        remove_unwanted_files_from_zip(args.dex_path)
    pass
예제 #5
0
def main(argv):
    args = parse_args(argv)

    base_dir = args.base_dir
    build_utils.delete_directory(base_dir)
    build_utils.make_directory(base_dir)

    for f in args.paths:
        classname = os.path.splitext(os.path.basename(f))[0]
        output = os.path.join(base_dir, classname + ".java")
        aidl_cmd = [args.aidl_path]
        for s in args.imports:
            aidl_cmd += ["-p", s]
        if args.includes:
            for s in args.includes:
                aidl_cmd += ["-I", s]
        aidl_cmd += [f, output]
        build_utils.check_output(aidl_cmd)
        pass

    with zipfile.ZipFile(args.srcjar, "w") as srcjar:
        for f in build_utils.find_in_directory(base_dir, "*.java"):
            with open(f, "r") as fileobj:
                data = fileobj.read()
                pass

            pkg_name = re.compile(r"^\s*package\s+(.*?)\s*;",
                                  re.M).search(data).group(1)
            arcname = "%s/%s" % (pkg_name.replace(".",
                                                  "/"), os.path.basename(f))
            srcjar.writestr(arcname, data)
        pass

    if args.depfile:
        all_dep_paths = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
예제 #6
0
    def check_output(self):
        self.build()
        open(self._outjar + ".dump", "w").close()
        open(self._outjar + ".seeds", "w").close()
        open(self._outjar + ".usage", "w").close()
        open(self._outjar + ".mapping", "w").close()
        stdout_filter = None
        stderr_filter = None
        if not self._verbose:
            stdout_filter = _ProguardOututFilter()
            stderr_filter = _ProguardOututFilter()

        build_utils.check_output(args=self.build(),
                                 print_stdout=True,
                                 print_stderr=True,
                                 stdout_filter=stdout_filter,
                                 stderr_filter=stderr_filter)
        this_info = {
            "inputs": self._injars,
            "configs": self._configs,
            "mapping": self._outjar + ".mapping"
        }
        build_utils.write_json(this_info, self._outjar + ".info")
        pass
def _on_stale_md5(package_command, args):
    base_dir = args.base_dir
    build_utils.make_directory(base_dir)
    build_utils.remove_subtree(base_dir)

    if args.resource_zips:
        for z in args.resource_zips:
            subdir = os.path.join(base_dir, os.path.basename(z))
            if os.path.exists(subdir):
                raise Exception("Resource zip name conflict: " +
                                os.path.basename(z))
            build_utils.extract_all(z, base_dir=subdir)
            package_command += package_args_for_extracted_zips(subdir)
            pass

    build_utils.check_output(args=package_command)

    if args.create_density_splits or args.language_splits:
        check_for_missed_configs(args.apk_path, args.create_density_splits,
                                 args.language_splits)

    if args.create_density_splits:
        rename_density_splits(args.apk_path)
    pass
예제 #8
0
def _on_stale_md5(args):
    aapt = args.aapt_path
    base_dir = args.base_dir
    build_utils.make_directory(base_dir)
    build_utils.remove_subtree(base_dir)

    deps_dir = os.path.join(base_dir, "deps")
    build_utils.make_directory(deps_dir)
    v14_dir = os.path.join(base_dir, "v14")
    build_utils.make_directory(v14_dir)
    gen_dir = os.path.join(base_dir, "gen")
    build_utils.make_directory(gen_dir)

    input_resource_dirs = args.resource_dirs

    dep_files = args.dependency_res_zips
    dep_subdirs = []
    for z in dep_files:
        dep_subdir = os.path.join(deps_dir, os.path.basename(z))
        if os.path.exists(dep_subdir):
            raise Exception("%s already exists" % dep_subdir)
        build_utils.make_directory(dep_subdir)
        dep_subdirs.append(dep_subdir)
        build_utils.extract_all(z, dep_subdir)
        pass

    package_command = [
        aapt,
        "package",
        "-m",
        "-M",
        args.android_manifest,
        "--auto-add-overlay",
        "--no-version-vectors",
        "-I",
        args.android_sdk_jar,
        "--output-text-symbols",
        gen_dir,
        "-J",
        gen_dir,
        "--ignore-assets",
        build_utils.AAPT_IGNORE_PATTERN,
    ]

    for d in input_resource_dirs:
        package_command += ["-S", d]

    for d in dep_subdirs:
        package_command += ["-S", d]

    if args.non_constant_id:
        package_command.append("--non-constant-id")
    if args.custom_package:
        package_command += ["--custom-package", args.custom_package]
    if args.proguard_file:
        package_command += ["-G", args.proguard_file]
    if args.shared_resources:
        package_command += ["--shared-lib"]
    if args.app_as_shared_lib:
        package_command += ["--app-as-shared-lib"]

    build_utils.check_output(args=package_command)

    base_crunch_dir = os.path.join(base_dir, "crunch")
    build_utils.make_directory(base_crunch_dir)

    zip_resources_dirs = list(input_resource_dirs)

    for idx, input_resource_dir in enumerate(input_resource_dirs):
        crunch_dir = os.path.join(base_crunch_dir, str(idx))
        build_utils.make_directory(crunch_dir)
        crunch_directory(aapt, input_resource_dir, crunch_dir)
        zip_resources_dirs.append(crunch_dir)
        pass

    create_resources_zip(zip_resources_dirs, args.resource_zip_out)

    if args.all_resources_zip_out:
        combine_zips([args.resource_zip_out] + dep_files,
                     args.all_resources_zip_out)

    if args.extra_res_packages:
        create_extra_r_java_files(gen_dir, args.extra_res_packages,
                                  args.extra_r_text_files, False)
        pass

    if args.srcjar_out:
        build_utils.zip_dir(args.srcjar_out, gen_dir)
        pass

    if args.r_text_out:
        shutil.copyfile(os.path.join(gen_dir, "R.txt"), args.r_text_out)
        pass
    pass