1
0
Fork 0

djtest: use pyelftools to find uwsgi ld.so

Change-Id: I54bdaa588ff15d8c6ca73c4307076a93a5682d78
master
q3k 2020-09-25 20:23:28 +00:00
parent 0dd5195766
commit 4e8622df35
3 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,7 @@ py_library(
srcs = glob(["djtest/**/*.py"]),
deps = [
requirement("django"),
requirement("pytz"),
requirement("sqlparse"),
],
)
@ -24,5 +25,6 @@ py_binary(
":app",
"@bazel_tools//tools/python/runfiles",
requirement("uwsgi"),
requirement("pyelftools"),
],
)

View File

@ -6,13 +6,24 @@ import tempfile
import bazel_tools
import bazel_tools.tools.python
from elftools.elf.elffile import ELFFile
from elftools.elf.segments import InterpSegment
from bazel_tools.tools.python.runfiles import runfiles
r = runfiles.Create()
uwsgi = r.Rlocation("pydeps_pypi__uWSGI_2_0_18/uWSGI-2.0.18.data/scripts/uwsgi")
print(uwsgi)
settings = r.Rlocation("hscloud/personal/q3k/djtest/djtest/settings.py")
print(settings)
# uwsgi from runfiles is non-chmodded, we have to run it through its interpreter
ld = None
with open(uwsgi, 'rb') as f:
elffile = ELFFile(f)
for segment in elffile.iter_segments():
if isinstance(segment, InterpSegment):
ld = segment.get_interp_name()
if ld is None:
raise Exception("could not find interpreter/ld.so path in uwsgi - failing")
apppath = os.path.dirname(settings)
sitepath = os.path.dirname(apppath)
@ -35,8 +46,7 @@ config.write(cfgf)
cfgf.close()
args = [
# uwsgi from runfiles is non-chmodded, run through interpreter
'/lib64/ld-linux-x86-64.so.2',
ld,
uwsgi,
'--ini', cfgf.name,
]

View File

@ -33,6 +33,7 @@ psycopg2==2.8.5
pyasn1==0.4.5
pycparser==2.19
PyNaCl==1.3.0
pyelftools==0.26
python-dateutil==2.8.0
pytz==2019.1
requests==2.22.0