Home | History | Annotate | Download | only in actions
      1 # Copyright 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """A module to add gyp support to cr."""
      6 
      7 import cr
      8 import os
      9 
     10 GYP_DEFINE_PREFIX = 'GYP_DEF_'
     11 
     12 class GypPrepareOut(cr.PrepareOut):
     13   """A prepare action that runs gyp whenever you select an output directory."""
     14 
     15   ENABLED = cr.Config.From(
     16       GYP_GENERATORS='ninja',
     17       GYP_GENERATOR_FLAGS='output_dir={CR_OUT_BASE} config={CR_BUILDTYPE}',
     18       GYP_DEF_target_arch='{CR_ENVSETUP_ARCH}',
     19   )
     20 
     21   def UpdateContext(self):
     22     # Collapse GYP_DEFINES from all GYP_DEF prefixes
     23     gyp_defines = cr.context.Find('GYP_DEFINES') or ''
     24     for key, value in cr.context.exported.items():
     25       if key.startswith(GYP_DEFINE_PREFIX):
     26         gyp_defines += ' %s=%s' % (key[len(GYP_DEFINE_PREFIX):], value)
     27     cr.context['GYP_DEFINES'] = gyp_defines.strip()
     28     if cr.context.verbose >= 1:
     29       print cr.context.Substitute('GYP_DEFINES = {GYP_DEFINES}')
     30 
     31   def Prepare(self):
     32     if cr.context.verbose >= 1:
     33       print cr.context.Substitute('Invoking gyp with {GYP_GENERATOR_FLAGS}')
     34 
     35     cr.Host.Execute(
     36         '{CR_SRC}/build/gyp_chromium',
     37         '--depth={CR_SRC}',
     38         '--check'
     39     )
     40