Install meson.exe as the entrypoint on Windows

Thanks to Rafael Rivera for the suggestion

Fixes https://github.com/mesonbuild/meson/issues/1877
pull/4004/head
Nirbheek Chauhan 6 years ago
parent 9f5c84279e
commit 2ee28029f9
  1. 8
      mesonbuild/mesonmain.py
  2. 26
      run_meson_command_tests.py
  3. 8
      setup.py

@ -232,15 +232,17 @@ def run_script_command(args):
return cmdfunc(cmdargs)
def set_meson_command(mainfile):
if mainfile.endswith('.exe'):
# On UNIX-like systems `meson` is a Python script
# On Windows `meson` and `meson.exe` are wrapper exes
if not mainfile.endswith('.py'):
mesonlib.meson_command = [mainfile]
elif os.path.isabs(mainfile) and mainfile.endswith('mesonmain.py'):
# Can't actually run meson with an absolute path to mesonmain.py, it must be run as -m mesonbuild.mesonmain
mesonlib.meson_command = mesonlib.python_command + ['-m', 'mesonbuild.mesonmain']
else:
# Either run uninstalled, or full path to meson-script.py
mesonlib.meson_command = mesonlib.python_command + [mainfile]
# This won't go into the log file because it's not initialized yet, and we
# need this value for unit tests.
# We print this value for unit tests.
if 'MESON_COMMAND_TESTS' in os.environ:
mlog.log('meson_command is {!r}'.format(mesonlib.meson_command))

@ -135,25 +135,15 @@ class CommandTests(unittest.TestCase):
self.assertTrue(bindir.is_dir())
# Run `meson`
os.chdir('/')
if is_windows():
resolved_meson_command = python_command + [str(bindir / 'meson.py')]
else:
resolved_meson_command = python_command + [str(bindir / 'meson')]
# The python configuration on appveyor does not register .py as
# a valid extension, so we cannot run `meson` on Windows.
builddir = str(self.tmpdir / 'build1')
meson_setup = ['meson', 'setup']
meson_command = meson_setup + self.meson_args
stdo = self._run(meson_command + [self.testdir, builddir])
self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
resolved_meson_command = [str(bindir / 'meson')]
builddir = str(self.tmpdir / 'build1')
meson_setup = ['meson', 'setup']
meson_command = meson_setup + self.meson_args
stdo = self._run(meson_command + [self.testdir, builddir])
self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
# Run `/path/to/meson`
builddir = str(self.tmpdir / 'build2')
if is_windows():
# Cannot run .py directly because of the appveyor configuration,
# and the script is named meson.py, not meson
meson_setup = python_command + [str(bindir / 'meson.py'), 'setup']
else:
meson_setup = [str(bindir / 'meson'), 'setup']
meson_setup = [str(bindir / 'meson'), 'setup']
meson_command = meson_setup + self.meson_args
stdo = self._run(meson_command + [self.testdir, builddir])
self.assertMesonCommandIs(stdo.split('\n')[0], resolved_meson_command)
@ -168,7 +158,7 @@ class CommandTests(unittest.TestCase):
# Next part requires a shell
return
# `meson` is a wrapper to `meson.real`
resolved_meson_command = python_command + [str(bindir / 'meson.real')]
resolved_meson_command = [str(bindir / 'meson.real')]
builddir = str(self.tmpdir / 'build4')
(bindir / 'meson').rename(bindir / 'meson.real')
wrapper = (bindir / 'meson')

@ -56,6 +56,13 @@ class install_scripts(orig):
self.copy_file(in_built, outfile)
self.outfiles.append(outfile)
entries = {}
if sys.platform == 'win32':
# This will create Scripts/meson.exe and Scripts/meson-script.py
# Can't use this on all platforms because distutils doesn't support
# entry_points in setup()
entries = {'console_scripts': ['meson=mesonbuild.mesonmain:main']}
setup(name='meson',
version=version,
description='A high performance build system',
@ -73,6 +80,7 @@ setup(name='meson',
'mesonbuild.wrap'],
scripts=['meson.py'],
cmdclass={'install_scripts': install_scripts},
entry_points=entries,
data_files=[('share/man/man1', ['man/meson.1']),
('share/polkit-1/actions', ['data/com.mesonbuild.install.policy'])],
classifiers=['Development Status :: 5 - Production/Stable',

Loading…
Cancel
Save