Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: platform_tools/android/gyp_gen/gypd_parser.py

Issue 140503007: Scripts to generate Android.mk for framework Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Respond to Elliot's comments in patch set 20. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright 2014 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 """
9 Functions for parsing the gypd output from gyp.
10 """
11
12 import vars_dict_lib
13
14 def parse_dictionary(var_dict, d, current_target_name):
15 """
16 Helper function to get the meaningful entries in a dictionary.
17 @param var_dict VarsDict object for storing the results of the parsing.
18 @param d Dictionary object to parse.
19 @param current_target_name The current target being parsed. If this
20 dictionary is a target, this will be its entry
21 'target_name'. Otherwise, this will be the name of
22 the target which contains this dictionary.
23 """
24 for source in d.get('sources', []):
25 # Compare against a lowercase version, in case files are named .H or .GYPI
26 lowercase_source = source.lower()
27 if lowercase_source.endswith('.h'):
28 # Android.mk does not need the header files.
29 continue
30 if lowercase_source.endswith('gypi'):
31 # The gypi files are included in sources, but the sources they included
32 # are also included. No need to parse them again.
33 continue
34 # The path is relative to the gyp folder, but Android wants the path
35 # relative to the root.
36 source = source.replace('../src', 'src', 1)
37 var_dict.LOCAL_SRC_FILES.add(source)
38
39 for lib in d.get('libraries', []):
40 if lib.endswith('.a'):
41 # Remove the '.a'
42 lib = lib[:-2]
43 # Add 'lib', if necessary
44 if not lib.startswith('lib'):
45 lib = 'lib' + lib
46 var_dict.LOCAL_STATIC_LIBRARIES.add(lib)
47 else:
48 # lib will be in the form of '-l<name>'. Change it to 'lib<name>'
49 lib = lib.replace('-l', 'lib', 1)
50 var_dict.LOCAL_SHARED_LIBRARIES.add(lib)
51
52 for dependency in d.get('dependencies', []):
53 # Each dependency is listed as
54 # <path_to_file>:<target>#target
55 li = dependency.split(':')
56 assert(len(li) <= 2 and len(li) >= 1)
57 sub_targets = []
58 if len(li) == 2 and li[1] != '*':
59 sub_targets.append(li[1].split('#')[0])
60 sub_path = li[0]
61 assert(sub_path.endswith('.gyp'))
62 # Although the original reference is to a .gyp, parse the corresponding
63 # gypd file, which was constructed by gyp.
64 sub_path = sub_path + 'd'
65 parse_gypd(var_dict, sub_path, sub_targets)
66
67 if 'default_configuration' in d:
68 config_name = d['default_configuration']
69 # default_configuration is meaningless without configurations
70 assert('configurations' in d)
71 config = d['configurations'][config_name]
72 parse_dictionary(var_dict, config, current_target_name)
73
74 for flag in d.get('cflags', []):
75 var_dict.LOCAL_CFLAGS.add(flag)
76 for flag in d.get('cflags_cc', []):
77 var_dict.LOCAL_CPPFLAGS.add(flag)
78
79 for include in d.get('include_dirs', []):
80 # The input path will be relative to gyp/, but Android wants relative to
81 # LOCAL_PATH
82 include = include.replace('..', '$(LOCAL_PATH)', 1)
83 # Remove a trailing slash, if present.
84 if include.endswith('/'):
85 include = include[:-1]
86 var_dict.LOCAL_C_INCLUDES.add(include)
87 # For the top level, libskia, include directories should be exported.
88 if current_target_name == 'libskia':
89 var_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(include)
90
91 for define in d.get('defines', []):
92 var_dict.LOCAL_CFLAGS.add('-D' + define)
93
94
95 def parse_gypd(var_dict, path, desired_targets=None):
96 """
97 Parse a gypd file.
98 @param var_dict VarsDict object for storing the result of the parse.
99 @param path Path to gypd file.
100 @param desired_targets List of targets to be parsed from this file. If empty,
101 parse all targets.
102 """
103 d = {}
104 with open(path, 'r') as f:
105 # Read the entire file as a dictionary
106 d = eval(f.read())
107
108 # The gypd file is structured such that the top level dictionary has an entry
109 # named 'targets'
110 for target in d['targets']:
111 target_name = target['target_name']
112 if target_name in var_dict.KNOWN_TARGETS:
113 # Avoid circular dependencies
114 continue
115 if desired_targets and target_name not in desired_targets:
116 # Our caller does not depend on this one
117 continue
118 # Add it to our known targets so we don't parse it again
119 var_dict.KNOWN_TARGETS.add(target_name)
120
121 parse_dictionary(var_dict, target, target_name)
122
OLDNEW
« no previous file with comments | « platform_tools/android/bin/gyp_to_android.py ('k') | platform_tools/android/gyp_gen/makefile_writer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698