1

The gyp documentation documents the 'variables' section like this:

'variables': Definitions of variables that can be interpolated and used in various other parts of the file.

(emphasis mine). This seems to exclude using the variables in included gyp files, and also exclude the possibility of including other gyp files that set variables.

Is this correct? What is the scope of these variables, and how do you set variables globally? I see that in Chromium, the build/common.gypi is setting lots of variables, but Chromium also is using a magic gyp_chromium script that is different from plain gyp.

user239558
  • 6,964
  • 1
  • 28
  • 35

1 Answers1

1

The scope of variables is GYP is very much alike with the scope of local variables in C++. Let's say you define a variable in a variables dictionary FOO. The scope of variables defined in FOO is the dictionary BAR which is parent of FOO. You can use those variables anywhere inside BAR and nowhere outside of it.


how do you set variables globally?

Knowing the described rules it's very easy. Add a variables dictionary to the top-level dictionary of your gyp script and define some variables in it. They will be available anywhere1 in this script.


This seems to exclude using the variables in included gyp files, and also exclude the possibility of including other gyp files that set variables.

This is not true. Let's say you include include.gypi into generator.gyp script. If include.gypi has variables section in it's top-level dictionary, those variables would be accessible anywhere in the generator.gyp. Obviously variables defined not in the top-level dictionary would not be accessible.


1 Keep in mind that includes are parsed before the variables expansion. Thus you can not use variables in includes paths.

Kolyunya
  • 5,973
  • 7
  • 46
  • 81