rm python2 %s from backends.py and ninjabackend.py

pull/7074/head
Michael Brockus 5 years ago committed by GitHub
parent b75dcd05c5
commit 3ac437cecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      mesonbuild/backend/backends.py
  2. 61
      mesonbuild/backend/ninjabackend.py

@ -196,7 +196,7 @@ class Backend:
return os.path.join(self.get_target_dir(target), target.get_filename()) return os.path.join(self.get_target_dir(target), target.get_filename())
elif isinstance(target, (build.CustomTarget, build.CustomTargetIndex)): elif isinstance(target, (build.CustomTarget, build.CustomTargetIndex)):
if not target.is_linkable_target(): if not target.is_linkable_target():
raise MesonException('Tried to link against custom target "%s", which is not linkable.' % target.name) raise MesonException('Tried to link against custom target "{}", which is not linkable.'.format(target.name))
return os.path.join(self.get_target_dir(target), target.get_filename()) return os.path.join(self.get_target_dir(target), target.get_filename())
elif isinstance(target, build.Executable): elif isinstance(target, build.Executable):
if target.import_filename: if target.import_filename:
@ -282,7 +282,7 @@ class Backend:
ofile = init_language_file(comp.get_default_suffix(), unity_file_number) ofile = init_language_file(comp.get_default_suffix(), unity_file_number)
unity_file_number += 1 unity_file_number += 1
files_in_current = 0 files_in_current = 0
ofile.write('#include<%s>\n' % src) ofile.write('#include<{}>\n'.format(src))
files_in_current += 1 files_in_current += 1
if ofile: if ofile:
ofile.close() ofile.close()
@ -537,14 +537,14 @@ class Backend:
def create_msvc_pch_implementation(self, target, lang, pch_header): def create_msvc_pch_implementation(self, target, lang, pch_header):
# We have to include the language in the file name, otherwise # We have to include the language in the file name, otherwise
# pch.c and pch.cpp will both end up as pch.obj in VS backends. # pch.c and pch.cpp will both end up as pch.obj in VS backends.
impl_name = 'meson_pch-%s.%s' % (lang, lang) impl_name = 'meson_pch-{}.{}'.format(lang, lang)
pch_rel_to_build = os.path.join(self.get_target_private_dir(target), impl_name) pch_rel_to_build = os.path.join(self.get_target_private_dir(target), impl_name)
# Make sure to prepend the build dir, since the working directory is # Make sure to prepend the build dir, since the working directory is
# not defined. Otherwise, we might create the file in the wrong path. # not defined. Otherwise, we might create the file in the wrong path.
pch_file = os.path.join(self.build_dir, pch_rel_to_build) pch_file = os.path.join(self.build_dir, pch_rel_to_build)
os.makedirs(os.path.dirname(pch_file), exist_ok=True) os.makedirs(os.path.dirname(pch_file), exist_ok=True)
content = '#include "%s"' % os.path.basename(pch_header) content = '#include "{}"'.format(os.path.basename(pch_header))
pch_file_tmp = pch_file + '.tmp' pch_file_tmp = pch_file + '.tmp'
with open(pch_file_tmp, 'w') as f: with open(pch_file_tmp, 'w') as f:
f.write(content) f.write(content)
@ -664,7 +664,7 @@ class Backend:
args = [] args = []
for d in deps: for d in deps:
if not (d.is_linkable_target()): if not (d.is_linkable_target()):
raise RuntimeError('Tried to link with a non-library target "%s".' % d.get_basename()) raise RuntimeError('Tried to link with a non-library target "{}".'.format(d.get_basename()))
arg = self.get_target_filename_for_linking(d) arg = self.get_target_filename_for_linking(d)
if not arg: if not arg:
continue continue
@ -853,7 +853,7 @@ class Backend:
m = regex.search(arg) m = regex.search(arg)
while m is not None: while m is not None:
index = int(m.group(1)) index = int(m.group(1))
src = '@OUTPUT%d@' % index src = '@OUTPUT{}@'.format(index)
arg = arg.replace(src, os.path.join(private_dir, output_list[index])) arg = arg.replace(src, os.path.join(private_dir, output_list[index]))
m = regex.search(arg) m = regex.search(arg)
newargs.append(arg) newargs.append(arg)

@ -67,9 +67,9 @@ def ninja_quote(text, is_build_line=False):
if '\n' in text: if '\n' in text:
errmsg = '''Ninja does not support newlines in rules. The content was: errmsg = '''Ninja does not support newlines in rules. The content was:
%s {}
Please report this error with a test case to the Meson bug tracker.''' % text Please report this error with a test case to the Meson bug tracker.'''.format(text)
raise MesonException(errmsg) raise MesonException(errmsg)
return text return text
@ -101,18 +101,18 @@ class NinjaRule:
if not self.refcount: if not self.refcount:
return return
outfile.write('rule %s\n' % self.name) outfile.write('rule {}\n'.format(self.name))
if self.rspable: if self.rspable:
outfile.write(' command = %s @$out.rsp\n' % ' '.join(self.command)) outfile.write(' command = {} @$out.rsp\n'.format(' '.join(self.command)))
outfile.write(' rspfile = $out.rsp\n') outfile.write(' rspfile = $out.rsp\n')
outfile.write(' rspfile_content = %s\n' % ' '.join(self.args)) outfile.write(' rspfile_content = {}\n'.format(' '.join(self.args)))
else: else:
outfile.write(' command = %s\n' % ' '.join(self.command + self.args)) outfile.write(' command = {}\n'.format(' '.join(self.command + self.args)))
if self.deps: if self.deps:
outfile.write(' deps = %s\n' % self.deps) outfile.write(' deps = {}\n'.format(self.deps))
if self.depfile: if self.depfile:
outfile.write(' depfile = %s\n' % self.depfile) outfile.write(' depfile = {}\n'.format(self.depfile))
outfile.write(' description = %s\n' % self.description) outfile.write(' description = {}\n'.format(self.description))
if self.extra: if self.extra:
for l in self.extra.split('\n'): for l in self.extra.split('\n'):
outfile.write(' ') outfile.write(' ')
@ -185,7 +185,7 @@ class NinjaBuildElement:
for e in self.elems: for e in self.elems:
(name, elems) = e (name, elems) = e
should_quote = name not in raw_names should_quote = name not in raw_names
line = ' %s = ' % name line = ' {} = '.format(name)
newelems = [] newelems = []
for i in elems: for i in elems:
if not should_quote or i == '&&': # Hackety hack hack if not should_quote or i == '&&': # Hackety hack hack
@ -204,7 +204,7 @@ class NinjaBuildElement:
def check_outputs(self): def check_outputs(self):
for n in self.outfilenames: for n in self.outfilenames:
if n in self.all_outputs: if n in self.all_outputs:
raise MesonException('Multiple producers for Ninja target "%s". Please rename your targets.' % n) raise MesonException('Multiple producers for Ninja target "{}". Please rename your targets.'.format(n))
self.all_outputs[n] = True self.all_outputs[n] = True
class NinjaBackend(backends.Backend): class NinjaBackend(backends.Backend):
@ -299,8 +299,7 @@ int dummy;
outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename) outfilename = os.path.join(self.environment.get_build_dir(), self.ninja_filename)
tempfilename = outfilename + '~' tempfilename = outfilename + '~'
with open(tempfilename, 'w', encoding='utf-8') as outfile: with open(tempfilename, 'w', encoding='utf-8') as outfile:
outfile.write('# This is the build file for project "%s"\n' % outfile.write('# This is the build file for project "{}"\n'.format(self.build.get_project()))
self.build.get_project())
outfile.write('# It is autogenerated by the Meson build system.\n') outfile.write('# It is autogenerated by the Meson build system.\n')
outfile.write('# Do not edit by hand.\n\n') outfile.write('# Do not edit by hand.\n\n')
outfile.write('ninja_required_version = 1.7.1\n\n') outfile.write('ninja_required_version = 1.7.1\n\n')
@ -308,9 +307,9 @@ int dummy;
num_pools = self.environment.coredata.backend_options['backend_max_links'].value num_pools = self.environment.coredata.backend_options['backend_max_links'].value
if num_pools > 0: if num_pools > 0:
outfile.write('''pool link_pool outfile.write('''pool link_pool
depth = %d depth = {}
''' % num_pools) '''.format(num_pools))
with self.detect_vs_dep_prefix(tempfilename) as outfile: with self.detect_vs_dep_prefix(tempfilename) as outfile:
self.generate_rules() self.generate_rules()
@ -765,7 +764,7 @@ int dummy;
target_name = 'meson-{}'.format(self.build_run_target_name(target)) target_name = 'meson-{}'.format(self.build_run_target_name(target))
elem = NinjaBuildElement(self.all_outputs, target_name, 'CUSTOM_COMMAND', []) elem = NinjaBuildElement(self.all_outputs, target_name, 'CUSTOM_COMMAND', [])
elem.add_item('COMMAND', cmd) elem.add_item('COMMAND', cmd)
elem.add_item('description', 'Running external command %s' % target.name) elem.add_item('description', 'Running external command {}'.format(target.name))
elem.add_item('pool', 'console') elem.add_item('pool', 'console')
# Alias that runs the target defined above with the name the user specified # Alias that runs the target defined above with the name the user specified
self.create_target_alias(target_name) self.create_target_alias(target_name)
@ -980,12 +979,12 @@ int dummy;
ofilename = os.path.join(self.get_target_private_dir(target), ofilebase) ofilename = os.path.join(self.get_target_private_dir(target), ofilebase)
elem = NinjaBuildElement(self.all_outputs, ofilename, "CUSTOM_COMMAND", rel_sourcefile) elem = NinjaBuildElement(self.all_outputs, ofilename, "CUSTOM_COMMAND", rel_sourcefile)
elem.add_item('COMMAND', ['resgen', rel_sourcefile, ofilename]) elem.add_item('COMMAND', ['resgen', rel_sourcefile, ofilename])
elem.add_item('DESC', 'Compiling resource %s' % rel_sourcefile) elem.add_item('DESC', 'Compiling resource {}'.format(rel_sourcefile))
self.add_build(elem) self.add_build(elem)
deps.append(ofilename) deps.append(ofilename)
a = '-resource:' + ofilename a = '-resource:' + ofilename
else: else:
raise InvalidArguments('Unknown resource file %s.' % r) raise InvalidArguments('Unknown resource file {}.'.format(r))
args.append(a) args.append(a)
return args, deps return args, deps
@ -1278,7 +1277,7 @@ int dummy;
main_rust_file = None main_rust_file = None
for i in target.get_sources(): for i in target.get_sources():
if not rustc.can_compile(i): if not rustc.can_compile(i):
raise InvalidArguments('Rust target %s contains a non-rust source file.' % target.get_basename()) raise InvalidArguments('Rust target {} contains a non-rust source file.'.format(target.get_basename()))
if main_rust_file is None: if main_rust_file is None:
main_rust_file = i.rel_to_builddir(self.build_to_src) main_rust_file = i.rel_to_builddir(self.build_to_src)
if main_rust_file is None: if main_rust_file is None:
@ -1377,11 +1376,11 @@ int dummy;
@classmethod @classmethod
def get_compiler_rule_name(cls, lang: str, for_machine: MachineChoice) -> str: def get_compiler_rule_name(cls, lang: str, for_machine: MachineChoice) -> str:
return '%s_COMPILER%s' % (lang, cls.get_rule_suffix(for_machine)) return '{}_COMPILER{}'.format(lang, cls.get_rule_suffix(for_machine))
@classmethod @classmethod
def get_pch_rule_name(cls, lang: str, for_machine: MachineChoice) -> str: def get_pch_rule_name(cls, lang: str, for_machine: MachineChoice) -> str:
return '%s_PCH%s' % (lang, cls.get_rule_suffix(for_machine)) return '{}_PCH{}'.format(lang, cls.get_rule_suffix(for_machine))
@classmethod @classmethod
def compiler_to_rule_name(cls, compiler: Compiler) -> str: def compiler_to_rule_name(cls, compiler: Compiler) -> str:
@ -1453,7 +1452,7 @@ int dummy;
abs_headers.append(absh) abs_headers.append(absh)
header_imports += swiftc.get_header_import_args(absh) header_imports += swiftc.get_header_import_args(absh)
else: else:
raise InvalidArguments('Swift target %s contains a non-swift source file.' % target.get_basename()) raise InvalidArguments('Swift target {} contains a non-swift source file.'.format(target.get_basename()))
os.makedirs(self.get_target_private_dir_abs(target), exist_ok=True) os.makedirs(self.get_target_private_dir_abs(target), exist_ok=True)
compile_args = swiftc.get_compile_only_args() compile_args = swiftc.get_compile_only_args()
compile_args += swiftc.get_optimization_args(self.get_option_for_target('optimization', target)) compile_args += swiftc.get_optimization_args(self.get_option_for_target('optimization', target))
@ -1540,7 +1539,7 @@ int dummy;
static_linker = self.build.static_linker[for_machine] static_linker = self.build.static_linker[for_machine]
if static_linker is None: if static_linker is None:
return return
rule = 'STATIC_LINKER%s' % self.get_rule_suffix(for_machine) rule = 'STATIC_LINKER{}'.format(self.get_rule_suffix(for_machine))
cmdlist = [] cmdlist = []
args = ['$in'] args = ['$in']
# FIXME: Must normalize file names with pathlib.Path before writing # FIXME: Must normalize file names with pathlib.Path before writing
@ -1574,7 +1573,7 @@ int dummy;
or langname == 'rust' \ or langname == 'rust' \
or langname == 'cs': or langname == 'cs':
continue continue
rule = '%s_LINKER%s' % (langname, self.get_rule_suffix(for_machine)) rule = '{}_LINKER{}'.format(langname, self.get_rule_suffix(for_machine))
command = compiler.get_linker_exelist() command = compiler.get_linker_exelist()
args = ['$ARGS'] + compiler.get_linker_output_args('$out') + ['$in', '$LINK_ARGS'] args = ['$ARGS'] + compiler.get_linker_output_args('$out') + ['$in', '$LINK_ARGS']
description = 'Linking target $out' description = 'Linking target $out'
@ -1645,7 +1644,7 @@ int dummy;
self.add_rule(NinjaRule(rule, command, [], description)) self.add_rule(NinjaRule(rule, command, [], description))
def generate_fortran_dep_hack(self, crstr): def generate_fortran_dep_hack(self, crstr):
rule = 'FORTRAN_DEP_HACK%s' % (crstr) rule = 'FORTRAN_DEP_HACK{}'.format(crstr)
if mesonlib.is_windows(): if mesonlib.is_windows():
cmd = ['cmd', '/C'] cmd = ['cmd', '/C']
else: else:
@ -1698,7 +1697,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
command = [ninja_quote(i) for i in compiler.get_exelist()] command = [ninja_quote(i) for i in compiler.get_exelist()]
args = ['$ARGS'] + quoted_depargs + compiler.get_output_args('$out') + compiler.get_compile_only_args() + ['$in'] args = ['$ARGS'] + quoted_depargs + compiler.get_output_args('$out') + compiler.get_compile_only_args() + ['$in']
description = 'Compiling %s object $out' % compiler.get_display_language() description = 'Compiling {} object $out'.format(compiler.get_display_language())
if isinstance(compiler, VisualStudioLikeCompiler): if isinstance(compiler, VisualStudioLikeCompiler):
deps = 'msvc' deps = 'msvc'
depfile = None depfile = None
@ -1859,9 +1858,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
modname = modmatch.group(1).lower() modname = modmatch.group(1).lower()
if modname in module_files: if modname in module_files:
raise InvalidArguments( raise InvalidArguments(
'Namespace collision: module %s defined in ' 'Namespace collision: module {} defined in '
'two files %s and %s.' % 'two files {} and {}.'.format(modname, module_files[modname], s))
(modname, module_files[modname], s))
module_files[modname] = s module_files[modname] = s
else: else:
submodmatch = submodre.match(line) submodmatch = submodre.match(line)
@ -1872,9 +1870,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
if submodname in submodule_files: if submodname in submodule_files:
raise InvalidArguments( raise InvalidArguments(
'Namespace collision: submodule %s defined in ' 'Namespace collision: submodule {} defined in '
'two files %s and %s.' % 'two files {} and {}.'.format(submodname, submodule_files[submodname], s))
(submodname, submodule_files[submodname], s))
submodule_files[submodname] = s submodule_files[submodname] = s
self.fortran_deps[target.get_basename()] = {**module_files, **submodule_files} self.fortran_deps[target.get_basename()] = {**module_files, **submodule_files}

Loading…
Cancel
Save