commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 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 | Script for generating the Android framework's version of Skia from gyp |
| 10 | files. |
| 11 | """ |
| 12 | |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 13 | import os |
| 14 | import shutil |
| 15 | import sys |
| 16 | import tempfile |
| 17 | |
| 18 | # Find the top of trunk |
| 19 | SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 20 | SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
| 21 | os.pardir)) |
| 22 | |
| 23 | # Find the directory with our helper files, and add it to the path. |
commit-bot@chromium.org | a398757 | 2014-04-29 00:39:45 +0000 | [diff] [blame] | 24 | ANDROID_TOOLS = os.path.join(SKIA_DIR, 'platform_tools', 'android') |
| 25 | sys.path.append(ANDROID_TOOLS) |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | a398757 | 2014-04-29 00:39:45 +0000 | [diff] [blame] | 27 | import gyp_gen.android_framework_gyp as android_framework_gyp |
| 28 | import gyp_gen.gypd_parser as gypd_parser |
| 29 | import gyp_gen.generate_user_config as generate_user_config |
| 30 | import gyp_gen.makefile_writer as makefile_writer |
| 31 | import gyp_gen.tool_makefile_writer as tool_makefile_writer |
| 32 | import gyp_gen.vars_dict_lib as vars_dict_lib |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 33 | |
| 34 | # Folder containing all gyp files and generated gypd files. |
| 35 | GYP_FOLDER = 'gyp' |
| 36 | |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 37 | |
| 38 | def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon): |
commit-bot@chromium.org | d665685 | 2014-04-28 16:00:30 +0000 | [diff] [blame] | 39 | """Create a VarsDict for a particular arch type. |
| 40 | |
| 41 | Each paramater is passed directly to android_framework_gyp.main(). |
| 42 | |
| 43 | Args: |
| 44 | target_dir: Directory containing gyp files. |
| 45 | target_file: Target gyp file. |
| 46 | skia_arch_type: Target architecture. |
| 47 | have_neon: Whether the target should build for neon. |
| 48 | Returns: |
| 49 | A VarsDict containing the variable definitions determined by gyp. |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 50 | """ |
| 51 | result_file = android_framework_gyp.main(target_dir, target_file, |
| 52 | skia_arch_type, have_neon) |
| 53 | var_dict = vars_dict_lib.VarsDict() |
commit-bot@chromium.org | d665685 | 2014-04-28 16:00:30 +0000 | [diff] [blame] | 54 | gypd_parser.parse_gypd(var_dict, result_file, '.') |
| 55 | android_framework_gyp.clean_gypd_files(target_dir) |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 56 | print '.', |
| 57 | return var_dict |
| 58 | |
commit-bot@chromium.org | ec68ee9 | 2014-04-21 14:45:01 +0000 | [diff] [blame] | 59 | def main(target_dir=None, require_sk_user_config=False): |
commit-bot@chromium.org | d665685 | 2014-04-28 16:00:30 +0000 | [diff] [blame] | 60 | """Create Android.mk for the Android framework's external/skia. |
| 61 | |
| 62 | Builds Android.mk using Skia's gyp files. |
| 63 | |
| 64 | Args: |
| 65 | target_dir: Directory in which to place 'Android.mk'. If None, the file |
| 66 | will be placed in skia's root directory. |
| 67 | require_sk_user_config: If True, raise an AssertionError if |
| 68 | SkUserConfig.h does not exist. |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 69 | """ |
| 70 | # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR |
| 71 | # so that it is a sibling of gyp/, so the relationships between gyp files and |
| 72 | # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced |
| 73 | # by android_deps.gyp as a relative path) is unchanged. |
| 74 | # Use mkdtemp to find an unused folder name, but then delete it so copytree |
| 75 | # can be called with a non-existent directory. |
| 76 | tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR) |
| 77 | os.rmdir(tmp_folder) |
| 78 | shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder) |
| 79 | |
| 80 | try: |
| 81 | main_gyp_file = 'android_framework_lib.gyp' |
| 82 | |
| 83 | print 'Creating Android.mk', |
| 84 | |
| 85 | # Generate a separate VarsDict for each architecture type. For each |
| 86 | # archtype: |
| 87 | # 1. call android_framework_gyp.main() to generate gypd files |
| 88 | # 2. call parse_gypd to read those gypd files into the VarsDict |
| 89 | # 3. delete the gypd files |
| 90 | # |
| 91 | # Once we have the VarsDict for each architecture type, we combine them all |
| 92 | # into a single Android.mk file, which can build targets of any |
| 93 | # architecture type. |
| 94 | |
| 95 | # The default uses a non-existant archtype, to find all the general |
| 96 | # variable definitions. |
| 97 | default_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'other', |
| 98 | False) |
| 99 | arm_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm', False) |
| 100 | arm_neon_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm', |
| 101 | True) |
commit-bot@chromium.org | 069c2a4 | 2014-02-28 17:24:32 +0000 | [diff] [blame] | 102 | x86_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'x86', False) |
| 103 | |
| 104 | mips_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'mips', False) |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 105 | |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 106 | arm64_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm64', |
| 107 | False) |
| 108 | |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 109 | # Compute the intersection of all targets. All the files in the intersection |
| 110 | # should be part of the makefile always. Each dict will now contain trimmed |
| 111 | # lists containing only variable definitions specific to that configuration. |
commit-bot@chromium.org | 069c2a4 | 2014-02-28 17:24:32 +0000 | [diff] [blame] | 112 | var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict, |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 113 | x86_var_dict, mips_var_dict, arm64_var_dict] |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 114 | common = vars_dict_lib.intersect(var_dict_list) |
| 115 | |
commit-bot@chromium.org | d665685 | 2014-04-28 16:00:30 +0000 | [diff] [blame] | 116 | common.LOCAL_MODULE.add('libskia') |
| 117 | |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 118 | # Create SkUserConfig |
| 119 | user_config = os.path.join(SKIA_DIR, 'include', 'config', 'SkUserConfig.h') |
| 120 | if target_dir: |
| 121 | dst_dir = target_dir |
| 122 | else: |
| 123 | dst_dir = os.path.join(SKIA_DIR, 'include', 'core') |
| 124 | |
| 125 | generate_user_config.generate_user_config( |
commit-bot@chromium.org | ec68ee9 | 2014-04-21 14:45:01 +0000 | [diff] [blame] | 126 | original_sk_user_config=user_config, |
| 127 | require_sk_user_config=require_sk_user_config, target_dir=dst_dir, |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 128 | ordered_set=common.DEFINES) |
| 129 | |
commit-bot@chromium.org | d665685 | 2014-04-28 16:00:30 +0000 | [diff] [blame] | 130 | tool_makefile_writer.generate_tool(gyp_dir=tmp_folder, |
| 131 | target_file='tests.gyp', |
| 132 | skia_trunk=target_dir, |
| 133 | dest_dir='tests', |
| 134 | skia_lib_var_dict=common, |
| 135 | local_module_name='skia_test', |
| 136 | local_module_tags=['eng', 'tests']) |
| 137 | |
| 138 | # TODO (scroggo): Generate bench/Android.mk. See skbug.com/2448 |
| 139 | #tool_makefile_writer.generate_tool(gyp_dir=tmp_folder, |
| 140 | # target_file='bench.gyp', |
| 141 | # skia_trunk=target_dir, |
| 142 | # dest_dir='bench', |
| 143 | # skia_lib_var_dict=common, |
| 144 | # local_module_name='skia_bench', |
| 145 | # local_module_tags=['tests']) |
| 146 | |
| 147 | # Now that the defines have been written to SkUserConfig and they've been |
| 148 | # used to skip adding them to the tools makefiles, they are not needed in |
| 149 | # Android.mk. Reset DEFINES. |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 150 | common.DEFINES.reset() |
| 151 | |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 152 | # Further trim arm_neon_var_dict with arm_var_dict. After this call, |
| 153 | # arm_var_dict (which will now be the intersection) includes all definitions |
| 154 | # used by both arm and arm + neon, and arm_neon_var_dict will only contain |
| 155 | # those specific to arm + neon. |
| 156 | arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict]) |
| 157 | |
commit-bot@chromium.org | 069c2a4 | 2014-02-28 17:24:32 +0000 | [diff] [blame] | 158 | # Now create a list of VarsDictData holding everything but common. |
| 159 | deviations_from_common = [] |
| 160 | deviations_from_common.append(makefile_writer.VarsDictData( |
| 161 | arm_var_dict, 'arm')) |
| 162 | deviations_from_common.append(makefile_writer.VarsDictData( |
| 163 | arm_neon_var_dict, 'arm', 'ARCH_ARM_HAVE_NEON')) |
| 164 | deviations_from_common.append(makefile_writer.VarsDictData(x86_var_dict, |
| 165 | 'x86')) |
| 166 | # Currently, x86_64 is identical to x86 |
| 167 | deviations_from_common.append(makefile_writer.VarsDictData(x86_var_dict, |
| 168 | 'x86_64')) |
| 169 | |
| 170 | deviations_from_common.append(makefile_writer.VarsDictData(mips_var_dict, |
| 171 | 'mips')) |
| 172 | |
commit-bot@chromium.org | ba0c5ea | 2014-03-28 15:59:04 +0000 | [diff] [blame] | 173 | deviations_from_common.append(makefile_writer.VarsDictData(arm64_var_dict, |
| 174 | 'arm64')) |
| 175 | |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 176 | makefile_writer.write_android_mk(target_dir=target_dir, |
commit-bot@chromium.org | 069c2a4 | 2014-02-28 17:24:32 +0000 | [diff] [blame] | 177 | common=common, deviations_from_common=deviations_from_common) |
commit-bot@chromium.org | 8933563 | 2014-02-06 16:13:00 +0000 | [diff] [blame] | 178 | |
| 179 | finally: |
| 180 | shutil.rmtree(tmp_folder) |
| 181 | |
| 182 | if __name__ == '__main__': |
| 183 | main() |