0

I have a project whose build options are complicated enough that I have to run several external scripts during the configuration process. If these scripts, or the files that they read, are changed, then configuration needs to be re-run.

Currently the project uses Autotools, and I can express this requirement using the CONFIG_STATUS_DEPENDENCIES variable. I'm experimenting with porting the build process to Meson and I can't find an equivalent. Is there currently an equivalent, or do I need to file a feature request?

For concreteness, a snippet of the meson.build in progress:

pymod = import('python')
python = pymod.find_installation('python3')
svf_script = files('scripts/compute-symver-floor')
svf = run_command(python, svf_script, files('lib'),
                  host_machine.system())
if svf.returncode() == 0
  svf_results = svf.stdout().split('\n')
  SYMVER_FLOOR = svf_results[0].strip()
  SYMVER_FILE  = svf_results[2].strip()

else
  error(svf.stderr())
endif

# next line is a fake API expressing the thing I can't figure out how to do
meson.rerun_configuration_if_files_change(svf_script, SYMVER_FILE)
zwol
  • 135,547
  • 38
  • 252
  • 361

1 Answers1

0

This is what custom_target() is for.

Minimal example

svf_script = files('svf_script.sh')
svf_depends = files('config_data_1', 'config_data_2') # files that svf_script.sh reads

svf = custom_target('svf_config', command: svf_script, depend_files: svf_depends, build_by_default: true, output: 'fake')

This creates a custom target named svf_config. When out of date, it runs the svf_script command. It depends on the files in the svf_depends file object, as well as all the files listed in the command keyword argument (i.e. the script itself).

You can also specify other targets as dependencies using the depends keyword argument.


output is set to 'fake' to stop meson from complaining about a missing output keyword argument. Make sure that there is a file of the same name in the corresponding build directory to stop the target from always being considered out-of-date. Alternatively, if your configure script(s) generate output files, you could list them in this array.

bool3max
  • 2,748
  • 5
  • 28
  • 57
  • I'm sorry, I don't think you understood the question. I am not looking for a way to make the `svf_script` get run in every build. I am looking for a way to tell Meson that it needs to redo the _configuration process_ (the stuff that happens when you do `meson ` in a fresh source tree) if the svf_script changes. In other words, it needs to treat the svf_script like `meson.build`. – zwol Jan 01 '20 at 16:39
  • I don't understand why you would ever need to do that. Could you elaborate? You can make virtually any aspect of meson.build dynamic and dependent on the output of a certain script. Dependencies, new targets, outputs, inputs, it can all be dynamic without having to re-run the setup. – bool3max Jan 01 '20 at 22:38