afrolov / gyp

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

variable set in condition is undefined when used by a target defined in another condition (BRANDING) #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In the self-contained example below, "gyp -f gypd" generates an error:

KeyError: 'Undefined variable BRANDING in <(BRANDING)'

As described in the comments below, the variable *is* defined if the target 
is itself outside of a condition.  It also doesn't matter if the two 
condition blocks are swapped in the 'conditions' list (i.e., you try to put 
the condition that defines the BRANDING variable "before" the target 
condition), you get the undefined variable error regardless of the order.

{
  'variables': {
    'OS': 'win',
    'branding': 'Chrome',
    # 'BRANDING' is set in the 'conditions' section at the bottom.
  },
  # BRANDING *is* defined for this target outside of the condition:
  #'targets': [
  #  {
  #    'target_name': 'mini_installer',
  #    'type': 'none',
  #    'sources': [
  #      '<(BRANDING)',
  #    ],
  #  },
  #],
  'conditions': [
    ['OS=="win"', {
      # BRANDING is undefined for this conditional target
      'targets': [
        {
          'target_name': 'setup',
          'type': 'none',
          'sources': [
            '<(BRANDING)',
          ],
        },
      ],
    }],
    [ 'branding == "Chrome"', {
      'variables': {
         'BRANDING': '../../chrome/app/theme/google_chrome/BRANDING',
      },
    }, { # else branding!="Chrome"
      'variables': {
         'BRANDING': '../../chrome/app/theme/chromium/BRANDING',
      },
    }],
  ],
}

Original issue reported on code.google.com by sgk@chromium.org on 29 May 2009 at 5:46

GoogleCodeExporter commented 9 years ago
The deal here is that BRANDING, set within a condition, can't be used in a 
merge dict
of a sibling condition.

I missed this in the checked-in file because BRANDING is also used outside of
conditional merge dicts.  I didn't realize it was used inside conditional merge 
dicts
too.

BRANDING doesn't exist while inside the merge dict corresponding to the 
OS=="win"
condition.  That's the reason we saw this at -DOS=win but not -DOS=linux.

Original comment by mark@chromium.org on 29 May 2009 at 6:31

GoogleCodeExporter commented 9 years ago
Keep in mind that I still saw problems when trying to move the 'conditions' 
into a 
'target_defaults' dict.  That doesn't seem to fit the sibling condition 
pattern, but 
I can kind of see how it might end up there under the covers...?

Original comment by sgk@chromium.org on 29 May 2009 at 9:14