• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 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"""This script is now only used by the closure_compilation builders."""
6
7import argparse
8import glob
9import gyp_environment
10import os
11import shlex
12import sys
13
14script_dir = os.path.dirname(os.path.realpath(__file__))
15chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
16
17sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
18import gyp
19
20
21def ProcessGypDefinesItems(items):
22  """Converts a list of strings to a list of key-value pairs."""
23  result = []
24  for item in items:
25    tokens = item.split('=', 1)
26    # Some GYP variables have hyphens, which we don't support.
27    if len(tokens) == 2:
28      result += [(tokens[0], tokens[1])]
29    else:
30      # No value supplied, treat it as a boolean and set it. Note that we
31      # use the string '1' here so we have a consistent definition whether
32      # you do 'foo=1' or 'foo'.
33      result += [(tokens[0], '1')]
34  return result
35
36
37def GetSupplementalFiles():
38  return []
39
40
41def GetGypVars(_):
42  """Returns a dictionary of all GYP vars."""
43  # GYP defines from the environment.
44  env_items = ProcessGypDefinesItems(
45      shlex.split(os.environ.get('GYP_DEFINES', '')))
46
47  # GYP defines from the command line.
48  parser = argparse.ArgumentParser()
49  parser.add_argument('-D', dest='defines', action='append', default=[])
50  cmdline_input_items = parser.parse_known_args()[0].defines
51  cmdline_items = ProcessGypDefinesItems(cmdline_input_items)
52
53  return dict(env_items + cmdline_items)
54
55
56def main():
57  gyp_environment.SetEnvironment()
58
59  print 'Updating projects from gyp files...'
60  sys.stdout.flush()
61  sys.exit(gyp.main(sys.argv[1:] + [
62      '--check',
63      '--no-circular-check',
64      '-I', os.path.join(script_dir, 'common.gypi'),
65      '-D', 'gyp_output_dir=out']))
66
67if __name__ == '__main__':
68  sys.exit(main())
69