meson: copy script to build directory

Viewed 437

I have as tests both C and shell source files. Meson unit tests are expected to be run from build directory. Compiled binaries from my C sources I get copied into build directory automatically (specified as executable()), how to copy there shell scripts?

Or should I run / source them from source directory, e.g.

test = join_paths(meson.source_root(), 'tests/run.sh')
run_command(test, "--foo", "bar")

Or use find_program()?

test = find_program('run.sh')
run_command(test, "--foo", "bar")
2 Answers

The more canonical way of doing that would be using "dummy" custom_target:

scipt_name = 'run.sh'
custom_target('copy script',
  input : script_name,
  output :  script_name,
  command : ['cp', '@INPUT@', '@OUTPUT@'],
  install : false,
  build_by_default : true)

This is better because it will get executed, i.e. copied when updated; and if you add this to meson.build in tests folder - no paths manipulations needed.

OK, find_program() searches in the system PATH, thus not suitable. Probably copying files to the build directory will be better:

src = join_paths(meson.source_root(), 'tests/run.sh')
dest = join_paths(meson.build_root(), 'tests')
message('copying @0@ to @1@ ...'.format(src, dest))
run_command('cp', src, dest)
Related