Merge pull request #4004 from mesonbuild/nirbheek/console-entrypoint

Install meson.exe as the entrypoint on Windows
This commit is contained in:
Jussi Pakkanen 2018-08-12 00:44:10 +03:00 committed by GitHub
commit f335c8bdeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 89 deletions

View File

@ -99,7 +99,7 @@ install:
- cmd: if %compiler%==msys2-mingw ( set "PATH=C:\msys64\mingw%PACMAN_BITS%\bin;%PATH%" )
- cmd: if %compiler%==msys2-mingw ( set "MESON_PYTHON_PATH=C:\msys64\mingw%PACMAN_BITS%\bin" )
- cmd: if %compiler%==msys2-mingw ( set "PYTHON=python3" )
- cmd: if %compiler%==msys2-mingw ( C:\msys64\usr\bin\pacman -S --needed --noconfirm "mingw%PACMAN_BITS%/mingw-w64-%PACMAN_ARCH%-python3" )
- cmd: if %compiler%==msys2-mingw ( C:\msys64\usr\bin\pacman -S --needed --noconfirm "mingw%PACMAN_BITS%/mingw-w64-%PACMAN_ARCH%-python3" "mingw%PACMAN_BITS%/mingw-w64-%PACMAN_ARCH%-python3-setuptools" )
# Cygwin
- cmd: if not %compiler%==cygwin ( set "PATH=%cd%;%MESON_PYTHON_PATH%;%PATH%;" )
- cmd: if %compiler%==cygwin ( set WRAPPER=ci\run-in-cygwin.bat )

View File

@ -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))

View File

@ -131,16 +131,25 @@ class CommandTests(unittest.TestCase):
os.environ['PYTHONPATH'] = str(pylibdir)
os.environ['PATH'] = str(bindir) + os.pathsep + os.environ['PATH']
self._run(python_command + ['setup.py', 'install', '--prefix', str(prefix)])
self.assertTrue(pylibdir.is_dir())
# Check that all the files were installed correctly
self.assertTrue(bindir.is_dir())
self.assertTrue(pylibdir.is_dir())
from setup import packages
# Extract list of expected python module files
expect = set()
for pkg in packages:
expect.update([p.as_posix() for p in Path(pkg.replace('.', '/')).glob('*.py')])
# Check what was installed, only count files that are inside 'mesonbuild'
have = set()
for p in Path(pylibdir).glob('**/*.py'):
s = p.as_posix()
if 'mesonbuild' not in s:
continue
have.add(s[s.rfind('mesonbuild'):])
self.assertEqual(have, expect)
# 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.
resolved_meson_command = [str(bindir / 'meson')]
builddir = str(self.tmpdir / 'build1')
meson_setup = ['meson', 'setup']
meson_command = meson_setup + self.meson_args
@ -148,11 +157,6 @@ class CommandTests(unittest.TestCase):
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_command = meson_setup + self.meson_args
stdo = self._run(meson_command + [self.testdir, builddir])
@ -168,7 +172,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')

View File

@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from mesonbuild.coredata import version
@ -24,38 +23,25 @@ if sys.version_info < (3, 5, 0):
'Meson requires Python 3.5.0 or greater')
sys.exit(1)
# We need to support Python installations that have nothing but the basic
# Python installation. Use setuptools when possible and fall back to
# plain distutils when setuptools is not available.
try:
from setuptools import setup
from setuptools.command.install_scripts import install_scripts as orig
except ImportError:
from distutils.core import setup
from distutils.command.install_scripts import install_scripts as orig
class install_scripts(orig):
def run(self):
if sys.platform == 'win32':
super().run()
return
if not self.skip_build:
self.run_command('build_scripts')
self.outfiles = []
if not self.dry_run:
self.mkpath(self.install_dir)
# We want the files to be installed without a suffix on Unix
for infile in self.get_inputs():
infile = os.path.basename(infile)
in_built = os.path.join(self.build_dir, infile)
in_stripped = infile[:-3] if infile.endswith('.py') else infile
outfile = os.path.join(self.install_dir, in_stripped)
# NOTE: Mode is preserved by default
self.copy_file(in_built, outfile)
self.outfiles.append(outfile)
# On windows, will create Scripts/meson.exe and Scripts/meson-script.py
# Other platforms will create bin/meson
entries = {'console_scripts': ['meson=mesonbuild.mesonmain:main']}
packages = ['mesonbuild',
'mesonbuild.backend',
'mesonbuild.compilers',
'mesonbuild.dependencies',
'mesonbuild.modules',
'mesonbuild.scripts',
'mesonbuild.wrap']
data_files = []
if sys.platform != 'win32':
# Only useful on UNIX-like systems
data_files = [('share/man/man1', ['man/meson.1']),
('share/polkit-1/actions', ['data/com.mesonbuild.install.policy'])]
if __name__ == '__main__':
setup(name='meson',
version=version,
description='A high performance build system',
@ -64,17 +50,9 @@ setup(name='meson',
url='http://mesonbuild.com',
license=' Apache License, Version 2.0',
python_requires='>=3.5',
packages=['mesonbuild',
'mesonbuild.backend',
'mesonbuild.compilers',
'mesonbuild.dependencies',
'mesonbuild.modules',
'mesonbuild.scripts',
'mesonbuild.wrap'],
scripts=['meson.py'],
cmdclass={'install_scripts': install_scripts},
data_files=[('share/man/man1', ['man/meson.1']),
('share/polkit-1/actions', ['data/com.mesonbuild.install.policy'])],
packages=packages,
entry_points=entries,
data_files=data_files,
classifiers=['Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',