mesonbuild / meson

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

configure_file argument depfile broken #9851

Open gunechristensen opened 2 years ago

gunechristensen commented 2 years ago

Describe the bug

Depfile argument seems broken from 0.53.0 - 0.52.0 and 0.52.1 has the behavior I expect to be correct.

Using configure_file with depfile argument works fine first time after a clean configure. But after running ninja or meson compile changes to dep files are on longer detected. Whats happens is that the depfile is removed from build.ninja.

To Reproduce

meson.build

project('configure file test', 'c')

genprog = import('python3').find_python()

genscript2deps = '@0@/generator-deps.py'.format(meson.current_source_dir())
ofile2deps = '@0@/config2deps.h'.format(meson.current_build_dir())
outf = configure_file(
  output : 'config2deps.h',
  depfile : 'mydepfile.d',
  command : [genprog, genscript2deps, ofile2deps, '@DEPFILE@']
)

generator-deps.py

#!/usr/bin/env python3

import sys, os
from pathlib import Path

if len(sys.argv) != 3:
    print("Wrong amount of parameters.")

build_dir = Path(os.environ['MESON_BUILD_ROOT'])
subdir = Path(os.environ['MESON_SUBDIR'])
outputf = Path(sys.argv[1])

with outputf.open('w') as ofile:
    ofile.write("#define ZERO_RESULT 0\n")

depf = Path(sys.argv[2])
with depf.open('w') as ofile:
    ofile.write(f"{outputf.name}: shc_dep\n")

meson build touch shc_dep ninja -C build

This works fine!

touch shc_dep ninja -C build

Nothing happens - ninja just reports ninja: no work to do.

Expected behavior

After touching or changing dep file (shc_dep) I expect build files to be regenerated when running ninja or meson compile.

system parameters

configure_file_issue.zip

eli-schwartz commented 2 years ago

In the depfile, what is the path to shc_dep? Nothing.

It therefore depends on what directory you run meson from.

This has been the case since it was initially implemented in #5702 I guess... /cc @elmarco

Actually wait, no. This comes from #6023, which indeed assumes everything is an absolute path, an assumption which was not originally true.

gunechristensen commented 1 year ago

Hi @eli-schwartz,

Thanks for the answer. Forgot I had this issue open.

What got me confused was the "test cases/common/14 configure file" example. I can make it work by doing 2 things:

1) Add the path to the depfile - as you described 2) But I also had to copy the example to a directory with no spaces

I did the testing on linux (Windows Subsystem for Linux).

Would you be interested in a pull request if I go for a deeper dive? Or do you have a good idea about the root cause?

Working example

meson.build

project('configure file test', 'c')

genprog = import('python3').find_python()
genscript2deps = '@0@/generator-deps.py'.format(meson.current_source_dir())
config = configure_file(
  input : 'shc_dep',
  output : 'config2deps.h',
  depfile : 'depfile.d',
  command : [genprog, genscript2deps, '@OUTPUT@', '@DEPFILE@']
)

generator-deps.py

#!/usr/bin/env python3

import sys, os
from pathlib import Path

if len(sys.argv) != 3:
    print("Wrong amount of parameters.")

source_root = Path(os.environ['MESON_SOURCE_ROOT'])

output = Path(sys.argv[1])
with output.open('w') as ofile:
    ofile.write("#define ZERO_RESULT 0\n")

depfile = Path(sys.argv[2])
with depfile.open('w') as ofile:
    ofile.write(f"{output.name}: {source_root}/shc2_dep\n")
eli-schwartz commented 1 year ago

Would you be interested in a pull request if I go for a deeper dive?

Sure.

germandiagogomez commented 5 months ago

FWIW, related (I guess).

I am generating a resource file. I tried via generator and via custom_target (both) and depfile argument seems broken to me for both invocations.

It does not generate a depfile at all anywhere if I invoke my resource compiler through the custom_target or generator. If I invoke the equivalent command from the command line, it does create the dep file.

My resource compiler program throws an exception if it cannot create the dep file, but it does not break when compiling with meson. I assume, then, that the file is created.

Meson will generate the output but not the depfile at all and my resource compiler works well. This means that it is not my resource compiler working wrong, I am guessing, but some kind of weird or unexpected behavior?

It is true also that my command, basically, has no inputs (the input is actually traversing a directory, and for generator I just faked the input by putting a file in the directory to compile the resource for). As a side-effect of invocation a depfile should be generated.

Here, the command line I used for custom_target:

embedded_resources = custom_target('rmlResources',
                                     output: 'rmlResources.res.hpp',
                                     depfile: 'rmlResources.deps',
                                     command: [resources_compiler_prog,
                                               'rmlResources',
                                               '@OUTPUT@',
                                               '@DEPFILE@',
                                               meson.current_source_dir() / 'resources', meson.current_source_dir() / 'resources/']
                                    )

executable(..., sources: [..., embedded_resources])

Is this incorrect behavior?