dump_build_config_gyp.py 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# Copyright 2017 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""The same as dump_build_config.py but for gyp legacy.

Expected to be called like:
dump_build_config.py path/to/file.json [key1=value1 ...]

Raw gyp values are supported - they will be tranformed into valid json.
"""
# TODO(machenbach): Remove this when gyp is deprecated.

14 15 16
# for py2/py3 compatibility
from __future__ import print_function

17 18 19 20 21 22 23 24 25
import json
import os
import sys

assert len(sys.argv) > 2


GYP_GN_CONVERSION = {
  'is_component_build': {
26 27
    'shared_library': 'true',
    'static_library': 'false',
28 29
  },
  'is_debug': {
30 31
    'Debug': 'true',
    'Release': 'false',
32 33 34 35 36 37
  },
}

DEFAULT_CONVERSION ={
  '0': 'false',
  '1': 'true',
38
  'ia32': 'x86',
39 40 41
}

def gyp_to_gn(key, value):
42 43 44
  value = GYP_GN_CONVERSION.get(key, DEFAULT_CONVERSION).get(value, value)
  value = value if value in ['true', 'false'] else '"{0}"'.format(value)
  return value
45 46 47 48

def as_json(kv):
  assert '=' in kv
  k, v = kv.split('=', 1)
49 50 51 52
  v2 = gyp_to_gn(k, v)
  try:
    return k, json.loads(v2)
  except ValueError as e:
53
    print((k, v, v2))
54
    raise e
55 56 57

with open(sys.argv[1], 'w') as f:
  json.dump(dict(map(as_json, sys.argv[2:])), f)