mesonbuild / meson

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

generator.process() doesn't handle custom target/index from subdirectories correctly #13168

Closed anarazel closed 1 week ago

anarazel commented 2 weeks ago

meson (a0ff14551 in my case, but the bug is older) with the ninja backend doesn't correctly handle generator.process() being used to process a generated file, if that file is in a subdirectory. It looks like something looses track of the path for the generated file.

meson.build:

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

touch = find_program('touch')

subdir('include')

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

custom_target('check-headers.stamp',
  command: [touch, '@INPUT@'],
  input: gen.process(test_header),
  output: 'check-headers.stamp',
  build_by_default: true,
)

include/meson.build:

test_header = custom_target(
    output: 'test_header.h',
    command: [touch, '@OUTPUT@']
)

Test:

$ m setup build && ninja -C build
...
ninja: error: 'test_header.h', needed by 'check-headers.stamp.p/test_header.h.t', missing and no known rule to make it

The problem is that test_header.h.t omitted the path in the dependency on test_header.h:

$ grep -E 'test_header.h(.t|):' build/build.ninja 
build include/test_header.h: CUSTOM_COMMAND  | /usr/bin/touch
build check-headers.stamp.p/test_header.h.t: CUSTOM_COMMAND test_header.h | /usr/bin/touch
tristan957 commented 2 weeks ago

Investigating

tristan957 commented 2 weeks ago

https://github.com/mesonbuild/meson/pull/13170

anarazel commented 1 week ago

Thanks!