Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright 2014 Google Inc. | 3 # Copyright 2014 Google Inc. |
| 4 # | 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
| 7 | 7 |
| 8 """ | 8 """ |
| 9 Functions for creating an Android.mk from already created dictionaries. | 9 Functions for creating an Android.mk from already created dictionaries. |
| 10 """ | 10 """ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 # | 119 # |
| 120 | 120 |
| 121 # benchmark (timings) | 121 # benchmark (timings) |
| 122 include $(BASE_PATH)/bench/Android.mk | 122 include $(BASE_PATH)/bench/Android.mk |
| 123 | 123 |
| 124 # diamond-master (one test to rule them all) | 124 # diamond-master (one test to rule them all) |
| 125 include $(BASE_PATH)/dm/Android.mk | 125 include $(BASE_PATH)/dm/Android.mk |
| 126 """ | 126 """ |
| 127 ) | 127 ) |
| 128 | 128 |
| 129 STATIC_HEADER = ( | |
| 130 """ | |
| 131 ############################################################################### | |
| 132 # STATIC LIBRARY | |
| 133 # | |
| 134 # This target is only to be used internally for only one of two purposes... | |
| 135 # (1) statically linking into testing frameworks | |
| 136 # (2) as an inclusion target for the libskia.so shared library | |
| 137 ############################################################################### | |
| 138 | |
| 139 """ | |
| 140 ) | |
| 141 | |
| 142 SHARED_HEADER = ( | |
| 143 """ | |
| 144 ############################################################################### | |
| 145 # SHARED LIBRARY | |
| 146 ############################################################################### | |
| 147 | |
| 148 """ | |
| 149 ) | |
| 150 | |
| 151 STATIC_DEPS_INFO = ( | |
| 152 """ | |
| 153 ############################################################################### | |
| 154 # | |
| 155 # This file contains the shared and static dependencies needed by any target | |
| 156 # that attempts to statically link Skia (i.e. libskia_static build target). | |
| 157 # | |
| 158 # This is a workaround for the fact that the build system does not add these | |
| 159 # transitive dependencies when it attempts to link libskia_static into another | |
| 160 # library. | |
| 161 # | |
| 162 ############################################################################### | |
| 163 | |
| 164 """ | |
| 165 ) | |
| 129 | 166 |
| 130 class VarsDictData(object): | 167 class VarsDictData(object): |
| 131 """Helper class to keep a VarsDict along with a name and optional condition. | 168 """Helper class to keep a VarsDict along with a name and optional condition. |
| 132 """ | 169 """ |
| 133 def __init__(self, vars_dict, name, condition=None): | 170 def __init__(self, vars_dict, name, condition=None): |
| 134 """Create a new VarsDictData. | 171 """Create a new VarsDictData. |
| 135 | 172 |
| 136 Args: | 173 Args: |
| 137 vars_dict: A VarsDict. Can be accessed via self.vars_dict. | 174 vars_dict: A VarsDict. Can be accessed via self.vars_dict. |
| 138 name: Name associated with the VarsDict. Can be accessed via | 175 name: Name associated with the VarsDict. Can be accessed via |
| 139 self.name. | 176 self.name. |
| 140 condition: Optional string representing a condition. If not None, | 177 condition: Optional string representing a condition. If not None, |
| 141 used to create a conditional inside the makefile. | 178 used to create a conditional inside the makefile. |
| 142 """ | 179 """ |
| 143 self.vars_dict = vars_dict | 180 self.vars_dict = vars_dict |
| 144 self.condition = condition | 181 self.condition = condition |
| 145 self.name = name | 182 self.name = name |
| 146 | 183 |
| 147 def write_local_path(f): | 184 def write_static_includes_mk(target_dir, common, deviations_from_common): |
|
scroggo
2016/02/11 21:35:33
Why did you inline this?
djsollen
2016/02/12 13:36:38
In both cases reading through the code I had to go
scroggo
2016/02/12 15:00:31
The point is that the interpreter will catch you i
| |
| 148 """Add the LOCAL_PATH line to the makefile. | 185 """Given all the variables, write the final make file. |
| 149 | 186 |
| 150 Args: | 187 Args: |
| 151 f: File open for writing. | 188 target_dir: The full path to the directory to write skia_static_includes.mk, |
| 189 or None to use the current working directory. | |
| 190 common: VarsDict holding variables definitions common to all | |
| 191 configurations. | |
| 192 deviations_from_common: List of VarsDictData, one for each possible | |
| 193 configuration. VarsDictData.name will be appended to each key before | |
| 194 writing it to the makefile. VarsDictData.condition, if not None, will be | |
| 195 written to the makefile as a condition to determine whether to include | |
| 196 VarsDictData.vars_dict. | |
| 152 """ | 197 """ |
| 153 f.write('LOCAL_PATH:= $(call my-dir)\n') | 198 target_file = 'skia_static_deps.mk' |
| 199 if target_dir: | |
| 200 target_file = os.path.join(target_dir, target_file) | |
| 201 with open(target_file, 'w') as f: | |
| 202 f.write(AUTOGEN_WARNING) | |
| 203 f.write(STATIC_DEPS_INFO) | |
| 154 | 204 |
| 155 def write_clear_vars(f): | 205 for data in deviations_from_common: |
|
scroggo
2016/02/11 21:35:33
Ditto.
| |
| 156 """Add the CLEAR_VARS line to the makefile. | 206 var_dict_shared = data.vars_dict['LOCAL_SHARED_LIBRARIES'] |
| 207 var_dict_static = data.vars_dict['LOCAL_STATIC_LIBRARIES'] | |
| 208 if data.condition and (var_dict_shared or var_dict_static): | |
| 209 f.write('ifeq ($(%s), true)\n' % data.condition) | |
| 210 write_group(f, 'LOCAL_SHARED_LIBRARIES', var_dict_shared, True) | |
| 211 write_group(f, 'LOCAL_STATIC_LIBRARIES', var_dict_static, True) | |
| 212 if data.condition and (var_dict_shared or var_dict_static): | |
| 213 f.write('endif\n\n') | |
| 157 | 214 |
| 158 Args: | 215 write_group(f, 'LOCAL_SHARED_LIBRARIES', common['LOCAL_SHARED_LIBRARIES'], |
| 159 f: File open for writing. | 216 True) |
| 160 """ | 217 write_group(f, 'LOCAL_STATIC_LIBRARIES', common['LOCAL_STATIC_LIBRARIES'], |
| 161 f.write('include $(CLEAR_VARS)\n') | 218 True) |
| 219 | |
| 162 | 220 |
| 163 def write_android_mk(target_dir, common, deviations_from_common): | 221 def write_android_mk(target_dir, common, deviations_from_common): |
| 164 """Given all the variables, write the final make file. | 222 """Given all the variables, write the final make file. |
| 165 | 223 |
| 166 Args: | 224 Args: |
| 167 target_dir: The full path to the directory to write Android.mk, or None | 225 target_dir: The full path to the directory to write Android.mk, or None |
| 168 to use the current working directory. | 226 to use the current working directory. |
| 169 common: VarsDict holding variables definitions common to all | 227 common: VarsDict holding variables definitions common to all |
| 170 configurations. | 228 configurations. |
| 171 deviations_from_common: List of VarsDictData, one for each possible | 229 deviations_from_common: List of VarsDictData, one for each possible |
| 172 configuration. VarsDictData.name will be appended to each key before | 230 configuration. VarsDictData.name will be appended to each key before |
| 173 writing it to the makefile. VarsDictData.condition, if not None, will be | 231 writing it to the makefile. VarsDictData.condition, if not None, will be |
| 174 written to the makefile as a condition to determine whether to include | 232 written to the makefile as a condition to determine whether to include |
| 175 VarsDictData.vars_dict. | 233 VarsDictData.vars_dict. |
| 176 """ | 234 """ |
| 177 target_file = 'Android.mk' | 235 target_file = 'Android.mk' |
| 178 if target_dir: | 236 if target_dir: |
| 179 target_file = os.path.join(target_dir, target_file) | 237 target_file = os.path.join(target_dir, target_file) |
| 180 with open(target_file, 'w') as f: | 238 with open(target_file, 'w') as f: |
| 181 f.write(AUTOGEN_WARNING) | 239 f.write(AUTOGEN_WARNING) |
| 182 f.write('BASE_PATH := $(call my-dir)\n') | 240 f.write('BASE_PATH := $(call my-dir)\n') |
| 183 write_local_path(f) | 241 f.write('LOCAL_PATH := $(call my-dir)\n') |
| 184 | 242 |
| 185 f.write(DEBUGGING_HELP) | 243 f.write(DEBUGGING_HELP) |
| 186 | 244 |
| 187 write_clear_vars(f) | 245 f.write(STATIC_HEADER) |
| 246 f.write('include $(CLEAR_VARS)\n\n') | |
| 188 | 247 |
| 189 # need flags to enable feedback driven optimization (FDO) when requested | 248 # need flags to enable feedback driven optimization (FDO) when requested |
| 190 # by the build system. | 249 # by the build system. |
| 191 f.write('LOCAL_FDO_SUPPORT := true\n') | 250 f.write('LOCAL_FDO_SUPPORT := true\n') |
| 192 f.write('ifneq ($(strip $(TARGET_FDO_CFLAGS)),)\n') | 251 f.write('ifneq ($(strip $(TARGET_FDO_CFLAGS)),)\n') |
| 193 f.write('\t# This should be the last -Oxxx specified in LOCAL_CFLAGS\n') | 252 f.write('\t# This should be the last -Oxxx specified in LOCAL_CFLAGS\n') |
| 194 f.write('\tLOCAL_CFLAGS += -O2\n') | 253 f.write('\tLOCAL_CFLAGS += -O2\n') |
| 195 f.write('endif\n\n') | 254 f.write('endif\n\n') |
| 196 | 255 |
| 197 f.write('LOCAL_ARM_MODE := thumb\n') | 256 f.write('LOCAL_ARM_MODE := thumb\n') |
| 198 | 257 |
| 199 f.write('# used for testing\n') | 258 f.write('# used for testing\n') |
| 200 f.write('#LOCAL_CFLAGS += -g -O0\n\n') | 259 f.write('#LOCAL_CFLAGS += -g -O0\n\n') |
| 201 | 260 |
| 202 f.write('ifeq ($(NO_FALLBACK_FONT),true)\n') | 261 # update the provided LOCAL_MODULE with a _static suffix |
| 203 f.write('\tLOCAL_CFLAGS += -DNO_FALLBACK_FONT\n') | 262 local_module = common['LOCAL_MODULE'][0] |
| 204 f.write('endif\n\n') | 263 static_local_module = local_module + '_static' |
| 264 common['LOCAL_MODULE'].reset() | |
| 265 common['LOCAL_MODULE'].add(static_local_module) | |
| 205 | 266 |
| 206 write_local_vars(f, common, False, None) | 267 write_local_vars(f, common, False, None) |
| 207 | 268 |
| 208 for data in deviations_from_common: | 269 for data in deviations_from_common: |
| 209 if data.condition: | 270 if data.condition: |
| 210 f.write('ifeq ($(%s), true)\n' % data.condition) | 271 f.write('ifeq ($(%s), true)\n' % data.condition) |
| 211 write_local_vars(f, data.vars_dict, True, data.name) | 272 write_local_vars(f, data.vars_dict, True, data.name) |
| 212 if data.condition: | 273 if data.condition: |
| 213 f.write('endif\n\n') | 274 f.write('endif\n\n') |
| 214 | 275 |
| 276 f.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n') | |
| 277 f.write('include $(BUILD_STATIC_LIBRARY)\n\n') | |
| 278 | |
| 279 f.write(SHARED_HEADER) | |
| 280 f.write('include $(CLEAR_VARS)\n\n') | |
| 281 f.write('LOCAL_MODULE_CLASS := SHARED_LIBRARIES\n') | |
| 282 f.write('LOCAL_MODULE := %s\n' % local_module) | |
| 283 f.write('LOCAL_WHOLE_STATIC_LIBRARIES := %s\n' % static_local_module) | |
| 284 write_group(f, 'LOCAL_EXPORT_C_INCLUDE_DIRS', | |
| 285 common['LOCAL_EXPORT_C_INCLUDE_DIRS'], False) | |
| 286 f.write('include $(BASE_PATH)/skia_static_deps.mk\n') | |
| 215 f.write('include $(BUILD_SHARED_LIBRARY)\n') | 287 f.write('include $(BUILD_SHARED_LIBRARY)\n') |
| 288 | |
| 216 f.write(SKIA_TOOLS) | 289 f.write(SKIA_TOOLS) |
| 217 | 290 |
| OLD | NEW |