diff options
Diffstat (limited to 'platform_tools/android/bin')
-rw-r--r-- | platform_tools/android/bin/android_framework_gyp.py | 79 | ||||
-rw-r--r-- | platform_tools/android/bin/gyp_to_android.py | 134 |
2 files changed, 213 insertions, 0 deletions
diff --git a/platform_tools/android/bin/android_framework_gyp.py b/platform_tools/android/bin/android_framework_gyp.py new file mode 100644 index 0000000000..7654492f07 --- /dev/null +++ b/platform_tools/android/bin/android_framework_gyp.py @@ -0,0 +1,79 @@ +#!/usr/bin/python + +# Copyright 2014 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Modified version of gyp_skia, used by gyp_to_android.py to generate Android.mk +""" + +import os +import sys + +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) + +# Unlike gyp_skia, this file is nested deep inside Skia. Find Skia's trunk dir. +# This line depends on the fact that the script is three levels deep +# (specifically, it is in platform_tools/android/bin). +SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, + os.pardir)) +dir_contents = os.listdir(SKIA_DIR) +assert 'third_party' in dir_contents and 'gyp' in dir_contents + +# Directory within which we can find the gyp source. +GYP_SOURCE_DIR = os.path.join(SKIA_DIR, 'third_party', 'externals', 'gyp') + +# Ensure we import our current gyp source's module, not any version +# pre-installed in your PYTHONPATH. +sys.path.insert(0, os.path.join(GYP_SOURCE_DIR, 'pylib')) + +import gyp + +def main(target_dir, target_file, skia_arch_type, have_neon): + """ + Create gypd files based on target_file. + @param target_dir Directory containing all gyp files, including common.gypi + @param target_file Gyp file to start on. Other files within target_dir will + be read if target_file depends on them. + @param skia_arch_type Target architecture to pass to gyp. + @param have_neon Whether to generate files including neon optimizations. + Only meaningful if skia_arch_type is 'arm'. + @return path Path to root gypd file created by running gyp. + """ + # Set GYP_DEFINES for building for the android framework. + gyp_defines = ('skia_android_framework=1 OS=android skia_arch_type=%s ' + % skia_arch_type) + if skia_arch_type == 'arm': + # Always use thumb and version 7 for arm + gyp_defines += 'arm_thumb=1 arm_version=7 ' + if have_neon: + gyp_defines += 'arm_neon=1 ' + else: + gyp_defines += 'arm_neon=0 ' + + os.environ['GYP_DEFINES'] = gyp_defines + + args = [] + args.extend(['--depth', '.']) + full_path = os.path.join(target_dir, target_file) + args.extend([full_path]) + # Common conditions + args.extend(['-I', os.path.join(target_dir, 'common.gypi')]) + # Use the debugging format. We'll use these to create one master make file. + args.extend(['-f', 'gypd']) + + # Off we go... + ret = gyp.main(args) + + if ret != 0: + raise Exception("gyp failed!") + + # Running gyp should have created a gypd file, with the same name as + # full_path but with a 'd' on the end. + gypd_file = full_path + 'd' + if not os.path.exists(gypd_file): + raise Exception("gyp failed to produce gypd file!") + + return gypd_file diff --git a/platform_tools/android/bin/gyp_to_android.py b/platform_tools/android/bin/gyp_to_android.py new file mode 100644 index 0000000000..7990ae9d8b --- /dev/null +++ b/platform_tools/android/bin/gyp_to_android.py @@ -0,0 +1,134 @@ +#!/usr/bin/python + +# Copyright 2014 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Script for generating the Android framework's version of Skia from gyp +files. +""" + +import android_framework_gyp +import os +import shutil +import sys +import tempfile + +# Find the top of trunk +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) +SKIA_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, + os.pardir)) + +# Find the directory with our helper files, and add it to the path. +GYP_GEN_DIR = os.path.join(SKIA_DIR, 'platform_tools', 'android', 'gyp_gen') +sys.path.append(GYP_GEN_DIR) + +import gypd_parser +import makefile_writer +import variables +import vars_dict_lib + +# Folder containing all gyp files and generated gypd files. +GYP_FOLDER = 'gyp' + +def clean_gypd_files(folder): + """ + Remove the gypd files generated by android_framework_gyp.main(). + @param folder Folder in which to delete all files ending with 'gypd'. + """ + assert os.path.isdir(folder) + files = os.listdir(folder) + for f in files: + if f.endswith('gypd'): + os.remove(os.path.join(folder, f)) + +def generate_var_dict(target_dir, target_file, skia_arch_type, have_neon): + """ + Create a VarsDict for a particular arch type. Each paramater is passed + directly to android_framework_gyp.main(). + @param target_dir Directory containing gyp files. + @param target_file Target gyp file. + @param skia_arch_type Target architecture. + @param have_neon Whether the target should build for neon. + @return a VarsDict containing the variable definitions determined by gyp. + """ + result_file = android_framework_gyp.main(target_dir, target_file, + skia_arch_type, have_neon) + var_dict = vars_dict_lib.VarsDict() + gypd_parser.parse_gypd(var_dict, result_file) + clean_gypd_files(target_dir) + print '.', + return var_dict + +def main(target_dir=None): + """ + Read gyp files and create Android.mk for the Android framework's + external/skia. + @param target_dir Directory in which to place 'Android.mk'. If None, the file + will be placed in skia's root directory. + """ + # Create a temporary folder to hold gyp and gypd files. Create it in SKIA_DIR + # so that it is a sibling of gyp/, so the relationships between gyp files and + # other files (e.g. platform_tools/android/gyp/dependencies.gypi, referenced + # by android_deps.gyp as a relative path) is unchanged. + # Use mkdtemp to find an unused folder name, but then delete it so copytree + # can be called with a non-existent directory. + tmp_folder = tempfile.mkdtemp(dir=SKIA_DIR) + os.rmdir(tmp_folder) + shutil.copytree(os.path.join(SKIA_DIR, GYP_FOLDER), tmp_folder) + + try: + main_gyp_file = 'android_framework_lib.gyp' + + print 'Creating Android.mk', + + # Generate a separate VarsDict for each architecture type. For each + # archtype: + # 1. call android_framework_gyp.main() to generate gypd files + # 2. call parse_gypd to read those gypd files into the VarsDict + # 3. delete the gypd files + # + # Once we have the VarsDict for each architecture type, we combine them all + # into a single Android.mk file, which can build targets of any + # architecture type. + + # The default uses a non-existant archtype, to find all the general + # variable definitions. + default_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'other', + False) + arm_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm', False) + arm_neon_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'arm', + True) + if variables.INCLUDE_X86_OPTS: + x86_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'x86', False) + else: + x86_var_dict = None + + # Compute the intersection of all targets. All the files in the intersection + # should be part of the makefile always. Each dict will now contain trimmed + # lists containing only variable definitions specific to that configuration. + var_dict_list = [default_var_dict, arm_var_dict, arm_neon_var_dict] + if variables.INCLUDE_X86_OPTS: + var_dict_list.append(x86_var_dict) + common = vars_dict_lib.intersect(var_dict_list) + + # Further trim arm_neon_var_dict with arm_var_dict. After this call, + # arm_var_dict (which will now be the intersection) includes all definitions + # used by both arm and arm + neon, and arm_neon_var_dict will only contain + # those specific to arm + neon. + arm_var_dict = vars_dict_lib.intersect([arm_var_dict, arm_neon_var_dict]) + + makefile_writer.write_android_mk(target_dir=target_dir, + common=common, + arm=arm_var_dict, + arm_neon=arm_neon_var_dict, + x86=x86_var_dict, + default=default_var_dict) + + finally: + shutil.rmtree(tmp_folder) + +if __name__ == '__main__': + main() |