• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 the V8 project 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"""The same as dump_build_config.py but for gyp legacy.
6
7Expected to be called like:
8dump_build_config.py path/to/file.json [key1=value1 ...]
9
10Raw gyp values are supported - they will be tranformed into valid json.
11"""
12# TODO(machenbach): Remove this when gyp is deprecated.
13
14import json
15import os
16import sys
17
18assert len(sys.argv) > 2
19
20
21GYP_GN_CONVERSION = {
22  'is_component_build': {
23    'shared_library': 'true',
24    'static_library': 'false',
25  },
26  'is_debug': {
27    'Debug': 'true',
28    'Release': 'false',
29  },
30}
31
32DEFAULT_CONVERSION ={
33  '0': 'false',
34  '1': 'true',
35  'ia32': 'x86',
36}
37
38def gyp_to_gn(key, value):
39  value = GYP_GN_CONVERSION.get(key, DEFAULT_CONVERSION).get(value, value)
40  value = value if value in ['true', 'false'] else '"{0}"'.format(value)
41  return value
42
43def as_json(kv):
44  assert '=' in kv
45  k, v = kv.split('=', 1)
46  v2 = gyp_to_gn(k, v)
47  try:
48    return k, json.loads(v2)
49  except ValueError as e:
50    print((k, v, v2))
51    raise e
52
53with open(sys.argv[1], 'w') as f:
54  json.dump(dict(map(as_json, sys.argv[2:])), f)
55