Exemplo n.º 1
0
def run_task_patch():
    f.debug("Patching...")

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

    # build gn
    source_file = os.path.join(
        source_dir,
        "BUILD.gn",
    )
    if f.file_line_has_content(source_file, 24, "  ]\n"):
        f.replace_line_in_file(source_file, 24, '    "FPDFSDK_EXPORTS",\n  ]\n')

        f.debug("Applied: Build GN")
    else:
        f.debug("Skipped: Build GN")

    # build gn flags
    source_file = os.path.join(
        source_dir,
        "BUILD.gn",
    )
    if f.file_line_has_content(source_file, 18, "  cflags = []\n"):
        f.replace_line_in_file(
            source_file, 18, '  cflags = [ "-fvisibility=default" ]\n'
        )

        f.debug("Applied: Build GN Flags")
    else:
        f.debug("Skipped: Build GN Flags")

    pass
Exemplo n.º 2
0
def run_task_patch():
    f.debug("Patching...")

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

    # zlib
    source_file = os.path.join(
        source_dir,
        "third_party",
        "zlib",
        "BUILD.gn",
    )
    if not f.file_line_has_content(
            source_file,
            56,
            'use_arm_neon_optimizations = (current_cpu == "arm" || current_cpu == "arm64")\n',
    ):
        f.replace_line_in_file(
            source_file,
            55,
            '\nuse_arm_neon_optimizations = (current_cpu == "arm" || current_cpu == "arm64")\n\n',
        )

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

    # zlib - skia
    source_file = os.path.join(
        source_dir,
        "third_party",
        "skia",
        "third_party",
        "zlib",
        "BUILD.gn",
    )
    if not f.file_line_has_content(
            source_file,
            23,
            '  use_arm_neon_optimizations = (current_cpu == "arm" || current_cpu == "arm64")\n',
    ):
        f.replace_line_in_file(
            source_file,
            22,
            '\n  use_arm_neon_optimizations = (current_cpu == "arm" || current_cpu == "arm64")\n\n',
        )

        f.debug("Applied: zlib - skia")
    else:
        f.debug("Skipped: zlib - skia")

    pass
Exemplo n.º 3
0
def run_task_patch():
    f.debug("Patching...")

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

    # build gn
    source_file = os.path.join(
        source_dir,
        "BUILD.gn",
    )
    if not f.file_line_has_content(source_file, 235,
                                   '#test("pdfium_unittests") {\n'):
        f.file_line_comment_range(source_file, 235, 282)
        f.file_line_comment_range(source_file, 375, 376)

        f.debug("Applied: Build GN")
    else:
        f.debug("Skipped: Build GN")

    # libjpeg
    source_file = os.path.join(
        source_dir,
        "third_party",
        "libjpeg_turbo",
        "BUILD.gn",
    )
    if not f.file_line_has_content(
            source_file,
            13,
            '#assert(!is_ios, "This is not used on iOS, don\'t drag it in unintentionally")\n',
    ):
        f.file_line_comment(source_file, 13)

        f.debug("Applied: Lib JPEG")
    else:
        f.debug("Skipped: Lib JPEG")

    # ios automatically manage certs
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "ios",
        "ios_sdk_overrides.gni",
    )
    if not f.file_has_content(source_file, "ios_automatically_manage_certs"):
        f.append_to_file(
            source_file,
            "if (is_ios) { ios_automatically_manage_certs = true }")

        f.debug("Applied: iOS Automatically Manage Certs")
    else:
        f.debug("Skipped: iOS Automatically Manage Certs")

    # compiler
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "compiler",
        "BUILD.gn",
    )
    if not f.file_line_has_content(source_file, 1630,
                                   '#      "-Wimplicit-fallthrough",\n'):
        f.file_line_comment(source_file, 1630)

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

    # carbon
    source_file = os.path.join(
        source_dir,
        "core",
        "fxge",
        "apple",
        "fx_quartz_device.h",
    )
    if not f.file_line_has_content(source_file, 10,
                                   "#include <CoreGraphics/CoreGraphics.h>\n"):
        f.replace_line_in_file(
            source_file,
            10,
            "#include <CoreGraphics/CoreGraphics.h>\n#include <CoreFoundation/CFString.h>\n",
        )

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

    # ios simulator
    source_file = os.path.join(
        source_dir,
        "build",
        "config",
        "ios",
        "rules.gni",
    )
    if not f.file_line_has_content(
            source_file, 930,
            '#          data_deps += [ "//testing/iossim" ]\n'):
        f.file_line_comment(source_file, 930)

        f.debug("Applied: iOS Simulator")
    else:
        f.debug("Skipped: iOS Simulator")

    # 32bits constexpr
    source_file = os.path.join(
        source_dir,
        "third_party",
        "base",
        "allocator",
        "partition_allocator",
        "address_space_randomization.h",
    )
    if f.file_line_has_content(
            source_file, 248,
            "  constexpr ALWAYS_INLINE uintptr_t ASLRMask() {\n"):
        f.replace_line_in_file(
            source_file,
            248,
            "  PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE uintptr_t ASLRMask() {\n",
        )
        f.replace_line_in_file(
            source_file,
            251,
            "  PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR ALWAYS_INLINE uintptr_t ASLROffset() {\n",
        )

        f.debug("Applied: 32bits constexpr")
    else:
        f.debug("Skipped: 32bits constexpr")

    # ARM Neon
    source_file = os.path.join(
        source_dir,
        "build_overrides",
        "build.gni",
    )
    if f.file_line_has_content(source_file, 18,
                               'if (current_cpu == "arm") {\n'):
        f.replace_line_in_file(source_file, 18,
                               'if (current_cpu == "arm64") {\n')

        f.debug("Applied: ARM Neon")
    else:
        f.debug("Skipped: ARM Neon")

    # core fxge
    source_file = os.path.join(source_dir, "core", "fxge", "BUILD.gn")
    if f.file_line_has_content(source_file, 167, "  if (is_mac) {\n"):
        f.replace_line_in_file(source_file, 167, "  if (is_mac || is_ios) {\n")

        f.debug("Applied: Core FXGE")
    else:
        f.debug("Skipped: Core FXGE")
Exemplo n.º 4
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!")