Index: platform_tools/android/gyp_gen/gypd_parser.py |
diff --git a/platform_tools/android/gyp_gen/gypd_parser.py b/platform_tools/android/gyp_gen/gypd_parser.py |
index fc4dc68e96a5894c0e167cdab27163343af57a52..b0e1417046c872720823361be876932aec6ba9c3 100644 |
--- a/platform_tools/android/gyp_gen/gypd_parser.py |
+++ b/platform_tools/android/gyp_gen/gypd_parser.py |
@@ -5,19 +5,32 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-""" |
-Functions for parsing the gypd output from gyp. |
+"""Functions for parsing the gypd output from gyp. |
""" |
-def parse_dictionary(var_dict, d, current_target_name): |
- """ |
- Helper function to get the meaningful entries in a dictionary. |
- @param var_dict VarsDict object for storing the results of the parsing. |
- @param d Dictionary object to parse. |
- @param current_target_name The current target being parsed. If this |
- dictionary is a target, this will be its entry |
- 'target_name'. Otherwise, this will be the name of |
- the target which contains this dictionary. |
+ |
+import os |
+ |
+ |
+def parse_dictionary(var_dict, d, current_target_name, dest_dir): |
+ """Helper function to get the meaningful entries in a dictionary. |
+ |
+ Parse dictionary d, and store unique relevant entries in var_dict. |
+ Recursively parses internal dictionaries and files that are referenced. |
+ When parsing the 'libraries' list from gyp, entries in the form |
+ '-l<name>' get assigned to var_dict.LOCAL_SHARED_LIBRARIES as 'lib<name>', |
+ and entries in the form '[lib]<name>.a' get assigned to |
+ var_dict.LOCAL_STATIC_LIBRARIES as 'lib<name>'. |
+ |
+ Args: |
+ var_dict: VarsDict object for storing the results of the parsing. |
+ d: Dictionary object to parse. |
+ current_target_name: The current target being parsed. If this dictionary |
+ is a target, this will be its entry 'target_name'. Otherwise, this will |
+ be the name of the target which contains this dictionary. |
+ dest_dir: Destination for the eventual Android.mk that will be created from |
+ this parse, relative to Skia trunk. Used to determine path for source |
+ files. |
""" |
for source in d.get('sources', []): |
# Compare against a lowercase version, in case files are named .H or .GYPI |
@@ -30,9 +43,10 @@ def parse_dictionary(var_dict, d, current_target_name): |
# are also included. No need to parse them again. |
continue |
# The path is relative to the gyp folder, but Android wants the path |
- # relative to the root. |
- source = source.replace('../src', 'src', 1) |
- var_dict.LOCAL_SRC_FILES.add(source) |
+ # relative to dest_dir. |
+ rel_source = os.path.relpath(source, os.pardir) |
+ rel_source = os.path.relpath(rel_source, dest_dir) |
+ var_dict.LOCAL_SRC_FILES.add(rel_source) |
for lib in d.get('libraries', []): |
if lib.endswith('.a'): |
@@ -60,14 +74,14 @@ def parse_dictionary(var_dict, d, current_target_name): |
# Although the original reference is to a .gyp, parse the corresponding |
# gypd file, which was constructed by gyp. |
sub_path = sub_path + 'd' |
- parse_gypd(var_dict, sub_path, sub_targets) |
+ parse_gypd(var_dict, sub_path, dest_dir, sub_targets) |
if 'default_configuration' in d: |
config_name = d['default_configuration'] |
# default_configuration is meaningless without configurations |
assert('configurations' in d) |
config = d['configurations'][config_name] |
- parse_dictionary(var_dict, config, current_target_name) |
+ parse_dictionary(var_dict, config, current_target_name, dest_dir) |
for flag in d.get('cflags', []): |
var_dict.LOCAL_CFLAGS.add(flag) |
@@ -75,28 +89,44 @@ def parse_dictionary(var_dict, d, current_target_name): |
var_dict.LOCAL_CPPFLAGS.add(flag) |
for include in d.get('include_dirs', []): |
- # The input path will be relative to gyp/, but Android wants relative to |
- # LOCAL_PATH |
- include = include.replace('..', '$(LOCAL_PATH)', 1) |
+ if include.startswith('external'): |
+ # This path is relative to the Android root. Leave it alone. |
+ rel_include = include |
+ else: |
+ # As with source, the input path will be relative to gyp/, but Android |
+ # wants relative to dest_dir. |
+ rel_include = os.path.relpath(include, os.pardir) |
+ rel_include = os.path.relpath(rel_include, dest_dir) |
+ rel_include = os.path.join('$(LOCAL_PATH)', rel_include) |
+ |
# Remove a trailing slash, if present. |
- if include.endswith('/'): |
- include = include[:-1] |
- var_dict.LOCAL_C_INCLUDES.add(include) |
+ if rel_include.endswith('/'): |
+ rel_include = rel_include[:-1] |
+ var_dict.LOCAL_C_INCLUDES.add(rel_include) |
# For the top level, libskia, include directories should be exported. |
+ # FIXME (scroggo): Do not hard code this. |
if current_target_name == 'libskia': |
- var_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(include) |
+ var_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(rel_include) |
for define in d.get('defines', []): |
var_dict.DEFINES.add(define) |
-def parse_gypd(var_dict, path, desired_targets=None): |
- """ |
- Parse a gypd file. |
- @param var_dict VarsDict object for storing the result of the parse. |
- @param path Path to gypd file. |
- @param desired_targets List of targets to be parsed from this file. If empty, |
- parse all targets. |
+def parse_gypd(var_dict, path, dest_dir, desired_targets=None): |
+ """Parse a gypd file. |
+ |
+ Open a file that consists of python dictionaries representing build targets. |
+ Parse those dictionaries using parse_dictionary. Recursively parses |
+ referenced files. |
+ |
+ Args: |
+ var_dict: VarsDict object for storing the result of the parse. |
+ path: Path to gypd file. |
+ dest_dir: Destination for the eventual Android.mk that will be created from |
+ this parse, relative to Skia trunk. Used to determine path for source |
+ files and include directories. |
+ desired_targets: List of targets to be parsed from this file. If empty, |
+ parse all targets. |
""" |
d = {} |
with open(path, 'r') as f: |
@@ -116,5 +146,5 @@ def parse_gypd(var_dict, path, desired_targets=None): |
# Add it to our known targets so we don't parse it again |
var_dict.KNOWN_TARGETS.add(target_name) |
- parse_dictionary(var_dict, target, target_name) |
+ parse_dictionary(var_dict, target, target_name, dest_dir) |