diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-06 14:35:25 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-08-23 11:33:39 -0400 |
commit | 18b96cd0692255b30f8f0597cbf4af89d142a93d (patch) | |
tree | b2edf3ee61fb7b1fef7f0e697c7288923f434a51 /mesonbuild/coredata.py | |
parent | bde690b06e930020a0ec6ccaea7a76babf77dff5 (diff) | |
download | meson-18b96cd0692255b30f8f0597cbf4af89d142a93d.zip meson-18b96cd0692255b30f8f0597cbf4af89d142a93d.tar.gz meson-18b96cd0692255b30f8f0597cbf4af89d142a93d.tar.bz2 |
machine file: Add @GLOBAL_SOURCE_ROOT@ and @DIRNAME@
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r-- | mesonbuild/coredata.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index bb84f72..d59d9b8 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -964,15 +964,20 @@ class CmdLineFileParser(configparser.ConfigParser): return optionstr class MachineFileParser(): - def __init__(self, filenames: T.List[str]) -> None: + def __init__(self, filenames: T.List[str], sourcedir: str) -> None: self.parser = CmdLineFileParser() self.constants: T.Dict[str, T.Union[str, bool, int, T.List[str]]] = {'True': True, 'False': False} self.sections: T.Dict[str, T.Dict[str, T.Union[str, bool, int, T.List[str]]]] = {} - try: - self.parser.read(filenames) - except configparser.Error as e: - raise EnvironmentException(f'Malformed cross or native file: {e}') + for fname in filenames: + with open(fname, encoding='utf-8') as f: + content = f.read() + content = content.replace('@GLOBAL_SOURCE_ROOT@', sourcedir) + content = content.replace('@DIRNAME@', os.path.dirname(fname)) + try: + self.parser.read_string(content, fname) + except configparser.Error as e: + raise EnvironmentException(f'Malformed machine file: {e}') # Parse [constants] first so they can be used in other sections if self.parser.has_section('constants'): @@ -1028,8 +1033,8 @@ class MachineFileParser(): return os.path.join(l, r) raise EnvironmentException('Unsupported node type') -def parse_machine_files(filenames: T.List[str]): - parser = MachineFileParser(filenames) +def parse_machine_files(filenames: T.List[str], sourcedir: str): + parser = MachineFileParser(filenames, sourcedir) return parser.sections def get_cmd_line_file(build_dir: str) -> str: |