Mike Klein | 552cd13 | 2016-10-26 13:32:07 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2016 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | import os |
| 9 | import sys |
| 10 | |
| 11 | # We'll read a single named list of paths from a .gni file. |
| 12 | gni, name = sys.argv[1:] |
| 13 | |
| 14 | # The .gni files we want to read are close enough to Python syntax |
| 15 | # that we can use execfile() if we supply definitions for GN builtins. |
| 16 | |
| 17 | def get_path_info(path, kind): |
| 18 | assert kind == "abspath" |
| 19 | # While we want absolute paths in GN, GYP prefers relative paths. |
| 20 | return path |
| 21 | |
| 22 | builtins = { |
| 23 | 'get_path_info': get_path_info, |
| 24 | } |
| 25 | definitions = {} |
| 26 | execfile(gni, builtins, definitions) |
| 27 | |
| 28 | # definitions now holds all the values defined in the .gni. |
| 29 | paths = definitions[name] |
| 30 | |
| 31 | # Perform any string substitutions. |
| 32 | for var in definitions: |
| 33 | if type(definitions[var]) is str: |
| 34 | paths = [ p.replace('$'+var, definitions[var]) for p in paths ] |
| 35 | |
| 36 | # Print the path list, to be received by <!@ syntax in GYP. |
| 37 | for p in paths: |
| 38 | print p |