diff options
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 77dfdaa..620f40f 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -628,7 +628,7 @@ class BuildTarget(Target): self.check_unknown_kwargs(kwargs) self.process_compilers() if not any([self.sources, self.generated, self.objects, self.link_whole]): - raise InvalidArguments('Build target {} has no sources.'.format(name)) + raise InvalidArguments(f'Build target {name} has no sources.') self.process_compilers_late() self.validate_sources() self.validate_install(environment) @@ -639,7 +639,7 @@ class BuildTarget(Target): return repr_str.format(self.__class__.__name__, self.get_id(), self.filename) def __str__(self): - return "{}".format(self.name) + return f"{self.name}" def validate_install(self, environment): if self.for_machine is MachineChoice.BUILD and self.need_install: @@ -668,7 +668,7 @@ class BuildTarget(Target): self.objects.append(s) elif isinstance(s, (GeneratedList, CustomTarget)): msg = 'Generated files are not allowed in the \'objects\' kwarg ' + \ - 'for target {!r}.\nIt is meant only for '.format(self.name) + \ + f'for target {self.name!r}.\nIt is meant only for ' + \ 'pre-built object files that are shipped with the\nsource ' + \ 'tree. Try adding it in the list of sources.' raise InvalidArguments(msg) @@ -808,7 +808,7 @@ class BuildTarget(Target): check_sources = list(self.sources) compiler = self.compilers[lang] if not self.can_compile_remove_sources(compiler, check_sources): - m = 'No {} sources found in target {!r}'.format(lang, self.name) + m = f'No {lang} sources found in target {self.name!r}' raise InvalidArguments(m) if check_sources: m = '{0} targets can only contain {0} files:\n'.format(lang.capitalize()) @@ -885,7 +885,7 @@ class BuildTarget(Target): raise MesonException('Object extraction arguments must be strings or Files.') # FIXME: It could be a generated source if src not in sources_set: - raise MesonException('Tried to extract unknown source {}.'.format(src)) + raise MesonException(f'Tried to extract unknown source {src}.') obj_src.append(src) return ExtractedObjects(self, obj_src) @@ -1035,7 +1035,7 @@ This will become a hard error in a future Meson release.''') assert(isinstance(i, File)) trial = os.path.join(environment.get_source_dir(), i.subdir, i.fname) if not(os.path.isfile(trial)): - raise InvalidArguments('Tried to add non-existing extra file {}.'.format(i)) + raise InvalidArguments(f'Tried to add non-existing extra file {i}.') self.extra_files = extra_files self.install_rpath: str = kwargs.get('install_rpath', '') if not isinstance(self.install_rpath, str): @@ -1049,7 +1049,7 @@ This will become a hard error in a future Meson release.''') raise InvalidArguments('Resource argument is not a string.') trial = os.path.join(environment.get_source_dir(), self.subdir, r) if not os.path.isfile(trial): - raise InvalidArguments('Tried to add non-existing resource {}.'.format(r)) + raise InvalidArguments(f'Tried to add non-existing resource {r}.') self.resources = resources if 'name_prefix' in kwargs: name_prefix = kwargs['name_prefix'] @@ -1104,7 +1104,7 @@ This will become a hard error in a future Meson release.''') def validate_win_subsystem(self, value: str) -> str: value = value.lower() if re.fullmatch(r'(boot_application|console|efi_application|efi_boot_service_driver|efi_rom|efi_runtime_driver|native|posix|windows)(,\d+(\.\d+)?)?', value) is None: - raise InvalidArguments('Invalid value for win_subsystem: {}.'.format(value)) + raise InvalidArguments(f'Invalid value for win_subsystem: {value}.') return value def _extract_pic_pie(self, kwargs, arg: str, environment, option: str): @@ -1123,7 +1123,7 @@ This will become a hard error in a future Meson release.''') val = False if not isinstance(val, bool): - raise InvalidArguments('Argument {} to {!r} must be boolean'.format(arg, self.name)) + raise InvalidArguments(f'Argument {arg} to {self.name!r} must be boolean') return val def get_filename(self): @@ -1238,15 +1238,15 @@ You probably should put it in link_with instead.''') # internal/convenience library, promote to link_whole. return self.link_whole(t) if not isinstance(t, (Target, CustomTargetIndex)): - raise InvalidArguments('{!r} is not a target.'.format(t)) + raise InvalidArguments(f'{t!r} is not a target.') if not t.is_linkable_target(): - raise InvalidArguments("Link target '{!s}' is not linkable.".format(t)) + raise InvalidArguments(f"Link target '{t!s}' is not linkable.") if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic: - msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) + msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. " msg += "Use the 'pic' option to static_library to build with PIC." raise InvalidArguments(msg) if self.for_machine is not t.for_machine: - msg = 'Tried to mix libraries for machines {} and {} in target {!r}'.format(self.for_machine, t.for_machine, self.name) + msg = f'Tried to mix libraries for machines {self.for_machine} and {t.for_machine} in target {self.name!r}' if self.environment.is_cross_build(): raise InvalidArguments(msg + ' This is not possible in a cross build.') else: @@ -1257,20 +1257,20 @@ You probably should put it in link_with instead.''') for t in unholder(listify(target)): if isinstance(t, (CustomTarget, CustomTargetIndex)): if not t.is_linkable_target(): - raise InvalidArguments('Custom target {!r} is not linkable.'.format(t)) + raise InvalidArguments(f'Custom target {t!r} is not linkable.') if not t.get_filename().endswith('.a'): raise InvalidArguments('Can only link_whole custom targets that are .a archives.') if isinstance(self, StaticLibrary): # FIXME: We could extract the .a archive to get object files raise InvalidArguments('Cannot link_whole a custom target into a static library') elif not isinstance(t, StaticLibrary): - raise InvalidArguments('{!r} is not a static library.'.format(t)) + raise InvalidArguments(f'{t!r} is not a static library.') elif isinstance(self, SharedLibrary) and not t.pic: - msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) + msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. " msg += "Use the 'pic' option to static_library to build with PIC." raise InvalidArguments(msg) if self.for_machine is not t.for_machine: - msg = 'Tried to mix libraries for machines {1} and {2} in target {0!r}'.format(self.name, self.for_machine, t.for_machine) + msg = f'Tried to mix libraries for machines {self.for_machine} and {t.for_machine} in target {self.name!r}' if self.environment.is_cross_build(): raise InvalidArguments(msg + ' This is not possible in a cross build.') else: @@ -1315,7 +1315,7 @@ You probably should put it in link_with instead.''') if not isinstance(f, str): raise MesonException('PCH arguments must be strings.') if not os.path.isfile(os.path.join(self.environment.source_dir, self.subdir, f)): - raise MesonException('File {} does not exist.'.format(f)) + raise MesonException(f'File {f} does not exist.') self.pch[language] = pchlist def add_include_dirs(self, args, set_is_system: T.Optional[str] = None): @@ -1387,7 +1387,7 @@ You probably should put it in link_with instead.''') 'Requires a compiler for language "{}", but that is not ' 'a project language.'.format(self.name, l)) return prelinker - raise MesonException('Could not determine prelinker for {!r}.'.format(self.name)) + raise MesonException(f'Could not determine prelinker for {self.name!r}.') def get_clink_dynamic_linker_and_stdlibs(self): ''' @@ -1587,7 +1587,7 @@ class Generator: elif isinstance(e, str): fs = [File.from_source_file(state.environment.source_dir, state.subdir, e)] elif not isinstance(e, File): - raise InvalidArguments('{} arguments must be strings, files or CustomTargets, not {!r}.'.format(name, e)) + raise InvalidArguments(f'{name} arguments must be strings, files or CustomTargets, not {e!r}.') for f in fs: if preserve_path_from: @@ -1597,7 +1597,7 @@ class Generator: output.add_file(f, state) if new: FeatureNew.single_use( - 'Calling "{}" with CustomTaget or Index of CustomTarget.'.format(name), + f'Calling "{name}" with CustomTaget or Index of CustomTarget.', '0.57.0', state.subproject) return output @@ -1723,8 +1723,8 @@ class Executable(BuildTarget): if not isinstance(kwargs.get('implib', False), bool): implib_basename = kwargs['implib'] if m.is_windows() or m.is_cygwin(): - self.vs_import_filename = '{}.lib'.format(implib_basename) - self.gcc_import_filename = 'lib{}.a'.format(implib_basename) + self.vs_import_filename = f'{implib_basename}.lib' + self.gcc_import_filename = f'lib{implib_basename}.a' if self.get_using_msvc(): self.import_filename = self.vs_import_filename else: @@ -1787,7 +1787,7 @@ class StaticLibrary(BuildTarget): self.rust_crate_type = 'rlib' # Don't let configuration proceed with a non-static crate type elif self.rust_crate_type not in ['rlib', 'staticlib']: - raise InvalidArguments('Crate type "{}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.rust_crate_type)) + raise InvalidArguments(f'Crate type "{self.rust_crate_type}" invalid for static libraries; must be "rlib" or "staticlib"') # By default a static library is named libfoo.a even on Windows because # MSVC does not have a consistent convention for what static libraries # are called. The MSVC CRT uses libfoo.lib syntax but nothing else uses @@ -1828,7 +1828,7 @@ class StaticLibrary(BuildTarget): if isinstance(rust_crate_type, str): self.rust_crate_type = rust_crate_type else: - raise InvalidArguments('Invalid rust_crate_type "{}": must be a string.'.format(rust_crate_type)) + raise InvalidArguments(f'Invalid rust_crate_type "{rust_crate_type}": must be a string.') def is_linkable_target(self): return True @@ -1859,7 +1859,7 @@ class SharedLibrary(BuildTarget): self.rust_crate_type = 'dylib' # Don't let configuration proceed with a non-dynamic crate type elif self.rust_crate_type not in ['dylib', 'cdylib']: - raise InvalidArguments('Crate type "{}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.rust_crate_type)) + raise InvalidArguments(f'Crate type "{self.rust_crate_type}" invalid for dynamic libraries; must be "dylib" or "cdylib"') if not hasattr(self, 'prefix'): self.prefix = None if not hasattr(self, 'suffix'): @@ -1925,7 +1925,7 @@ class SharedLibrary(BuildTarget): # Shared library is of the form foo.dll prefix = '' # Import library is called foo.dll.lib - self.import_filename = '{}.dll.lib'.format(self.name) + self.import_filename = f'{self.name}.dll.lib' create_debug_file = True elif self.get_using_msvc(): # Shared library is of the form foo.dll @@ -2045,7 +2045,7 @@ class SharedLibrary(BuildTarget): if not isinstance(self.ltversion, str): raise InvalidArguments('Shared library version needs to be a string, not ' + type(self.ltversion).__name__) if not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', self.ltversion): - raise InvalidArguments('Invalid Shared library version "{}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.'.format(self.ltversion)) + raise InvalidArguments(f'Invalid Shared library version "{self.ltversion}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.') # Try to extract/deduce the soversion if 'soversion' in kwargs: self.soversion = kwargs['soversion'] @@ -2092,7 +2092,7 @@ class SharedLibrary(BuildTarget): if isinstance(rust_crate_type, str): self.rust_crate_type = rust_crate_type else: - raise InvalidArguments('Invalid rust_crate_type "{}": must be a string.'.format(rust_crate_type)) + raise InvalidArguments(f'Invalid rust_crate_type "{rust_crate_type}": must be a string.') def get_import_filename(self): """ @@ -2195,7 +2195,7 @@ class CommandBase: elif isinstance(c, list): final_cmd += self.flatten_command(c) else: - raise InvalidArguments('Argument {!r} in "command" is invalid'.format(c)) + raise InvalidArguments(f'Argument {c!r} in "command" is invalid') return final_cmd class CustomTarget(Target, CommandBase): @@ -2287,7 +2287,7 @@ class CustomTarget(Target, CommandBase): if i.strip() == '': raise InvalidArguments('Output must not consist only of whitespace.') if has_path_sep(i): - raise InvalidArguments('Output {!r} must not contain a path segment.'.format(i)) + raise InvalidArguments(f'Output {i!r} must not contain a path segment.') if '@INPUT@' in i or '@INPUT0@' in i: m = 'Output cannot contain @INPUT@ or @INPUT0@, did you ' \ 'mean @PLAINNAME@ or @BASENAME@?' @@ -2507,10 +2507,10 @@ class Jar(BuildTarget): super().__init__(name, subdir, subproject, for_machine, sources, objects, environment, kwargs) for s in self.sources: if not s.endswith('.java'): - raise InvalidArguments('Jar source {} is not a java file.'.format(s)) + raise InvalidArguments(f'Jar source {s} is not a java file.') for t in self.link_targets: if not isinstance(t, Jar): - raise InvalidArguments('Link target {} is not a jar target.'.format(t)) + raise InvalidArguments(f'Link target {t} is not a jar target.') self.filename = self.name + '.jar' self.outputs = [self.filename] self.java_args = kwargs.get('java_args', []) @@ -2675,13 +2675,13 @@ def get_sources_string_names(sources, backend): elif isinstance(s, File): names.append(s.fname) else: - raise AssertionError('Unknown source type: {!r}'.format(s)) + raise AssertionError(f'Unknown source type: {s!r}') return names def load(build_dir: str) -> Build: filename = os.path.join(build_dir, 'meson-private', 'build.dat') - load_fail_msg = 'Build data file {!r} is corrupted. Try with a fresh build tree.'.format(filename) - nonexisting_fail_msg = 'No such build data file as "{!r}".'.format(filename) + load_fail_msg = f'Build data file {filename!r} is corrupted. Try with a fresh build tree.' + nonexisting_fail_msg = f'No such build data file as "{filename!r}".' try: with open(filename, 'rb') as f: obj = pickle.load(f) |