Skip to content

Commit

Permalink
backend/ninja: fix bad @OUTPUTn@ replacements
Browse files Browse the repository at this point in the history
`outfilelist` is the output list of the target, while `outfiles` is the output
list of the individual commands

Bug: mesonbuild/pull/13304#issuecomment-2226398671
  • Loading branch information
chubinou committed Aug 8, 2024
1 parent 43b80e0 commit b04ac25
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2602,17 +2602,18 @@ def generate_genlist_for_target(self, genlist: build.GeneratedList, target: buil
subdir = genlist.subdir
exe = generator.get_exe()
infilelist = genlist.get_inputs()
outfilelist = genlist.get_outputs()
extra_dependencies = self.get_target_depend_files(genlist)
for i, curfile in enumerate(infilelist):
if len(generator.outputs) == 1:
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i])
else:
sole_output = f'{curfile}'
for curfile in infilelist:
infilename = curfile.rel_to_builddir(self.build_to_src, self.get_target_private_dir(target))
base_args = generator.get_arglist(infilename)
outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]
outfilespriv = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles]

if len(generator.outputs) == 1:
sole_output = outfilespriv[0]
else:
sole_output = f'{curfile}'

if generator.depfile is None:
rulename = 'CUSTOM_COMMAND'
args = base_args
Expand All @@ -2623,19 +2624,16 @@ def generate_genlist_for_target(self, genlist: build.GeneratedList, target: buil
args = [x.replace('@DEPFILE@', depfile) for x in base_args]
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)
for x in args]
args = self.replace_outputs(args, self.get_target_private_dir(target), outfilelist)
# We have consumed output files, so drop them from the list of remaining outputs.
if len(generator.outputs) > 1:
outfilelist = outfilelist[len(generator.outputs):]
args = self.replace_outputs(args, self.get_target_private_dir(target), outfiles)
args = self.replace_paths(target, args, override_subdir=subdir)
cmdlist, reason = self.as_meson_exe_cmdline(exe,
self.replace_extra_args(args, genlist),
capture=outfiles[0] if generator.capture else None,
capture=outfilespriv[0] if generator.capture else None,
env=genlist.env)
abs_pdir = os.path.join(self.environment.get_build_dir(), self.get_target_dir(target))
os.makedirs(abs_pdir, exist_ok=True)

elem = NinjaBuildElement(self.all_outputs, outfiles, rulename, infilename)
elem = NinjaBuildElement(self.all_outputs, outfilespriv, rulename, infilename)
elem.add_dep([self.get_target_filename(x) for x in generator.depends])
if generator.depfile is not None:
elem.add_item('DEPFILE', depfile)
Expand Down

0 comments on commit b04ac25

Please sign in to comment.