blob: e88539964482018b768e460aa35fada7105b7185 [file] [log] [blame]
commit-bot@chromium.org89335632014-02-06 16:13:00 +00001#!/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"""
9Script for generating the Android framework's version of Skia from gyp
10files.
11"""
12
commit-bot@chromium.org89335632014-02-06 16:13:00 +000013import os
14import shutil
15import sys
16import tempfile
17
18# Find the top of trunk
19SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
20SKIA_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.orga3987572014-04-29 00:39:45 +000024ANDROID_TOOLS = os.path.join(SKIA_DIR, 'platform_tools', 'android')
25sys.path.append(ANDROID_TOOLS)
commit-bot@chromium.org89335632014-02-06 16:13:00 +000026
commit-bot@chromium.orga3987572014-04-29 00:39:45 +000027import gyp_gen.android_framework_gyp as android_framework_gyp
28import gyp_gen.gypd_parser as gypd_parser
29import gyp_gen.generate_user_config as generate_user_config
30import gyp_gen.makefile_writer as makefile_writer
31import gyp_gen.tool_makefile_writer as tool_makefile_writer
32import gyp_gen.vars_dict_lib as vars_dict_lib
commit-bot@chromium.org89335632014-02-06 16:13:00 +000033
34# Folder containing all gyp files and generated gypd files.
35GYP_FOLDER = 'gyp'
36
commit-bot@chromium.org89335632014-02-06 16:13:00 +000037
38def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon):
commit-bot@chromium.orgd6656852014-04-28 16:00:30 +000039 """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.org89335632014-02-06 16:13:00 +000050 """
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.orgd6656852014-04-28 16:00:30 +000054 gypd_parser.parse_gypd(var_dict, result_file, '.')
55 android_framework_gyp.clean_gypd_files(target_dir)
commit-bot@chromium.org89335632014-02-06 16:13:00 +000056 print '.',
57 return var_dict
58
commit-bot@chromium.orgec68ee92014-04-21 14:45:01 +000059def main(target_dir=None, require_sk_user_config=False):
commit-bot@chromium.orgd6656852014-04-28 16:00:30 +000060 """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.org89335632014-02-06 16:13:00 +000069 """
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.org069c2a42014-02-28 17:24:32 +0000102 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.org89335632014-02-06 16:13:00 +0000105
commit-bot@chromium.orgba0c5ea2014-03-28 15:59:04 +0000106 arm64_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm64',
107 False)
108
commit-bot@chromium.org89335632014-02-06 16:13:00 +0000109 # 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.org069c2a42014-02-28 17:24:32 +0000112 var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict,
commit-bot@chromium.orgba0c5ea2014-03-28 15:59:04 +0000113 x86_var_dict, mips_var_dict, arm64_var_dict]
commit-bot@chromium.org89335632014-02-06 16:13:00 +0000114 common = vars_dict_lib.intersect(var_dict_list)
115
commit-bot@chromium.orgd6656852014-04-28 16:00:30 +0000116 common.LOCAL_MODULE.add('libskia')
117
commit-bot@chromium.orgba0c5ea2014-03-28 15:59:04 +0000118 # 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.orgec68ee92014-04-21 14:45:01 +0000126 original_sk_user_config=user_config,
127 require_sk_user_config=require_sk_user_config, target_dir=dst_dir,
commit-bot@chromium.orgba0c5ea2014-03-28 15:59:04 +0000128 ordered_set=common.DEFINES)
129
commit-bot@chromium.orgd6656852014-04-28 16:00:30 +0000130 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.orgba0c5ea2014-03-28 15:59:04 +0000150 common.DEFINES.reset()
151
commit-bot@chromium.org89335632014-02-06 16:13:00 +0000152 # 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.org069c2a42014-02-28 17:24:32 +0000158 # 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.orgba0c5ea2014-03-28 15:59:04 +0000173 deviations_from_common.append(makefile_writer.VarsDictData(arm64_var_dict,
174 'arm64'))
175
commit-bot@chromium.org89335632014-02-06 16:13:00 +0000176 makefile_writer.write_android_mk(target_dir=target_dir,
commit-bot@chromium.org069c2a42014-02-28 17:24:32 +0000177 common=common, deviations_from_common=deviations_from_common)
commit-bot@chromium.org89335632014-02-06 16:13:00 +0000178
179 finally:
180 shutil.rmtree(tmp_folder)
181
182if __name__ == '__main__':
183 main()