From 4e8622df3503df18da5061072dce14fe6967a5d6 Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Fri, 25 Sep 2020 20:23:28 +0000 Subject: [PATCH] djtest: use pyelftools to find uwsgi ld.so Change-Id: I54bdaa588ff15d8c6ca73c4307076a93a5682d78 --- personal/q3k/djtest/BUILD | 2 ++ personal/q3k/djtest/uwsgi-start.py | 18 ++++++++++++++---- third_party/py/requirements.txt | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/personal/q3k/djtest/BUILD b/personal/q3k/djtest/BUILD index d4ab6cc1..8e82b258 100644 --- a/personal/q3k/djtest/BUILD +++ b/personal/q3k/djtest/BUILD @@ -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"), ], ) diff --git a/personal/q3k/djtest/uwsgi-start.py b/personal/q3k/djtest/uwsgi-start.py index eb22d55b..a5c325ed 100644 --- a/personal/q3k/djtest/uwsgi-start.py +++ b/personal/q3k/djtest/uwsgi-start.py @@ -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, ] diff --git a/third_party/py/requirements.txt b/third_party/py/requirements.txt index 875712ef..94765d77 100644 --- a/third_party/py/requirements.txt +++ b/third_party/py/requirements.txt @@ -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