1

As explained here, I like to create file objects in subdirs, and library / executables in the top-level file. However, since all the variables end up in global scope, two subdir files could accidentally use the same variable names. For example:

# Top-level meson.build
subdir('src/abc')
subdir('src/def')
# src/abc/meson.build
my_files=files('1.c','2.c')
# src/def/meson.build
my_files=files('3.c','4.c')

I want meson to throw an error when src/def/meson.build tries to assign a value to my_files. Is this possible in Meson 0.50?

rellenberg
  • 105
  • 8
  • At present it's not possible. You may want to read this discussion: [issue #2607](https://github.com/mesonbuild/meson/issues/2607). Maybe it's the time to make a feature request? – Matt Apr 17 '19 at 12:27
  • 1
    Thanks! I hadn't seen that discussion before. I have a feature request open for this now, [issue #5270](https://github.com/mesonbuild/meson/issues/5270). – rellenberg Apr 18 '19 at 16:04

1 Answers1

0

Reassigning variables is rather legitimate operation in meson, so it looks as it is not possible to generate error in standard way. One way of avoiding this problem is following some naming rules e.g. according to folders/sub-folders' names (abc_files, def_files in your case).

But if you really need to have variables with the same name and make sure they are not reassigned, you can use is_variable() function which returns true if variable with given name has been assigned. So, place the following assert before each assignment:

assert(not is_variable('my_files'), 'my_files already assigned!!!')
my_files=files('3.c','4.c')
pmod
  • 10,450
  • 1
  • 37
  • 50