I have python script that generates source and header file based on a configuration file. I want to run the python script on every build to ensure the generated "test.cpp" and "test.h" are up to date.
Both "build_always_stale" and "build_by_default" are set to true, but the script is not getting executed.
python_file = files('script/autogenerate.py')
config_file = files('config/configuration.yaml')
custom_target(
command: ['python3', python_file, meson.current_source_dir()],
output: ['test.h', 'test.cpp'],
input: config_file,
build_always_stale: true,
build_by_default: true
)
Since "test.cpp" and "test.h" should be created and filled by the script, I do not have these files created manually when i start the build. When I create the file manually before starting the build, the script runs only first time to autogenerate the code inside. But the script does not get executed the second time.
How can I get the autogenerating script to run every time even if no change is made to the python file and configuration file?
I would need to see more of your
meson.build
file to say for certain, but my assumption is you have something like this...The problem you have here is that a
custom_target()
is just like anexecutable()
orlibrary()
; meson needs to be told that thecustom_target()
is 'used by' another build target to ensure there is a correct sequencing events, e.g. your file generation runs, then then executable gets recompiled. The way to do this is to take the result of yourcustom_target()
and include it in the sources list for anylibrary()
orexecutable()
that needs said files to exist. Alternatively, you could useconfigure_file()
to have the files be generated at configure-time, although there is no way to make this happen every single time (although I would not recommend doing that anyway).The following build file correctly regenerates the file each time: