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)
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)
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)
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)
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))
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")
def run_task_publish(): f.debug("Publishing...") current_dir = os.getcwd() publish_dir = os.path.join(current_dir, "build", "linux", "publish") node_dir = os.path.join(current_dir, "build", "linux", "x64", "release", "node") template_dir = os.path.join(current_dir, "extras", "wasm", "template") # copy generated files f.remove_dir(publish_dir) f.copy_dir(node_dir, publish_dir) # copy template files f.copy_file( os.path.join(template_dir, "README.md"), os.path.join(publish_dir, "README.md"), ) # finish f.debug("Published")
def run_task_publish_to_web(): f.debug("Publishing...") current_dir = os.getcwd() publish_dir = os.path.join(current_dir, "build", "linux", "publish") node_dir = os.path.join(current_dir, "build", "linux", "x64", "release", "node") template_dir = os.path.join(current_dir, "extras", "wasm", "template") # copy generated files f.remove_dir(publish_dir) f.copytree(node_dir, publish_dir) # copy template files f.copyfile( os.path.join(template_dir, "README.md"), os.path.join(publish_dir, "README.md"), ) # clone gh-pages branch command = "git init ." check_call(command, cwd=publish_dir, shell=True) command = "git add ." check_call(command, cwd=publish_dir, shell=True) command = 'git commit -m "published new version"' check_call(command, cwd=publish_dir, shell=True) command = 'git push "[email protected]:paulo-coutinho/pdfium-lib.git" master:gh-pages --force' check_call(command, cwd=publish_dir, shell=True) # finish f.debug( "Test on browser with: https://paulo-coutinho.github.io/pdfium-lib/") f.debug("Published")
def run_task_publish(): f.debug("Publishing...") current_dir = os.getcwd() publish_dir = os.path.join(current_dir, "build", "linux", "publish") node_dir = os.path.join(current_dir, "build", "linux", "x64", "release", "node") template_dir = os.path.join(current_dir, "extras", "wasm", "template") # copy generated files f.remove_dir(publish_dir) f.copy_dir(node_dir, publish_dir) # copy template files f.copy_file( os.path.join(template_dir, "README.md"), os.path.join(publish_dir, "README.md"), ) # finish f.debug( "Test on browser with: https://paulo-coutinho.github.io/pdfium-lib/") f.debug("Published")
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)
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)
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)
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_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")
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_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")