Example #1
0
def run_task_build_pdfium():
    f.debug("Building PDFium...")

    target = "android"
    build_dir = os.path.join("build", target)
    f.create_dir(build_dir)

    target_dir = os.path.join(build_dir, "pdfium")
    f.remove_dir(target_dir)

    cwd = build_dir
    command = " ".join(
        [
            "gclient",
            "config",
            "--unmanaged",
            "https://pdfium.googlesource.com/pdfium.git",
        ]
    )
    check_call(command, cwd=cwd, shell=True)

    gclient_file = os.path.join(build_dir, ".gclient")
    f.append_to_file(gclient_file, "target_os = [ 'android' ]")

    cwd = build_dir
    command = " ".join(["gclient", "sync"])
    check_call(command, cwd=cwd, shell=True)

    cwd = target_dir
    command = " ".join(["git", "checkout", c.pdfium_git_commit])
    check_call(command, cwd=cwd, shell=True)
Example #2
0
def run_task_install():
    f.debug("Installing libraries...")

    # configs
    for config in c.configurations_ios:
        f.remove_dir(os.path.join("build", "ios", config))
        f.create_dir(os.path.join("build", "ios", config))

        # targets
        for target in c.targets_ios:
            files = get_compiled_files(config, target)

            files_str = " ".join(files)

            lib_file_out = os.path.join(
                "build", "ios", config, "libpdfium_{0}.a".format(target["target_cpu"])
            )

            # we have removed symbols to squeeze final results. -no_warning_for_no_symbols will save us from useless warnings.
            command = " ".join(
                [
                    "libtool",
                    "-static -no_warning_for_no_symbols",
                    files_str,
                    "-o",
                    lib_file_out,
                ]
            )
            check_call(command, shell=True)

        # universal
        folder = os.path.join("build", "ios", config, "*.a")
        files = glob.glob(folder)
        files_str = " ".join(files)
        lib_file_out = os.path.join("build", "ios", config, "libpdfium.a")

        f.debug("Merging libraries (lipo)...")
        command = " ".join(["lipo", "-create", files_str, "-o", lib_file_out])
        check_call(command, shell=True)

        f.debug("File data...")
        command = " ".join(["file", lib_file_out])
        check_call(command, shell=True)

        f.debug("File size...")
        command = " ".join(["ls", "-lh ", lib_file_out])
        check_call(command, shell=True)

        # include
        include_dir = os.path.join("build", "ios", "pdfium", "public")
        target_include_dir = os.path.join("build", "ios", config, "include")
        f.remove_dir(target_include_dir)
        f.create_dir(target_include_dir)

        for basename in os.listdir(include_dir):
            if basename.endswith(".h"):
                pathname = os.path.join(include_dir, basename)

                if os.path.isfile(pathname):
                    shutil.copy2(pathname, target_include_dir)
Example #3
0
def run_task_test():
    f.debug("Testing...")

    current_dir = os.getcwd()
    sample_dir = os.path.join(current_dir, "sample")
    build_dir = os.path.join(sample_dir, "build")

    f.remove_dir(build_dir)
    f.create_dir(build_dir)

    os.chdir(build_dir)

    # generate project
    command = " ".join(["cmake", "../"])

    check_call(command, shell=True)

    # build
    command = " ".join(["cmake", "--build", "."])
    check_call(command, shell=True)

    # copy assets
    copyfile(os.path.join(sample_dir, "assets", "f1.pdf"),
             os.path.join(build_dir, "f1.pdf"))

    # run
    command = " ".join(["./sample"])
    check_call(command, shell=True)

    # finish
    os.chdir(current_dir)
Example #4
0
def run_task_test():
    f.debug("Testing...")

    current_dir = os.getcwd()
    sample_dir = os.path.join(current_dir, "sample-wasm")
    build_dir = os.path.join(sample_dir, "build")
    http_dir = os.path.join("sample-wasm", "build")

    for config in c.configurations_wasm:
        for target in c.targets_wasm:
            lib_file_out = os.path.join(
                current_dir,
                "build",
                target["target_os"],
                target["target_cpu"],
                config,
                "lib",
                "libpdfium.a",
            )

            include_dir = os.path.join(
                current_dir,
                "build",
                target["target_os"],
                target["target_cpu"],
                config,
                "include",
            )

            f.remove_dir(build_dir)
            f.create_dir(build_dir)

            # build
            command = " ".join([
                "em++",
                "-o",
                "build/index.html",
                "src/main.cpp",
                lib_file_out,
                "-I{0}".format(include_dir),
                "-s",
                "DEMANGLE_SUPPORT=1",
                "-s",
                "USE_ZLIB=1",
                "-s",
                "USE_LIBJPEG=1",
                "-s",
                "WASM=1",
                "-s",
                "ASSERTIONS=1",
                "-s",
                "ALLOW_MEMORY_GROWTH=1",
                "--embed-file",
                "assets/web-assembly.pdf",
            ])
            check_call(command, cwd=sample_dir, shell=True)

            f.debug(
                "Test on browser with: python -m http.server --directory {0}".
                format(http_dir))
Example #5
0
def run_task_build_emsdk():
    f.debug("Building Emscripten SDK...")

    build_dir = os.path.join("build")
    f.create_dir(build_dir)

    tools_dir = os.path.join(build_dir, "emsdk")
    f.remove_dir(tools_dir)

    cwd = build_dir
    command = " ".join([
        "git",
        "clone",
        "https://github.com/emscripten-core/emsdk.git",
    ])
    check_call(command, cwd=cwd, shell=True)

    cwd = tools_dir
    command = " ".join(["./emsdk", "install", "latest"])
    check_call(command, cwd=cwd, shell=True)

    cwd = tools_dir
    command = " ".join(["./emsdk", "activate", "latest"])
    check_call(command, cwd=cwd, shell=True)

    cwd = tools_dir
    command = " ".join(["source", "emsdk_env.sh"])
    check_call(command, cwd=cwd, shell=True)
Example #6
0
def run_task_build_depot_tools():
    f.debug("Building depot tools...")

    build_dir = os.path.join("build")
    f.create_dir(build_dir)

    tools_dir = os.path.join(build_dir, "depot-tools")
    f.remove_dir(tools_dir)

    cwd = build_dir
    command = " ".join([
        "git",
        "clone",
        "https://chromium.googlesource.com/chromium/tools/depot_tools.git",
        "depot-tools",
    ])
    check_call(command, cwd=cwd, shell=True)

    f.debug(
        "Execute on your terminal: export PATH=$PATH:$PWD/build/depot-tools")
Example #7
0
def run_task_install():
    f.debug("Installing libraries...")

    # configs
    for config in c.configurations_android:
        f.remove_dir(os.path.join("build", "android", config))
        f.create_dir(os.path.join("build", "android", config))

        # targets
        for target in c.targets_android:
            out_dir = "{0}-{1}-{2}".format(
                config, target["target_os"], target["target_cpu"]
            )
            library_dir = os.path.join("build", "android", "pdfium", "out", out_dir)
            target_dir = os.path.join("build", "android", config, target["android_cpu"])

            f.remove_dir(target_dir)
            f.create_dir(target_dir)

            for basename in os.listdir(library_dir):
                if basename.endswith(".so"):
                    pathname = os.path.join(library_dir, basename)

                    if os.path.isfile(pathname):
                        shutil.copy2(pathname, target_dir)

        # include
        include_dir = os.path.join("build", "android", "pdfium", "public")
        target_include_dir = os.path.join("build", "android", config, "include")
        f.remove_dir(target_include_dir)
        f.create_dir(target_include_dir)

        for basename in os.listdir(include_dir):
            if basename.endswith(".h"):
                pathname = os.path.join(include_dir, basename)

                if os.path.isfile(pathname):
                    shutil.copy2(pathname, target_include_dir)
Example #8
0
def run_task_build():
    f.debug("Building libraries...")

    current_dir = os.getcwd()

    # configs
    for config in c.configurations_android:
        # targets
        for target in c.targets_android:
            main_dir = os.path.join(
                "build",
                target["target_os"],
                "pdfium",
                "out",
                "{0}-{1}-{2}".format(config, target["target_os"], target["target_cpu"]),
            )

            f.remove_dir(main_dir)
            f.create_dir(main_dir)

            os.chdir(
                os.path.join(
                    "build",
                    target["target_os"],
                    "pdfium",
                )
            )

            # generating files...
            f.debug(
                'Generating files to arch "{0}" and configuration "{1}"...'.format(
                    target["target_cpu"], config
                )
            )

            arg_is_debug = "true" if config == "debug" else "false"

            args = []
            args.append('target_os="{0}"'.format(target["pdfium_os"]))
            args.append('target_cpu="{0}"'.format(target["target_cpu"]))
            args.append("use_goma=false")
            args.append("is_debug={0}".format(arg_is_debug))
            args.append("pdf_use_skia=false")
            args.append("pdf_use_skia_paths=false")
            args.append("pdf_enable_xfa=false")
            args.append("pdf_enable_v8=false")
            args.append("is_component_build=true")
            args.append("pdf_is_standalone=true")
            args.append("pdf_bundle_freetype=true")

            if config == "release":
                args.append("symbol_level=0")

            args_str = " ".join(args)

            command = " ".join(
                [
                    "gn",
                    "gen",
                    "out/{0}-{1}-{2}".format(
                        config, target["target_os"], target["target_cpu"]
                    ),
                    "--args='{0}'".format(args_str),
                ]
            )
            check_call(command, shell=True)

            # compiling...
            f.debug(
                'Compiling to arch "{0}" and configuration "{1}"...'.format(
                    target["target_cpu"], config
                )
            )

            command = " ".join(
                [
                    "ninja",
                    "-C",
                    "out/{0}-{1}-{2}".format(
                        config, target["target_os"], target["target_cpu"]
                    ),
                    "pdfium",
                    "-v",
                ]
            )
            check_call(command, shell=True)

            os.chdir(current_dir)
Example #9
0
def run_task_install():
    f.debug("Installing libraries...")

    # configs
    for config in c.configurations_ios:
        f.remove_dir(os.path.join("build", "ios", config))
        f.create_dir(os.path.join("build", "ios", config))
        f.create_dir(os.path.join("build", "ios", config, "lib"))

        # targets
        for target in c.targets_ios:
            source_lib_path = os.path.join(
                "build",
                target["target_os"],
                "pdfium",
                "out",
                "{0}-{1}-{2}".format(target["target_os"], target["target_cpu"],
                                     config),
                "obj",
                "libpdfium.a",
            )

            target_lib_path = os.path.join(
                "build",
                target["target_os"],
                config,
                "lib",
                "libpdfium_{0}.a".format(target["target_cpu"]),
            )

            f.copy_file(source_lib_path, target_lib_path)

        # universal
        folder = os.path.join("build", "ios", config, "lib", "*.a")
        files = glob.glob(folder)
        files_str = " ".join(files)
        lib_file_out = os.path.join("build", "ios", config, "lib",
                                    "libpdfium.a")

        f.debug("Merging libraries (lipo)...")
        command = " ".join(["lipo", "-create", files_str, "-o", lib_file_out])
        check_call(command, shell=True)

        f.debug("File data...")
        command = " ".join(["file", lib_file_out])
        check_call(command, shell=True)

        f.debug("File size...")
        command = " ".join(["ls", "-lh ", lib_file_out])
        check_call(command, shell=True)

        # include
        include_dir = os.path.join("build", "ios", "pdfium", "public")
        target_include_dir = os.path.join("build", "ios", config, "include")
        f.remove_dir(target_include_dir)
        f.create_dir(target_include_dir)

        for basename in os.listdir(include_dir):
            if basename.endswith(".h"):
                pathname = os.path.join(include_dir, basename)

                if os.path.isfile(pathname):
                    f.copy_file2(pathname, target_include_dir)
Example #10
0
def run_task_build():
    f.debug("Building libraries...")

    current_dir = os.getcwd()

    # configs
    for config in c.configurations_ios:
        # targets
        for target in c.targets_ios:
            main_dir = os.path.join(
                "build",
                target["target_os"],
                "pdfium",
                "out",
                "{0}-{1}-{2}".format(target["target_os"], target["target_cpu"],
                                     config),
            )

            f.remove_dir(main_dir)
            f.create_dir(main_dir)

            os.chdir(os.path.join(
                "build",
                target["target_os"],
                "pdfium",
            ))

            # generating files...
            f.debug(
                'Generating files to arch "{0}" and configuration "{1}"...'.
                format(target["target_cpu"], config))

            arg_is_debug = "true" if config == "debug" else "false"

            args = []
            args.append('target_os="{0}"'.format(target["pdfium_os"]))
            args.append('target_cpu="{0}"'.format(target["target_cpu"]))
            args.append("use_goma=false")
            args.append("is_debug={0}".format(arg_is_debug))
            args.append("pdf_use_skia=false")
            args.append("pdf_use_skia_paths=false")
            args.append("pdf_enable_xfa=false")
            args.append("pdf_enable_v8=false")
            args.append("is_component_build=false")
            args.append("clang_use_chrome_plugins=false")
            args.append("pdf_is_standalone=false")
            args.append('ios_deployment_target="9.0"')
            args.append("ios_enable_code_signing=false")
            args.append("use_xcode_clang=true")
            args.append("pdf_is_complete_lib=true")

            if target["target_cpu"] == "arm":
                args.append("enable_ios_bitcode=true")
                args.append("arm_use_neon=false")
            elif target["target_cpu"] == "arm64":
                args.append("enable_ios_bitcode=true")

            if config == "release":
                args.append("symbol_level=0")

            args_str = " ".join(args)

            command = " ".join([
                "gn",
                "gen",
                "out/{0}-{1}-{2}".format(target["target_os"],
                                         target["target_cpu"], config),
                "--args='{0}'".format(args_str),
            ])
            check_call(command, shell=True)

            # compiling...
            f.debug(
                'Compiling to arch "{0}" and configuration "{1}"...'.format(
                    target["target_cpu"], config))

            command = " ".join([
                "ninja",
                "-C",
                "out/{0}-{1}-{2}".format(target["target_os"],
                                         target["target_cpu"], config),
                "pdfium",
                "-v",
            ])
            check_call(command, shell=True)

            os.chdir(current_dir)
Example #11
0
def run_task_generate():
    f.debug("Generating...")

    current_dir = os.getcwd()

    for config in c.configurations_wasm:
        for target in c.targets_wasm:
            # paths
            utils_dir = os.path.join(current_dir, "extras", "wasm", "utils")
            template_dir = os.path.join(current_dir, "extras", "wasm",
                                        "template")

            relative_dir = os.path.join(
                "build",
                target["target_os"],
                target["target_cpu"],
            )

            root_dir = os.path.join(current_dir, relative_dir)
            main_dir = os.path.join(root_dir, config)
            lib_dir = os.path.join(main_dir, "lib")
            include_dir = os.path.join(main_dir, "include")
            gen_dir = os.path.join(root_dir, "gen")
            node_dir = os.path.join(main_dir, "node")
            http_dir = os.path.join(relative_dir, config, "node")

            f.remove_dir(gen_dir)
            f.create_dir(gen_dir)

            # doxygen
            f.debug("Doxygen...")

            doxygen_file = os.path.join(
                current_dir,
                "extras",
                "wasm",
                "doxygen",
                "Doxyfile",
            )

            command = " ".join([
                "doxygen",
                doxygen_file,
            ])
            check_call(command, cwd=include_dir, shell=True)

            # copy xml files
            f.debug("Copying xml files...")

            xml_dir = os.path.join(include_dir, "xml")
            f.copy_dir(xml_dir, os.path.join(gen_dir, "xml"))
            f.remove_dir(xml_dir)

            # copy utils files
            f.debug("Copying utils files...")

            f.copy_dir(utils_dir, os.path.join(gen_dir, "utils"))

            # prepare files
            f.debug("Preparing files...")

            rsp_file = os.path.join(gen_dir, "utils", "pdfium.rsp")
            f.replace_in_file(rsp_file, "{LIB_DIR}", lib_dir)
            f.replace_in_file(rsp_file, "{INCLUDE_DIR}", include_dir)

            # node modules
            f.debug("Installing node modules...")

            gen_utils_dir = os.path.join(
                gen_dir,
                "utils",
            )

            command = " ".join([
                "npm",
                "install",
            ])
            check_call(command, cwd=gen_utils_dir, shell=True)

            # generate
            f.debug("Compiling with emscripten...")

            gen_out_dir = os.path.join(
                gen_dir,
                "out",
            )

            f.remove_dir(gen_out_dir)
            f.create_dir(gen_out_dir)

            html_file = os.path.join(
                gen_out_dir,
                "pdfium.html",
            )

            command = " ".join([
                "em++",
                "-o",
                html_file,
                "-s",
                'EXPORTED_FUNCTIONS="$(node function-names ../xml/index.xml)"',
                "-s",
                'EXTRA_EXPORTED_RUNTIME_METHODS=\'["ccall", "cwrap"]\'',
                "custom.cpp",
                "@pdfium.rsp",
                "-O3",
                "-std=c++11",
                "-Wall",
                "--no-entry",
            ])
            check_call(command, cwd=gen_utils_dir, shell=True)

            # copy files
            f.debug("Copying compiled files...")

            f.remove_dir(node_dir)
            f.copy_dir(gen_out_dir, node_dir)

            # copy template files
            f.debug("Copying template files...")

            f.copy_file(
                os.path.join(template_dir, "index.html"),
                os.path.join(node_dir, "index.html"),
            )

            # test
            f.debug(
                "Test on browser with: python -m http.server --directory {0}".
                format(http_dir))

    f.debug("Generated")
Example #12
0
def run_task_install():
    f.debug("Installing libraries...")

    # configs
    for config in c.configurations_wasm:
        for target in c.targets_wasm:
            f.remove_dir(
                os.path.join("build", target["target_os"],
                             target["target_cpu"], config))

            f.create_dir(
                os.path.join("build", target["target_os"],
                             target["target_cpu"], config))

            f.create_dir(
                os.path.join("build", target["target_os"],
                             target["target_cpu"], config, "lib"))

            source_lib_path = os.path.join(
                "build",
                target["target_os"],
                "pdfium",
                "out",
                "{0}-{1}-{2}".format(target["target_os"], target["target_cpu"],
                                     config),
                "obj",
                "libpdfium.a",
            )

            target_lib_path = os.path.join(
                "build",
                target["target_os"],
                target["target_cpu"],
                config,
                "lib",
                "libpdfium.a",
            )

            f.copy_file(source_lib_path, target_lib_path)

            # check file
            f.debug("File data...")
            command = " ".join(["file", target_lib_path])
            check_call(command, shell=True)

            f.debug("File size...")
            command = " ".join(["ls", "-lh ", target_lib_path])
            check_call(command, shell=True)

            # include
            include_dir = os.path.join("build", "linux", "pdfium", "public")
            target_include_dir = os.path.join("build", target["target_os"],
                                              target["target_cpu"], config,
                                              "include")

            f.remove_dir(target_include_dir)
            f.create_dir(target_include_dir)

            for basename in os.listdir(include_dir):
                if basename.endswith(".h"):
                    pathname = os.path.join(include_dir, basename)

                    if os.path.isfile(pathname):
                        f.copy_file2(pathname, target_include_dir)
Example #13
0
def run_task_patch():
    f.debug("Patching...")

    source_dir = os.path.join("build", "linux", "pdfium")

    # build config
    source_file = os.path.join(
        source_dir,
        "build",
        "build_config.h",
    )
    if f.file_line_has_content(
            source_file,
            201,
            "#error Please add support for your architecture in build/build_config.h\n",
    ):
        f.replace_line_in_file(
            source_file,
            201,
            "#define ARCH_CPU_X86_FAMILY 1\n#define ARCH_CPU_32_BITS 1\n#define ARCH_CPU_LITTLE_ENDIAN 1\n",
        )

        f.debug("Applied: build config")
    else:
        f.debug("Skipped: build config")

    # compiler thin archive
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "BUILDCONFIG.gn",
    )
    if f.file_line_has_content(
            source_file,
            342,
            '  "//build/config/compiler:thin_archive",\n',
    ):
        f.replace_line_in_file(
            source_file,
            342,
            '  #"//build/config/compiler:thin_archive",\n',
        )

        f.debug("Applied: compiler thin archive")
    else:
        f.debug("Skipped: compiler thin archive")

    # build thin archive
    source_file = os.path.join(
        source_dir,
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            203,
            '    configs -= [ "//build/config/compiler:thin_archive" ]\n',
    ):
        f.replace_line_in_file(
            source_file,
            203,
            '    #configs -= [ "//build/config/compiler:thin_archive" ]\n',
        )

        f.debug("Applied: build thin archive")
    else:
        f.debug("Skipped: build thin archive")

    # compiler
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            768,
            '        "-m64",\n',
    ):
        f.replace_line_in_file(
            source_file,
            768,
            '        #"-m64",\n',
        )
        f.replace_line_in_file(
            source_file,
            769,
            '        #"-march=$x64_arch",\n',
        )
        f.replace_line_in_file(
            source_file,
            770,
            '        #"-msse3",\n',
        )

        f.debug("Applied: compiler")
    else:
        f.debug("Skipped: compiler")

    # pragma optimize
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            1541,
            '          "-Wno-ignored-pragma-optimize",\n',
    ):
        f.replace_line_in_file(
            source_file,
            1541,
            '          "-Wno-deprecated-register",\n',
        )

        f.debug("Applied: pragma optimize")
    else:
        f.debug("Skipped: pragma optimize")

    # pubnames
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            2358,
            '        cflags += [ "-ggnu-pubnames" ]\n',
    ):
        f.replace_line_in_file(
            source_file,
            2358,
            '        #cflags += [ "-ggnu-pubnames" ]\n',
        )

        f.debug("Applied: pubnames")
    else:
        f.debug("Skipped: pubnames")

    # gcc toolchain
    source_file = os.path.join(
        source_dir,
        "build",
        "toolchain",
        "gcc_toolchain.gni",
    )
    if f.file_line_has_content(
            source_file,
            643,
            '    cc = "$prefix/clang"\n',
    ):
        f.replace_line_in_file(
            source_file,
            643,
            '    cc = "emcc"\n',
        )
        f.replace_line_in_file(
            source_file,
            644,
            '    cxx = "em++"\n',
        )

        f.debug("Applied: gcc toolchain")
    else:
        f.debug("Skipped: gcc toolchain")

    # partition allocator
    source_file = os.path.join(
        source_dir,
        "third_party",
        "base",
        "allocator",
        "partition_allocator",
        "spin_lock.cc",
    )
    if f.file_line_has_content(
            source_file,
            54,
            '#warning "Processor yield not supported on this architecture."\n',
    ):
        f.replace_line_in_file(
            source_file,
            54,
            '//#warning "Processor yield not supported on this architecture."\n',
        )

        f.debug("Applied: partition allocator")
    else:
        f.debug("Skipped: partition allocator")

    # compiler stack protector
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            306,
            '        cflags += [ "-fstack-protector" ]\n',
    ):
        f.replace_line_in_file(
            source_file,
            306,
            '        cflags += [ "-fno-stack-protector" ]\n',
        )

        f.debug("Applied: compiler stack protector")
    else:
        f.debug("Skipped: compiler stack protector")

    # build pthread
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            236,
            '      "pthread",\n',
    ):
        f.replace_line_in_file(
            source_file,
            236,
            '      #"pthread",\n',
        )

        f.debug("Applied: build pthread")
    else:
        f.debug("Skipped: build pthread")

    # compiler pthread
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            465,
            '    cflags += [ "-pthread" ]\n',
    ):
        f.replace_line_in_file(
            source_file,
            465,
            '    #cflags += [ "-pthread" ]\n',
        )

        f.debug("Applied: compiler pthread")
    else:
        f.debug("Skipped: compiler pthread")

    # skia pthread
    source_file = os.path.join(
        source_dir,
        "third_party",
        "skia",
        "gn",
        "BUILD.gn",
    )
    if f.file_line_has_content(
            source_file,
            231,
            '    libs += [ "pthread" ]\n',
    ):
        f.replace_line_in_file(
            source_file,
            231,
            '    #libs += [ "pthread" ]\n',
        )

        f.debug("Applied: skia pthread")
    else:
        f.debug("Skipped: skia pthread")

    # copy files required
    f.debug("Copying required files...")

    linux_dir = os.path.join(source_dir, "linux")
    f.create_dir(linux_dir)

    f.copy_file("/usr/include/jpeglib.h", os.path.join(source_dir,
                                                       "jpeglib.h"))
    f.copy_file("/usr/include/jmorecfg.h",
                os.path.join(source_dir, "jmorecfg.h"))
    f.copy_file("/usr/include/zlib.h", os.path.join(source_dir, "zlib.h"))
    f.copy_file("/usr/include/zconf.h", os.path.join(source_dir, "zconf.h"))
    f.copy_file("/usr/include/jerror.h", os.path.join(source_dir, "jerror.h"))
    f.copy_file("/usr/include/x86_64-linux-gnu/jconfig.h",
                os.path.join(source_dir, "jconfig.h"))
    f.copy_file("/usr/include/linux/limits.h",
                os.path.join(linux_dir, "limits.h"))

    f.debug("Copied!")
Example #14
0
def run_task_generate():
    f.debug("Generating...")

    current_dir = os.getcwd()

    for config in c.configurations_wasm:
        for target in c.targets_wasm:
            # paths
            utils_dir = os.path.join(current_dir, "extras", "wasm", "utils")
            template_dir = os.path.join(current_dir, "extras", "wasm",
                                        "template")

            relative_dir = os.path.join(
                "build",
                target["target_os"],
                target["target_cpu"],
            )

            root_dir = os.path.join(current_dir, relative_dir)
            main_dir = os.path.join(root_dir, config)
            lib_dir = os.path.join(main_dir, "lib")
            include_dir = os.path.join(main_dir, "include")
            gen_dir = os.path.join(root_dir, "gen")
            node_dir = os.path.join(main_dir, "node")
            http_dir = os.path.join(relative_dir, config, "node")
            lib_file_out = os.path.join(lib_dir, "libpdfium.a")

            f.remove_dir(gen_dir)
            f.create_dir(gen_dir)

            # doxygen
            f.debug("Doxygen...")

            doxygen_file = os.path.join(
                current_dir,
                "extras",
                "wasm",
                "doxygen",
                "Doxyfile",
            )

            command = " ".join([
                "doxygen",
                doxygen_file,
            ])
            check_call(command, cwd=include_dir, shell=True)

            # copy xml files
            f.debug("Copying xml files...")

            xml_dir = os.path.join(include_dir, "xml")
            f.copy_dir(xml_dir, os.path.join(gen_dir, "xml"))
            f.remove_dir(xml_dir)

            # copy utils files
            f.debug("Copying utils files...")
            f.copy_dir(utils_dir, os.path.join(gen_dir, "utils"))

            # node modules
            f.debug("Installing node modules...")

            gen_utils_dir = os.path.join(
                gen_dir,
                "utils",
            )

            command = " ".join([
                "npm",
                "install",
            ])
            check_call(command, cwd=gen_utils_dir, shell=True)

            # generate
            f.debug("Compiling with emscripten...")

            gen_out_dir = os.path.join(
                gen_dir,
                "out",
            )

            f.remove_dir(gen_out_dir)
            f.create_dir(gen_out_dir)

            html_file = os.path.join(
                gen_out_dir,
                "pdfium.html",
            )

            command = " ".join([
                "em++",
                "{0}".format("-g" if config == "debug" else "-O3"),
                "-o",
                html_file,
                "-s",
                'EXPORTED_FUNCTIONS="$(node function-names ../xml/index.xml)"',
                "-s",
                'EXPORTED_RUNTIME_METHODS=\'["ccall", "cwrap"]\'',
                "custom.cpp",
                lib_file_out,
                "-I{0}".format(include_dir),
                "-s",
                "DEMANGLE_SUPPORT=1",
                "-s",
                "USE_ZLIB=1",
                "-s",
                "USE_LIBJPEG=1",
                "-s",
                "WASM=1",
                "-s",
                "ASSERTIONS=1",
                "-s",
                "ALLOW_MEMORY_GROWTH=1",
                "-std=c++11",
                "-Wall",
                "--no-entry",
            ])
            check_call(command, cwd=gen_utils_dir, shell=True)

            # copy files
            f.debug("Copying compiled files...")

            f.remove_dir(node_dir)
            f.copy_dir(gen_out_dir, node_dir)

            # copy template files
            f.debug("Copying template files...")

            f.copy_file(
                os.path.join(template_dir, "index.html"),
                os.path.join(node_dir, "index.html"),
            )

            # change template tags
            f.debug("Replacing template tags...")

            f.replace_in_file(
                os.path.join(node_dir, "index.html"),
                "{pdfium-branch}",
                c.pdfium_git_branch,
            )

            f.replace_in_file(
                os.path.join(node_dir, "index.html"),
                "{pdfium-commit}",
                c.pdfium_git_commit,
            )

            # test
            f.debug(
                "Test on browser with: python -m http.server --directory {0}".
                format(http_dir))

    f.debug("Generated")