From 2ee28029f945d74d01e63d6efd8802c9df03b28f Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 10 Aug 2018 16:05:07 +0530 Subject: [PATCH] Install meson.exe as the entrypoint on Windows Thanks to Rafael Rivera for the suggestion Fixes https://github.com/mesonbuild/meson/issues/1877 --- mesonbuild/mesonmain.py | 8 +++++--- run_meson_command_tests.py | 26 ++++++++------------------ setup.py | 8 ++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 011ac14b1..68a2ddb2d 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.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)) diff --git a/run_meson_command_tests.py b/run_meson_command_tests.py index cd220de5c..f38b89a19 100755 --- a/run_meson_command_tests.py +++ b/run_meson_command_tests.py @@ -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') diff --git a/setup.py b/setup.py index 8c267a32f..d8a614b2c 100644 --- a/setup.py +++ b/setup.py @@ -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',