mesonbuild / meson

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

fs.copyfile() does not allow relative destination directories #12755

Open UnixY2K opened 8 months ago

UnixY2K commented 8 months ago

I have noticed that the following code is not valid:

fs = import('fs')
fs.copyfile(some_file,'relative_dir/file')

is there a reason why this cannot be made for relative directories?

the expected result would be to have the copied file in the meson.current_build_dir() and creating the directory if not exists, I think that this can be done with scripts but would be better to have it out of the box, besides changing in fs.py https://github.com/mesonbuild/meson/blob/33527630f1bd0e51093044016557cb44e7bb6547/mesonbuild/modules/fs.py#L281

to use something like os.path.isabs(dest) I don´t know if is required to change anything else.

please let me know if this is intended.

bruchar1 commented 8 months ago

is there a reason why this cannot be made for relative directories?

See https://github.com/mesonbuild/meson/issues/2320#issuecomment-466171587

eli-schwartz commented 8 months ago

The general restriction is inherited from custom_target, yes.

As I commented in the linked thread: https://github.com/mesonbuild/meson/issues/2320#issuecomment-1648437208

Shower thought: perhaps we could allow directories in the output filename, but only as long as that output directory segment

  1. is never descended into using subdir()

  2. does not contain a ../ component, it's a pure child of the current subdir

Check 2 should actually check if the given subdirectory exists in the source dir at all and error out if it does.

It is still something I'm willing to put the time into coding up, if @jpakkane agrees that given all 3 restrictions, it makes sense to permit custom_target and build_target to place files in relative ("pure child") directory locations.