Enable searching system crossfile locations on more platforms

There's no reason not to also look in these places on Cygwin or OSX.  Don't
do this on Windows, as these paths aren't meaningful there.

Move test_cross_file_system_paths from LinuxlikeTests to AllPlatformTests.
pull/3122/head
Jon Turney 7 years ago committed by Jussi Pakkanen
parent 845dbfcbbc
commit cf98f5e370
  1. 14
      mesonbuild/coredata.py
  2. 91
      run_unittests.py

@ -222,17 +222,17 @@ class CoreData:
(after resolving variables and ~), return that absolute path. Next, (after resolving variables and ~), return that absolute path. Next,
check if the file is relative to the current source dir. If the path check if the file is relative to the current source dir. If the path
still isn't resolved do the following: still isn't resolved do the following:
Linux + BSD: Windows:
- Error
*:
- $XDG_DATA_HOME/meson/cross (or ~/.local/share/meson/cross if - $XDG_DATA_HOME/meson/cross (or ~/.local/share/meson/cross if
undefined) undefined)
- $XDG_DATA_DIRS/meson/cross (or - $XDG_DATA_DIRS/meson/cross (or
/usr/local/share/meson/cross:/usr/share/meson/cross if undefined) /usr/local/share/meson/cross:/usr/share/meson/cross if undefined)
- Error - Error
*:
- Error Non-Windows follows the Linux path and will honor XDG_* if set. This
BSD follows the Linux path and will honor XDG_* if set. This simplifies simplifies the implementation somewhat.
the implementation somewhat, especially since most BSD users wont set
those environment variables.
""" """
if filename is None: if filename is None:
return None return None
@ -242,7 +242,7 @@ class CoreData:
path_to_try = os.path.abspath(filename) path_to_try = os.path.abspath(filename)
if os.path.exists(path_to_try): if os.path.exists(path_to_try):
return path_to_try return path_to_try
if sys.platform == 'linux' or 'bsd' in sys.platform.lower(): if sys.platform != 'win32':
paths = [ paths = [
os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')), os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')),
] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') ] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':')

@ -1749,6 +1749,53 @@ int main(int argc, char **argv) {
self._run(ninja, self._run(ninja,
workdir=os.path.join(tmpdir, 'builddir')) workdir=os.path.join(tmpdir, 'builddir'))
def test_cross_file_system_paths(self):
if is_windows():
raise unittest.SkipTest('system crossfile paths not defined for Windows (yet)')
testdir = os.path.join(self.common_test_dir, '1 trivial')
cross_content = textwrap.dedent("""\
[binaries]
c = '/usr/bin/cc'
ar = '/usr/bin/ar'
strip = '/usr/bin/ar'
[properties]
[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
""")
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
f.write(cross_content)
name = os.path.basename(f.name)
with mock.patch.dict(os.environ, {'XDG_DATA_HOME': d}):
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
with mock.patch.dict(os.environ, {'XDG_DATA_DIRS': d}):
os.environ.pop('XDG_DATA_HOME', None)
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
f.write(cross_content)
name = os.path.basename(f.name)
with mock.patch('mesonbuild.coredata.os.path.expanduser', lambda x: x.replace('~', d)):
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
class FailureTests(BasePlatformTests): class FailureTests(BasePlatformTests):
''' '''
@ -2546,50 +2593,6 @@ endian = 'little'
self.init(testdir, ['-Db_lto=true'], default_args=False) self.init(testdir, ['-Db_lto=true'], default_args=False)
self.build('reconfigure') self.build('reconfigure')
def test_cross_file_system_paths(self):
testdir = os.path.join(self.common_test_dir, '1 trivial')
cross_content = textwrap.dedent("""\
[binaries]
c = '/usr/bin/cc'
ar = '/usr/bin/ar'
strip = '/usr/bin/ar'
[properties]
[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
""")
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
f.write(cross_content)
name = os.path.basename(f.name)
with mock.patch.dict(os.environ, {'XDG_DATA_HOME': d}):
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
with mock.patch.dict(os.environ, {'XDG_DATA_DIRS': d}):
os.environ.pop('XDG_DATA_HOME', None)
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
with tempfile.TemporaryDirectory() as d:
dir_ = os.path.join(d, '.local', 'share', 'meson', 'cross')
os.makedirs(dir_)
with tempfile.NamedTemporaryFile('w', dir=dir_, delete=False) as f:
f.write(cross_content)
name = os.path.basename(f.name)
with mock.patch('mesonbuild.coredata.os.path.expanduser', lambda x: x.replace('~', d)):
self.init(testdir, ['--cross-file=' + name], inprocess=True)
self.wipe()
def test_vala_generated_source_buildir_inside_source_tree(self): def test_vala_generated_source_buildir_inside_source_tree(self):
''' '''
Test that valac outputs generated C files in the expected location when Test that valac outputs generated C files in the expected location when

Loading…
Cancel
Save