mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.3k stars 1.52k forks source link

depfile support vs generator.process(..., preserve_path_from: ...) #13169

Open anarazel opened 2 weeks ago

anarazel commented 2 weeks ago

When a generator is used with depfiles support and preserve_path_from is being used, the chosen depfile names are not guaranteed to be unique. This can lead to all kinds of fun issues like corrupted depfiles, missing rebuilds, ...

project('testme',
  ['c'],
)

touch = find_program('touch')

test_files = []

test_files = files('a/test_file', 'b/test_file')

gen = generator(
  touch,
  arguments: ['@OUTPUT@'],
  output: '@PLAINNAME@.t',
  depfile: '@PLAINNAME@.t.d',
)

custom_target(
  command: [touch, '@INPUT@'],
  input: gen.process(test_files, preserve_path_from: meson.current_source_dir()),
  output: 'doit',
  build_by_default: true,
)

where a/test_file and b/test_file are just empty files.

With meson a0ff14551 (not a very recent bug though), this ends up with the generator targets using the same depfile:

$ grep -A1 'build .*test_file.t:' build/build.ninja 
build doit.p/a/test_file.t: CUSTOM_COMMAND_DEP ../a/test_file | /usr/bin/touch
 DEPFILE = doit.p/test_file.t.d
--
build doit.p/b/test_file.t: CUSTOM_COMMAND_DEP ../b/test_file | /usr/bin/touch
 DEPFILE = doit.p/test_file.t.d

Obviously the depfiles used clash. Not good.

For a moment I thought the problem was me using @PLAINNAME@, but afaict there really is no alternative, as neither @OUTPUT@ nor subdirectories are supported.

tristan957 commented 1 week ago

Admittedly, I'm not sure the best way to solve this problem. It seems pretty difficult.