Skip to content

Commit

Permalink
backends: handle cython ninja rules a bit more idiomatically
Browse files Browse the repository at this point in the history
We want to use as much default ninja behavior as we can, so reuse $out
instead of repeating the output file as a string in $ARGS, and raise
that into the build rule so it is only listed once.
  • Loading branch information
eli-schwartz committed Feb 9, 2023
1 parent d0b39a6 commit 56e6118
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,8 +1703,6 @@ def generate_cython_transpile(self, target: build.BuildTarget) -> \
for src in target.get_sources():
if src.endswith('.pyx'):
output = os.path.join(self.get_target_private_dir(target), f'{src}.{ext}')
args = args.copy()
args += cython.get_output_args(output)
element = NinjaBuildElement(
self.all_outputs, [output],
self.compiler_to_rule_name(cython),
Expand All @@ -1725,9 +1723,7 @@ def generate_cython_transpile(self, target: build.BuildTarget) -> \
else:
ssrc = os.path.join(gen.get_subdir(), ssrc)
if ssrc.endswith('.pyx'):
args = args.copy()
output = os.path.join(self.get_target_private_dir(target), f'{ssrc}.{ext}')
args += cython.get_output_args(output)
element = NinjaBuildElement(
self.all_outputs, [output],
self.compiler_to_rule_name(cython),
Expand Down Expand Up @@ -2235,9 +2231,14 @@ def generate_vala_compile_rules(self, compiler):

def generate_cython_compile_rules(self, compiler: 'Compiler') -> None:
rule = self.compiler_to_rule_name(compiler)
command = compiler.get_exelist() + ['$ARGS', '$in']
description = 'Compiling Cython source $in'
self.add_rule(NinjaRule(rule, command, [], description, extra='restat = 1'))
command = compiler.get_exelist()

args = ['$ARGS', '$in']
args += NinjaCommandArg.list(compiler.get_output_args('$out'), Quoting.none)
self.add_rule(NinjaRule(rule, command + args, [],
description,
extra='restat = 1'))

def generate_rust_compile_rules(self, compiler):
rule = self.compiler_to_rule_name(compiler)
Expand Down

0 comments on commit 56e6118

Please sign in to comment.