backend/ninja: add generated sources to depscan order deps

Since we changed to using a json file to avoid over long command lines
we created a situation where the generated files may not be ready when
the depscan happens. To avoid that, we need to add all of the generated
sources as order deps.

Fixes: #9258
pull/9030/merge
Dylan Baker 3 years ago committed by Eli Schwartz
parent 276ff0cc89
commit 40ff02268c
  1. 8
      mesonbuild/backend/ninjabackend.py
  2. 16
      test cases/fortran/7 generated/meson.build
  3. 2
      test cases/fortran/7 generated/mod3.f90

@ -887,7 +887,7 @@ class NinjaBackend(backends.Backend):
else:
final_obj_list = obj_list
elem = self.generate_link(target, outname, final_obj_list, linker, pch_objects, stdlib_args=stdlib_args)
self.generate_dependency_scan_target(target, compiled_sources, source2object)
self.generate_dependency_scan_target(target, compiled_sources, source2object, generated_source_files)
self.generate_shlib_aliases(target, self.get_target_dir(target))
self.add_build(elem)
@ -911,7 +911,7 @@ class NinjaBackend(backends.Backend):
return False
return True
def generate_dependency_scan_target(self, target, compiled_sources, source2object):
def generate_dependency_scan_target(self, target, compiled_sources, source2object, generated_source_files: T.List[mesonlib.File]):
if not self.should_use_dyndeps_for_target(target):
return
depscan_file = self.get_dep_scan_file_for(target)
@ -929,6 +929,10 @@ class NinjaBackend(backends.Backend):
json.dump(scan_sources, f)
elem = NinjaBuildElement(self.all_outputs, depscan_file, rule_name, json_abs)
elem.add_item('picklefile', pickle_file)
# Add any generated outputs to the order deps of the scan target, so
# that those sources are present
for g in generated_source_files:
elem.orderdeps.add(g.relative_name())
scaninfo = TargetDependencyScannerInfo(self.get_target_private_dir(target), source2object)
with open(pickle_abs, 'wb') as p:
pickle.dump(scaninfo, p)

@ -7,9 +7,21 @@ project('generated', 'fortran',
conf_data = configuration_data()
conf_data.set('ONE', 1)
conf_data.set('TWO', 2)
conf_data.set('THREE', 3)
mod3_f = configure_file(input : 'mod3.fpp', output : 'mod3.f90', configuration : conf_data)
mod3_f = custom_target(
'mod3.f',
input : 'mod3.f90',
output : 'mod3.f90',
# We need a platform agnostic way to do a copy a file, using a custom_target
# and we need to use the @OUTDIR@, not @OUTPUT@ in order to exercise
# https://github.com/mesonbuild/meson/issues/9258
command : [
find_program('python', 'python3'), '-c',
'import sys, shutil; shutil.copy(sys.argv[1], sys.argv[2])',
'@INPUT@', '@OUTDIR@',
],
)
three = library('mod3', mod3_f)
templates_basenames = ['mod2', 'mod1']

@ -1,6 +1,6 @@
module mod3
implicit none
integer, parameter :: modval3 = @THREE@
integer, parameter :: modval3 = 3
end module mod3
Loading…
Cancel
Save