Skip to content

Commit

Permalink
Revert "mesonlib: handle meson exe wrappers"
Browse files Browse the repository at this point in the history
This reverts commit 0627e9d.

Breaks installation: mesonbuild#3647

Will be restored once that can be fixed.
  • Loading branch information
nirbheek committed May 31, 2018
1 parent 05f8b1b commit f56b402
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 41 deletions.
9 changes: 7 additions & 2 deletions meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
# limitations under the License.

from mesonbuild import mesonmain
import sys
import sys, os

def main():
# Always resolve the command path so Ninja can find it for regen, tests, etc.
launcher = os.path.realpath(sys.argv[0])
return mesonmain.run(sys.argv[1:], launcher)

if __name__ == '__main__':
sys.exit(mesonmain.main())
sys.exit(main())
48 changes: 47 additions & 1 deletion mesonbuild/mesonlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,58 @@

from glob import glob

def detect_meson_py_location():
c = sys.argv[0]
c_dir, c_fname = os.path.split(c)

# get the absolute path to the <mesontool> folder
m_dir = None
if os.path.isabs(c):
# $ /foo/<mesontool>.py <args>
m_dir = c_dir
elif c_dir == '':
# $ <mesontool> <args> (gets run from /usr/bin/<mesontool>)
in_path_exe = shutil.which(c_fname)
if in_path_exe:
if not os.path.isabs(in_path_exe):
m_dir = os.getcwd()
c_fname = in_path_exe
else:
m_dir, c_fname = os.path.split(in_path_exe)
else:
m_dir = os.path.abspath(c_dir)

# find meson in m_dir
if m_dir is not None:
for fname in ['meson', 'meson.py']:
m_path = os.path.join(m_dir, fname)
if os.path.exists(m_path):
return m_path

# No meson found, which means that either:
# a) meson is not installed
# b) meson is installed to a non-standard location
# c) the script that invoked mesonlib is not the one of meson tools (e.g. run_unittests.py)
fname = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'meson.py'))
if os.path.exists(fname):
return fname
# If meson is still not found, we might be imported by out-of-source tests
# https://github.com/mesonbuild/meson/issues/3015
exe = shutil.which('meson')
if exe is None:
exe = shutil.which('meson.py')
if exe is not None:
return exe
# Give up.
raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.')

if os.path.basename(sys.executable) == 'meson.exe':
# In Windows and using the MSI installed executable.
meson_command = [sys.executable]
python_command = [sys.executable, 'runpython']
else:
python_command = [sys.executable]
meson_command = python_command + ['-m', 'mesonbuild.mesonmain']
meson_command = python_command + [detect_meson_py_location()]

def is_ascii_string(astring):
try:
Expand Down
8 changes: 0 additions & 8 deletions mesonbuild/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,3 @@ def run(original_args, mainfile=None):
mlog.shutdown()

return 0

def main():
# Always resolve the command path so Ninja can find it for regen, tests, etc.
launcher = os.path.realpath(sys.argv[0])
return run(sys.argv[1:], launcher)

if __name__ == '__main__':
sys.exit(main())
2 changes: 0 additions & 2 deletions run_cross_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from run_project_tests import gather_tests, run_tests, StopException, setup_commands
from run_project_tests import failing_logs
from run_tests import setup_pythonpath

def runtests(cross_file):
commontests = [('common', gather_tests(Path('test cases', 'common')), False)]
Expand All @@ -47,6 +46,5 @@ def runtests(cross_file):

if __name__ == '__main__':
setup_commands('ninja')
setup_pythonpath()
cross_file = sys.argv[1]
runtests(cross_file)
13 changes: 9 additions & 4 deletions run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from run_unittests import get_fake_options, run_configure

from run_tests import get_backend_commands, get_backend_args_for_dir, Backend
from run_tests import ensure_backend_detects_changes, setup_pythonpath
from run_tests import ensure_backend_detects_changes


class BuildStep(Enum):
Expand Down Expand Up @@ -88,6 +88,12 @@ def __exit__(self, _type, value, traceback):

system_compiler = None

meson_command = os.path.join(os.getcwd(), 'meson')
if not os.path.exists(meson_command):
meson_command += '.py'
if not os.path.exists(meson_command):
raise RuntimeError('Could not find main Meson script to run.')

class StopException(Exception):
def __init__(self):
super().__init__('Stopped by user')
Expand Down Expand Up @@ -318,7 +324,7 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, compiler, backen
if pass_libdir_to_test(testdir):
gen_args += ['--libdir', 'lib']
gen_args += [testdir, test_build_dir] + flags + test_args + extra_args
(returncode, stdo, stde) = run_configure(mesonlib.meson_command, gen_args)
(returncode, stdo, stde) = run_configure(meson_command, gen_args)
try:
logfile = Path(test_build_dir, 'meson-logs', 'meson-log.txt')
mesonlog = logfile.open(errors='ignore', encoding='utf-8').read()
Expand Down Expand Up @@ -641,7 +647,7 @@ def check_format():
check_file(fullname)

def check_meson_commands_work():
global backend, compile_commands, test_commands, install_commands
global backend, meson_command, compile_commands, test_commands, install_commands
testdir = PurePath('test cases', 'common', '1 trivial').as_posix()
with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir:
print('Checking that configuring works...')
Expand Down Expand Up @@ -686,7 +692,6 @@ def detect_system_compiler():
setup_commands(options.backend)

detect_system_compiler()
setup_pythonpath()
script_dir = os.path.split(__file__)[0]
if script_dir != '':
os.chdir(script_dir)
Expand Down
22 changes: 0 additions & 22 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@
else:
exe_suffix = ''

def setup_pythonpath():
# Make sure python can import mesonbuild, even if we change directories as
# some tests do. Since sys.path is the final product of fairly complex code
# in site.py, it's hard to tell where each entry came from just by looking
# at sys.path, so we don't know if a given entry was set from a relative or
# absolute path. If an entry was set from a relative path, it won't
# continue to work if we change directories. Instead of trying to guess
# where a given entry came from, just add the known-good mesonbuild to
# PYTHONPATH so that it will continue to be importable from other
# directories.
import mesonbuild
meson_dir = os.path.dirname(os.path.abspath(mesonbuild.__file__))
meson_root = os.path.realpath(os.path.join(meson_dir, os.pardir))
try:
python_path = os.environ['PYTHONPATH']
except KeyError:
python_path = meson_root
else:
paths = python_path.split(os.pathsep) + [meson_root]
python_path = os.pathsep.join(paths)
os.environ['PYTHONPATH'] = python_path

def get_backend_args_for_dir(backend, builddir):
'''
Visual Studio backend needs to be given the solution to build
Expand Down
3 changes: 1 addition & 2 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from run_tests import exe_suffix, get_fake_options
from run_tests import get_builddir_target_args, get_backend_commands, Backend
from run_tests import ensure_backend_detects_changes, run_configure, meson_exe
from run_tests import should_run_linux_cross_tests, setup_pythonpath
from run_tests import should_run_linux_cross_tests


def get_dynamic_section_entry(fname, entry):
Expand Down Expand Up @@ -3313,7 +3313,6 @@ def unset_envs():

if __name__ == '__main__':
unset_envs()
setup_pythonpath()
cases = ['InternalTests', 'AllPlatformTests', 'FailureTests', 'PythonTests']
if not is_windows():
cases += ['LinuxlikeTests']
Expand Down

0 comments on commit f56b402

Please sign in to comment.