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)
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++", "{0}".format("-g" if config == "debug" else ""), "-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))
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")
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)
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, 333, ' "//build/config/compiler:thin_archive",\n', ): f.replace_line_in_file( source_file, 333, ' #"//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, 219, ' configs -= [ "//build/config/compiler:thin_archive" ]\n', ): f.replace_line_in_file( source_file, 219, ' #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, 853, ' "-m64",\n', ): f.replace_line_in_file( source_file, 853, ' #"-m64",\n', ) f.replace_line_in_file( source_file, 854, ' #"-march=$x64_arch",\n', ) f.replace_line_in_file( source_file, 855, ' #"-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, 1626, ' "-Wno-ignored-pragma-optimize",\n', ): f.replace_line_in_file( source_file, 1626, ' "-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, 2406, ' cflags += [ "-ggnu-pubnames" ]\n', ): f.replace_line_in_file( source_file, 2406, ' #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, 677, ' cc = "$prefix/clang"\n', ): f.replace_line_in_file( source_file, 677, ' cc = "emcc"\n', ) f.replace_line_in_file( source_file, 678, ' 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, 333, ' cflags += [ "-fstack-protector" ]\n', ): f.replace_line_in_file( source_file, 333, ' cflags += [ "-fno-stack-protector" ]\n', ) f.replace_line_in_file( source_file, 345, ' 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, 231, ' "pthread",\n', ): f.replace_line_in_file( source_file, 231, ' #"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, 494, ' cflags += [ "-pthread" ]\n', ): f.replace_line_in_file( source_file, 494, ' #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", "skia", "BUILD.gn", ) if f.file_line_has_content( source_file, 224, ' libs += [ "pthread" ]\n', ): f.replace_line_in_file( source_file, 224, ' #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/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!")
def main(options): # show all params for debug if ("--debug" in options and options["--debug"]) or ( "-d" in options and options["-d"] ): c.make_debug = True if c.make_debug: f.debug("You have executed with options:") f.message(str(options)) f.message("") # bind options if "<task-name>" in options: make_task = options["<task-name>"] # validate data f.debug("Validating data...") # validate task if not make_task: f.error("Task is invalid") # build depot tools if make_task == "format": common.run_task_format() # build depot tools elif make_task == "build-depot-tools": common.run_task_build_depot_tools() ####################### # iOS ####################### # build pdfium - ios elif make_task == "build-pdfium-ios": ios.run_task_build_pdfium() # patch - ios elif make_task == "patch-ios": ios.run_task_patch() # build - ios elif make_task == "build-ios": ios.run_task_build() # install - ios elif make_task == "install-ios": ios.run_task_install() # test - ios elif make_task == "test-ios": ios.run_task_test() # archive - ios elif make_task == "archive-ios": ios.run_task_archive() ####################### # macOS ####################### # build pdfium - macos elif make_task == "build-pdfium-macos": macos.run_task_build_pdfium() # patch - macos elif make_task == "patch-macos": macos.run_task_patch() # build - macos elif make_task == "build-macos": macos.run_task_build() # install - macos elif make_task == "install-macos": macos.run_task_install() # test - macos elif make_task == "test-macos": macos.run_task_test() # archive - macos elif make_task == "archive-macos": macos.run_task_archive() ####################### # Android ####################### # build pdfium - android elif make_task == "build-pdfium-android": android.run_task_build_pdfium() # patch - android elif make_task == "patch-android": android.run_task_patch() # build - android elif make_task == "build-android": android.run_task_build() # install - android elif make_task == "install-android": android.run_task_install() # test - android elif make_task == "test-android": android.run_task_test() # archive - android elif make_task == "archive-android": android.run_task_archive() ####################### # Invalid ####################### # invalid else: f.error("Task is invalid") f.message("") f.debug("FINISHED!")
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, 247, '#test("pdfium_unittests") {\n'): f.file_line_comment_range( source_file, 247, 294) # comment all lines of "pdfium_unittests" f.file_line_comment_range(source_file, 385, 386) # group "pdfium_all", comment all tests f.debug("Applied: Build GN") else: f.debug("Skipped: Build GN") # deprecated warning source_file = os.path.join( source_dir, "BUILD.gn", ) if f.file_line_has_content(source_file, 56, ' cflags += [ "-Wdeprecated-copy" ]\n'): f.file_line_comment(source_file, 56) f.debug("Applied: Deprecated Warning") else: f.debug("Skipped: Deprecated Warning") # 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 f.file_line_has_content(source_file, 1707, ' "-Wimplicit-fallthrough",\n'): f.file_line_comment(source_file, 1707) 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") # carbon - font source_file = os.path.join( source_dir, "core", "fpdfapi", "font", "cpdf_type1font.cpp", ) if not f.file_line_has_content(source_file, 22, "#include <CoreGraphics/CoreGraphics.h>\n"): f.replace_line_in_file( source_file, 22, "#include <CoreGraphics/CoreGraphics.h>\n", ) f.debug("Applied: Carbon - Font") else: f.debug("Skipped: Carbon - Font") # ios simulator source_file = os.path.join( source_dir, "build", "config", "ios", "rules.gni", ) if not f.file_line_has_content( source_file, 954, '# data_deps += [ "//testing/iossim" ]\n'): f.file_line_comment(source_file, 954) 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") # clang 12 source_file = os.path.join( source_dir, "build", "config", "compiler", "BUILD.gn", ) if f.file_line_has_content( source_file, 1237, ' cflags += [ "-ffile-compilation-dir=." ]\n'): f.replace_line_in_file( source_file, 1237, ' cflags += ["-Xclang","-fdebug-compilation-dir","-Xclang","."]\n', ) f.debug("Applied: Clang 12") else: f.debug("Skipped: Clang 12")
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)