mirror of
https://github.com/facebook/proxygen.git
synced 2025-08-05 19:55:47 +03:00
feat(fbcode_builder): Enable python pex
archives to allow native library dependencies
Summary: Fixes integration test failure due to lack of a functioning python-psutil (on Linux, this requires the inclusion of native code which is not permitted in a zipapp). X-link: https://github.com/facebook/sapling/pull/1100 Reviewed By: zzl0 Differential Revision: D77674102 Pulled By: quark-zju fbshipit-source-id: 11ac197d8c4082eaf16e0e28bc1a45c67f7dbb07
This commit is contained in:
committed by
Facebook GitHub Bot
parent
007a0cb3f4
commit
4f0db407cf
@@ -7,6 +7,7 @@ import collections
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zipapp
|
||||
@@ -123,6 +124,36 @@ def populate_install_tree(inst_dir, path_map):
|
||||
pass
|
||||
|
||||
|
||||
def build_pex(args, path_map):
|
||||
"""Create a self executing python binary using the PEX tool
|
||||
|
||||
This type of Python binary is more complex as it requires a third-party tool,
|
||||
but it does support native language extensions (.so/.dll files).
|
||||
"""
|
||||
dest_dir = os.path.dirname(args.output)
|
||||
with tempfile.TemporaryDirectory(prefix="make_fbpy.", dir=dest_dir) as tmpdir:
|
||||
inst_dir = os.path.join(tmpdir, "tree")
|
||||
populate_install_tree(inst_dir, path_map)
|
||||
|
||||
if os.path.exists(os.path.join(inst_dir, "__main__.py")):
|
||||
os.rename(
|
||||
os.path.join(inst_dir, "__main__.py"),
|
||||
os.path.join(inst_dir, "main.py"),
|
||||
)
|
||||
args.main = "main"
|
||||
|
||||
tmp_output = os.path.abspath(os.path.join(tmpdir, "output.exe"))
|
||||
subprocess.check_call(
|
||||
["pex"]
|
||||
+ ["--output-file", tmp_output]
|
||||
+ ["--python", args.python]
|
||||
+ ["--sources-directory", inst_dir]
|
||||
+ ["-e", args.main]
|
||||
)
|
||||
|
||||
os.replace(tmp_output, args.output)
|
||||
|
||||
|
||||
def build_zipapp(args, path_map):
|
||||
"""Create a self executing python binary using Python 3's built-in
|
||||
zipapp module.
|
||||
@@ -262,6 +293,7 @@ def check_main_module(args, path_map):
|
||||
|
||||
|
||||
BUILD_TYPES = {
|
||||
"pex": build_pex,
|
||||
"zipapp": build_zipapp,
|
||||
"dir": build_install_dir,
|
||||
"lib-install": install_library,
|
||||
|
Reference in New Issue
Block a user