diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-04-21 13:10:02 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-04-21 23:10:02 +0300 |
commit | 3edc7f343b938b9040c53004407f47f58fc15fcb (patch) | |
tree | baa304e972aba33fb7135b223bc9c5e31a2cf911 /mesonbuild | |
parent | bffd28d4b22b685b2fcf5a5b5983e3f9c69102e7 (diff) | |
download | meson-3edc7f343b938b9040c53004407f47f58fc15fcb.zip meson-3edc7f343b938b9040c53004407f47f58fc15fcb.tar.gz meson-3edc7f343b938b9040c53004407f47f58fc15fcb.tar.bz2 |
coredata: store cross/native files in the same form they will be used (#5224)
* coredata: store cross/native files in the same form they will be used
Currently they're forced to absolute paths when they're stored in the
coredata datastructure, then when they're loaded we de-absolute path
them to check if they're in the system wide directories. This doesn't
work at all, since the ninja backend will generat a dependency on a
file that is in the source directory unless the path was already given
as absolute. This results in builds being retriggereed forever due to
a non-existant file.
The right way to do this is to figure out whether the file is in the
build directory, is absolute, or is in one of the system paths at
creation time, and store that path as absolute. Then the code that
reads the file and the code that generates the dependencies in the
ninja backend just takes the computed list and there is no mismatch
between them.
Fixes #5257
* run_unittests: Add a test for correct native file storage
This tests the bug in #5257
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/coredata.py | 59 | ||||
-rw-r--r-- | mesonbuild/environment.py | 4 |
2 files changed, 30 insertions, 33 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 51b36f0..9281019 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -26,7 +26,7 @@ from .wrap import WrapMode import ast import argparse import configparser -from typing import Optional, Any, TypeVar, Generic, Type +from typing import Optional, Any, TypeVar, Generic, Type, List version = '0.50.999' backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'vs2019', 'xcode'] @@ -212,32 +212,10 @@ class UserFeatureOption(UserComboOption): return self.value == 'auto' -def load_configs(filenames, subdir): +def load_configs(filenames: List[str]) -> configparser.ConfigParser: """Load configuration files from a named subdirectory.""" - def gen(): - for f in filenames: - f = os.path.expanduser(os.path.expandvars(f)) - if os.path.exists(f): - yield f - continue - elif sys.platform != 'win32': - f = os.path.basename(f) - paths = [ - os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')), - ] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') - for path in paths: - path_to_try = os.path.join(path, 'meson', subdir, f) - if os.path.isfile(path_to_try): - yield path_to_try - break - else: - raise MesonException('Cannot find specified native file: ' + f) - continue - - raise MesonException('Cannot find specified native file: ' + f) - config = configparser.ConfigParser() - config.read(gen()) + config.read(filenames) return config @@ -265,23 +243,42 @@ class CoreData: self.user_options = {} self.compiler_options = PerMachine({}, {}, {}) self.base_options = {} - self.cross_files = self.__load_config_files(options.cross_file) + self.cross_files = self.__load_config_files(options.cross_file, 'cross') self.compilers = OrderedDict() self.cross_compilers = OrderedDict() self.deps = OrderedDict() # Only to print a warning if it changes between Meson invocations. - self.config_files = self.__load_config_files(options.native_file) + self.config_files = self.__load_config_files(options.native_file, 'native') self.libdir_cross_fixup() @staticmethod - def __load_config_files(filenames): + def __load_config_files(filenames: Optional[List[str]], ftype: str) -> List[str]: # Need to try and make the passed filenames absolute because when the # files are parsed later we'll have chdir()d. if not filenames: return [] - filenames = [os.path.abspath(os.path.expanduser(os.path.expanduser(f))) - for f in filenames] - return filenames + + real = [] + for f in filenames: + f = os.path.expanduser(os.path.expandvars(f)) + if os.path.exists(f): + real.append(os.path.abspath(f)) + continue + elif sys.platform != 'win32': + paths = [ + os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')), + ] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') + for path in paths: + path_to_try = os.path.join(path, 'meson', ftype, f) + if os.path.isfile(path_to_try): + real.append(path_to_try) + break + else: + raise MesonException('Cannot find specified {} file: {}'.format(ftype, f)) + continue + + raise MesonException('Cannot find specified {} file: {}'.format(ftype, f)) + return real def libdir_cross_fixup(self): # By default set libdir to "lib" when cross compiling since diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index f85decd..c6e9a0c 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -422,13 +422,13 @@ class Environment: if self.coredata.config_files is not None: config = MesonConfigFile.from_config_parser( - coredata.load_configs(self.coredata.config_files, 'native')) + coredata.load_configs(self.coredata.config_files)) self.binaries.build = BinaryTable(config.get('binaries', {})) self.paths.build = Directories(**config.get('paths', {})) if self.coredata.cross_files: config = MesonConfigFile.from_config_parser( - coredata.load_configs(self.coredata.cross_files, 'cross')) + coredata.load_configs(self.coredata.cross_files)) self.properties.host = Properties(config.get('properties', {}), False) self.binaries.host = BinaryTable(config.get('binaries', {}), False) if 'host_machine' in config: |