aboutsummaryrefslogtreecommitdiffhomepage
path: root/gyp/read_gni.py
blob: b8a7b39de82fcbbac77d1b6e28b80b26965a7a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
#
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys

# We'll read a single named list of paths from a .gni file.
gni, name = sys.argv[1:]

# The .gni files we want to read are close enough to Python syntax
# that we can use execfile() if we supply definitions for GN builtins.

def get_path_info(path, kind):
  assert kind == "abspath"
  # While we want absolute paths in GN, GYP prefers relative paths.
  return path

builtins = {
  'get_path_info': get_path_info,
}
definitions = {}
execfile(gni, builtins, definitions)

# definitions now holds all the values defined in the .gni.
paths = definitions[name]

# Perform any string substitutions.
for var in definitions:
  if type(definitions[var]) is str:
    paths = [ p.replace('$'+var, definitions[var]) for p in paths ]

# Print the path list, to be received by <!@ syntax in GYP.
for p in paths:
  print p