3 # Copyright 2014 Google Inc.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
8 """Code for generating Android.mk for a tool."""
11 import android_framework_gyp
13 import makefile_writer
18 def write_tool_android_mk(target_dir, var_dict):
19 """Write Android.mk for a Skia tool.
22 target_dir: Destination for the makefile. Must not be None.
23 var_dict: VarsDict containing variables for the makefile.
25 target_file = os.path.join(target_dir, 'Android.mk')
26 with open(target_file, 'w') as f:
27 f.write(makefile_writer.AUTOGEN_WARNING)
29 makefile_writer.write_local_path(f)
30 makefile_writer.write_clear_vars(f)
32 makefile_writer.write_local_vars(f, var_dict, False, None)
34 makefile_writer.write_include_stlport(f)
36 f.write('include $(BUILD_NATIVE_TEST)\n')
39 def generate_tool(gyp_dir, target_file, skia_trunk, dest_dir,
40 skia_lib_var_dict, local_module_name, local_module_tags,
42 """Common steps for building one of the skia tools.
44 Parse a gyp file and create an Android.mk for this tool.
47 gyp_dir: Directory containing gyp files.
48 target_file: gyp file for the project to be built, contained in gyp_dir.
49 skia_trunk: Trunk of Skia, used for determining the destination to write
51 dest_dir: Destination for 'Android.mk', relative to skia_trunk. Used for
52 both writing relative paths in the makefile and for determining the
53 destination to write the it.
54 skia_lib_var_dict: VarsDict representing libskia. Used as a reference to
55 ensure we do not duplicate anything in this Android.mk.
56 local_module_name: Name for this tool, to set as LOCAL_MODULE.
57 local_module_tags: Tags to pass to LOCAL_MODULE_TAG.
58 desired_targets: List of targets to parse.
60 result_file = android_framework_gyp.main(target_dir=gyp_dir,
61 target_file=target_file,
62 skia_arch_type='other',
65 var_dict = vars_dict_lib.VarsDict()
67 # Add known targets from skia_lib, so we do not reparse them.
68 var_dict.KNOWN_TARGETS.set(skia_lib_var_dict.KNOWN_TARGETS)
70 gypd_parser.parse_gypd(var_dict, result_file, dest_dir, desired_targets)
72 android_framework_gyp.clean_gypd_files(gyp_dir)
74 var_dict.LOCAL_MODULE.add(local_module_name)
75 for tag in local_module_tags:
76 var_dict.LOCAL_MODULE_TAGS.add(tag)
78 # No need for defines that are already in skia_lib.
79 for define in skia_lib_var_dict.DEFINES:
81 var_dict.DEFINES.remove(define)
83 # Okay if the define was not part of the parse for our tool.
87 full_dest = os.path.join(skia_trunk, dest_dir)
91 # If the path does not exist, create it. This will happen during testing,
92 # where there is no subdirectory for each tool (just a temporary folder).
93 if not os.path.exists(full_dest):
96 write_tool_android_mk(target_dir=full_dest, var_dict=var_dict)