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