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"""Code for generating Android.mk for a tool.""" 9 10 11import android_framework_gyp 12import gypd_parser 13import makefile_writer 14import os 15import vars_dict_lib 16 17SKIA_RESOURCES = ( 18""" 19# Store skia's resources in the directory structure that the Android testing 20# infrastructure expects. This requires that Skia maintain a symlinked 21# subdirectory in the DATA folder that points to the top level skia resources... 22# i.e. external/skia/DATA/skia_resources --> ../resources 23LOCAL_PICKUP_FILES := $(LOCAL_PATH)/../DATA 24""" 25) 26 27def write_tool_android_mk(target_dir, var_dict): 28 """Write Android.mk for a Skia tool. 29 30 Args: 31 target_dir: Destination for the makefile. Must not be None. 32 var_dict: VarsDict containing variables for the makefile. 33 """ 34 target_file = os.path.join(target_dir, 'Android.mk') 35 with open(target_file, 'w') as f: 36 f.write(makefile_writer.AUTOGEN_WARNING) 37 38 f.write(makefile_writer.LOCAL_PATH) 39 f.write(makefile_writer.CLEAR_VARS) 40 41 makefile_writer.write_local_vars(f, var_dict, False, None) 42 43 f.write(SKIA_RESOURCES) 44 f.write('include $(LOCAL_PATH)/../skia_static_deps.mk\n') 45 if 'libhwui_static' in var_dict['LOCAL_STATIC_LIBRARIES']: 46 f.write('include frameworks/base/libs/hwui/hwui_static_deps.mk\n') 47 f.write('include $(BUILD_NATIVE_TEST)\n') 48 49 50def generate_tool(gyp_dir, target_file, skia_trunk, dest_dir, 51 skia_lib_var_dict, local_module_name, local_module_tags, 52 desired_targets, gyp_source_dir=None): 53 """Common steps for building one of the skia tools. 54 55 Parse a gyp file and create an Android.mk for this tool. 56 57 Args: 58 gyp_dir: Directory containing gyp files. 59 target_file: gyp file for the project to be built, contained in gyp_dir. 60 skia_trunk: Trunk of Skia, used for determining the destination to write 61 'Android.mk'. 62 dest_dir: Destination for 'Android.mk', relative to skia_trunk. Used for 63 both writing relative paths in the makefile and for determining the 64 destination to write the it. 65 skia_lib_var_dict: VarsDict representing libskia. Used as a reference to 66 ensure we do not duplicate anything in this Android.mk. 67 local_module_name: Name for this tool, to set as LOCAL_MODULE. 68 local_module_tags: Tags to pass to LOCAL_MODULE_TAG. 69 desired_targets: List of targets to parse. 70 gyp_source_dir: Source directory for gyp. 71 """ 72 result_file = android_framework_gyp.main(target_dir=gyp_dir, 73 target_file=target_file, 74 skia_arch_type='other', 75 have_neon=False, 76 gyp_source_dir=gyp_source_dir) 77 78 var_dict = vars_dict_lib.VarsDict() 79 80 # Add known targets from skia_lib, so we do not reparse them. 81 var_dict.KNOWN_TARGETS.set(skia_lib_var_dict.KNOWN_TARGETS) 82 83 gypd_parser.parse_gypd(var_dict, result_file, dest_dir, desired_targets) 84 85 android_framework_gyp.clean_gypd_files(gyp_dir) 86 87 var_dict.LOCAL_MODULE.add(local_module_name) 88 for tag in local_module_tags: 89 var_dict.LOCAL_MODULE_TAGS.add(tag) 90 91 # No need for defines that are already in skia_lib. 92 for define in skia_lib_var_dict.DEFINES: 93 try: 94 var_dict.DEFINES.remove(define) 95 except ValueError: 96 # Okay if the define was not part of the parse for our tool. 97 pass 98 99 if skia_trunk: 100 full_dest = os.path.join(skia_trunk, dest_dir) 101 else: 102 full_dest = dest_dir 103 104 # If the path does not exist, create it. This will happen during testing, 105 # where there is no subdirectory for each tool (just a temporary folder). 106 if not os.path.exists(full_dest): 107 os.mkdir(full_dest) 108 109 write_tool_android_mk(target_dir=full_dest, var_dict=var_dict) 110