There are somewhat common, reasonable and legitimate use cases for a dependency to provide data files installed to /usr which are used as command inputs. When getting a dependency from a subproject, however, the attempt to directly construct an input file from a subproject results in a sandbox violation. This means not all dependencies can be wrapped as a subproject. One example is wayland-protocols XML files which get scanned and used to produce C source files. Teach Meson to recognize when a string path is the result of fetching a dep.get_variable(), and special case this to be exempt from subproject violations. A requirement of this is that the file must be installed by install_data() or install_subdir() because otherwise it is not actually representative of what a pkg-config dependency would provide.pull/10039/head
parent
b55349c2e9
commit
0e3ed2f655
18 changed files with 154 additions and 4 deletions
@ -0,0 +1,13 @@ |
||||
project('subproject dependency variables', 'c') |
||||
|
||||
subfiles_dep = subproject('subfiles').get_variable('files_dep') |
||||
|
||||
executable( |
||||
'foo', |
||||
join_paths(subfiles_dep.get_variable('pkgdatadir'), 'foo.c') |
||||
) |
||||
|
||||
executable( |
||||
'foo2', |
||||
subfiles_dep.get_variable('pkgdatadir2') / 'foo.c' |
||||
) |
@ -0,0 +1,26 @@ |
||||
project('dependency variable resource') |
||||
|
||||
files_dep = declare_dependency( |
||||
variables: [ |
||||
'pkgdatadir=@0@/subdir'.format(meson.current_source_dir()), |
||||
'pkgdatadir2=@0@/subdir2'.format(meson.current_source_dir()), |
||||
] |
||||
) |
||||
|
||||
install_data('subdir/foo.c', install_dir: get_option('datadir') / 'subdir') |
||||
install_subdir('subdir2', install_dir: get_option('datadir')) |
||||
|
||||
import('pkgconfig').generate( |
||||
name: 'depvar_resource', |
||||
description: 'Get a resource file from pkgconfig or a subproject', |
||||
version: '0.1', |
||||
variables: [ |
||||
'pkgdatadir=${datadir}/subdir', |
||||
'pkgdatadir2=${datadir}/subdir2', |
||||
], |
||||
uninstalled_variables: [ |
||||
'pkgdatadir=@0@/subdir'.format(meson.current_source_dir()), |
||||
'pkgdatadir2=@0@/subdir2'.format(meson.current_source_dir()), |
||||
], |
||||
dataonly: true, |
||||
) |
@ -0,0 +1 @@ |
||||
int main(void) { return 0; } |
@ -0,0 +1 @@ |
||||
int main(void) { return 0; } |
@ -0,0 +1,7 @@ |
||||
{ |
||||
"installed": [ |
||||
{ "type": "file", "file": "usr/share/pkgconfig/depvar_resource.pc" }, |
||||
{ "type": "file", "file": "usr/share/subdir/foo.c" }, |
||||
{ "type": "file", "file": "usr/share/subdir2/foo.c" } |
||||
] |
||||
} |
@ -0,0 +1,25 @@ |
||||
project('subproject-sandbox-violation') |
||||
|
||||
sub1_d = subproject('subproj1').get_variable('d') |
||||
sub1_mustfail = sub1_d.get_variable('dir') / '..' / 'file.txt' |
||||
|
||||
sub2_d = subproject('subproj2').get_variable('d') |
||||
sub2_mustfail = sub2_d.get_variable('dir') / 'file.txt' |
||||
|
||||
if get_option('failmode') == 'parent-dir' |
||||
mustfail = sub1_mustfail |
||||
elif get_option('failmode') == 'not-installed' |
||||
mustfail = sub2_mustfail |
||||
endif |
||||
|
||||
custom_target( |
||||
'mustfail', |
||||
input: mustfail, |
||||
output: 'file.txt', |
||||
command: [ |
||||
'python3', '-c', |
||||
'import os; shutil.copy(sys.argv[1], sys.argv[2])', |
||||
'@INPUT@', |
||||
'@OUTPUT@' |
||||
], |
||||
) |
@ -0,0 +1 @@ |
||||
option('failmode', type: 'combo', choices: ['parent-dir', 'not-installed']) |
@ -0,0 +1,4 @@ |
||||
project('subproj1') |
||||
|
||||
install_data('file.txt') |
||||
subdir('nested') |
@ -0,0 +1,5 @@ |
||||
d = declare_dependency( |
||||
variables: [ |
||||
'dir=@0@'.format(meson.current_source_dir()), |
||||
] |
||||
) |
@ -0,0 +1,7 @@ |
||||
project('subproj1') |
||||
|
||||
d = declare_dependency( |
||||
variables: [ |
||||
'dir=@0@'.format(meson.current_source_dir()), |
||||
] |
||||
) |
@ -0,0 +1,15 @@ |
||||
{ |
||||
"matrix": { |
||||
"options": { |
||||
"failmode": [ |
||||
{ "val": "not-installed" }, |
||||
{ "val": "parent-dir" } |
||||
] |
||||
} |
||||
}, |
||||
"stdout": [ |
||||
{ |
||||
"line": "test cases/failing/123 subproject sandbox violation/meson.build:19:0: ERROR: Sandbox violation: Tried to grab file file.txt from a nested subproject." |
||||
} |
||||
] |
||||
} |
Loading…
Reference in new issue