Corky94 / gyp

Automatically exported from code.google.com/p/gyp
0 stars 0 forks source link

Variables defined in a conditions can't be reused in another condition block #165

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See attached reduction:

{
  'variables': {
    'true': '1',
  },
  'conditions': [
    ['true==1', {
      'variables': {
        'type': 'none',
      },
    }],
    ['true==1', {
      'targets': [
        {
          'target_name': 'main',
          'type': '<(type)',
        },
      ],
    }],
  ],
}

---

Traceback (most recent call last):
  File "../chromium.git/src/tools/gyp/gyp", line 18, in <module>
    sys.exit(gyp.main(sys.argv[1:]))
  File "../chromium.git/src/tools/gyp/pylib/gyp/__init__.py", line 445, in main
    options.circular_check)
  File "../chromium.git/src/tools/gyp/pylib/gyp/__init__.py", line 84, in Load
    depth, generator_input_info, check, circular_check)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 2148, in Load
    depth, check)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 380, in LoadTargetBuildFile
    build_file_path)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 941, in ProcessVariablesAndConditionsInDict
    ProcessConditionsInDict(the_dict, is_late, variables, build_file)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 818, in ProcessConditionsInDict
    variables, build_file)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 967, in ProcessVariablesAndConditionsInDict
    build_file)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 982, in ProcessVariablesAndConditionsInList
    ProcessVariablesAndConditionsInDict(item, is_late, variables, build_file)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 896, in ProcessVariablesAndConditionsInDict
    expanded = ExpandVariables(value, is_late, variables, build_file)
  File "../chromium.git/src/tools/gyp/pylib/gyp/input.py", line 666, in ExpandVariables
    ' in ' + build_file
KeyError: 'Undefined variable type in variables.gyp while trying to load 
variables.gyp'

Original issue reported on code.google.com by maruel@chromium.org on 27 Aug 2010 at 12:59

GoogleCodeExporter commented 9 years ago
This is correct, variables aren’t reloaded in between conditions. (Maybe they 
could be, if it doesn’t break anything.)

Move the first condition into the outer variables block? You’d have 
'variables':{'conditions':[['1',{'type':'none'}]]} instead of 
'conditions':[['1','variables':{'type':'none'}]] that way.

If you need to use another variable inside your condition, you may need to use 
the variables-inside-variables hack, like 
'variables':{'variables':{'true':'1'},'true%':'<(true)'}. See the comment in 
chrome’s build/common.gypi about “putting a variables dict inside another 
variables dict.”

Putting that all together, it would look like this:

'variables': {
  'variables': {
    'true': '1',
  },
  'true%': '<(true)',
  'conditions': [
    ['true==1', {
      'type': 'none',
    ]},
  ],
},
'conditions': [
  ['true==1', {
    'targets': [
      {
        'target_name': 'main',
        'type': '<(type)',
      },
    ],
  }],
],

(or something like that, I haven’t actually tried.)

Original comment by mark@chromium.org on 27 Aug 2010 at 3:05

GoogleCodeExporter commented 9 years ago

Original comment by mark@chromium.org on 27 Aug 2010 at 3:05