Index: platform_tools/android/bin/gyp_to_android.py |
diff --git a/platform_tools/android/bin/gyp_to_android.py b/platform_tools/android/bin/gyp_to_android.py |
index ee1f86ef823f0647cf1e7d6603382dfdf0f153ba..dafd42b7af8c0989dc62391d7c56a05c146b8eac 100644 |
--- a/platform_tools/android/bin/gyp_to_android.py |
+++ b/platform_tools/android/bin/gyp_to_android.py |
@@ -11,6 +11,8 @@ files. |
""" |
import os |
+import shutil |
+import tempfile |
# Folder containing all gyp files and generated gypd files. |
GYP_FOLDER = 'gyp' |
@@ -141,9 +143,11 @@ DEBUGGING_HELP = ( |
""" |
) |
-def WriteAndroidMk(common, arm, armNeon, x86, default): |
+def WriteAndroidMk(target_dir, common, arm, armNeon, x86, default): |
""" |
Given all the variables, write the final make file. |
+ @param target_dir The full path to the directory to write Android.mk, or None |
+ to use the current working directory. |
@param common VarsDict holding variables definitions common to all |
configurations. |
@param arm VarsDict holding variable definitions unique to arm. Will be |
@@ -158,7 +162,10 @@ def WriteAndroidMk(common, arm, armNeon, x86, default): |
without custom optimizations. |
TODO: Add mips. |
""" |
- with open('Android.mk', 'w') as f: |
+ target_file = 'Android.mk' |
+ if target_dir: |
+ target_file = os.path.join(target_dir, target_file) |
+ with open(target_file, 'w') as f: |
f.write(AUTOGEN_WARNING) |
f.write('BASE_PATH := $(call my-dir)\n') |
f.write('LOCAL_PATH:= $(call my-dir)\n') |
@@ -354,79 +361,100 @@ def Intersect(var_dict_list): |
var_dict[key].remove(item) |
return intersection |
-def CleanGypdFiles(): |
+def CleanGypdFiles(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(GYP_FOLDER) |
- files = os.listdir(GYP_FOLDER) |
+ assert os.path.isdir(folder) |
+ files = os.listdir(folder) |
for f in files: |
if f.endswith('gypd'): |
- os.remove(os.path.join(GYP_FOLDER, f)) |
+ os.remove(os.path.join(folder, f)) |
import android_framework_gyp |
-def main(): |
+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. |
+ """ |
# Move up to top of trunk |
- script_dir = os.path.dirname(__file__) |
+ 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)) |
- os.chdir(skia_dir) |
- |
- main_gypd_file = os.path.join(GYP_FOLDER, 'android_framework_lib.gypd') |
- |
- print 'Creating Android.mk', |
- |
- # Call the script to generate gypd files, first using a non-existant archtype. |
- android_framework_gyp.main('other', False) |
- # And store its variables in the default dict |
- default_var_dict = VarsDict() |
- ParseGypd(default_var_dict, main_gypd_file) |
- CleanGypdFiles() |
- |
- print '.', |
- |
- # Now do the same for Arm. arm_var_dict will contain all the variable |
- # definitions needed to build with arm (meaning that it will share most |
- # with default_var_dict). |
- android_framework_gyp.main('arm', False) |
- arm_var_dict = VarsDict() |
- ParseGypd(arm_var_dict, main_gypd_file) |
- CleanGypdFiles() |
- |
- print '.', |
- |
- # Now do the same for Arm/Neon. |
- android_framework_gyp.main('arm', True) |
- arm_neon_var_dict = VarsDict() |
- ParseGypd(arm_neon_var_dict, main_gypd_file) |
- CleanGypdFiles() |
- |
- print '.' |
- |
- # Now do the same for x86. |
- x86_var_dict = VarsDict() |
- if INCLUDE_X86_OPTS: |
- android_framework_gyp.main('x86', False) |
- ParseGypd(x86_var_dict, main_gypd_file) |
- CleanGypdFiles() |
- |
- # 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 INCLUDE_X86_OPTS: |
- var_dict_list.append(x86_var_dict) |
- common = 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 = Intersect([arm_var_dict, arm_neon_var_dict]) |
- |
- WriteAndroidMk(common, arm_var_dict, arm_neon_var_dict, x86_var_dict, |
- default_var_dict) |
+ # 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' |
+ main_gypd_file = os.path.join(tmp_folder, main_gyp_file + 'd') |
+ |
+ print 'Creating Android.mk', |
+ |
+ # Call the script to generate gypd files, first using a non-existant |
+ # archtype. |
+ android_framework_gyp.main(tmp_folder, main_gyp_file, 'other', False) |
+ # And store its variables in the default dict |
+ default_var_dict = VarsDict() |
+ ParseGypd(default_var_dict, main_gypd_file) |
+ CleanGypdFiles(tmp_folder) |
+ |
+ print '.', |
+ |
+ # Now do the same for Arm. arm_var_dict will contain all the variable |
+ # definitions needed to build with arm (meaning that it will share most |
+ # with default_var_dict). |
+ android_framework_gyp.main(tmp_folder, main_gyp_file, 'arm', False) |
+ arm_var_dict = VarsDict() |
+ ParseGypd(arm_var_dict, main_gypd_file) |
+ CleanGypdFiles(tmp_folder) |
+ |
+ print '.', |
+ |
+ # Now do the same for Arm/Neon. |
+ android_framework_gyp.main(tmp_folder, main_gyp_file, 'arm', True) |
+ arm_neon_var_dict = VarsDict() |
+ ParseGypd(arm_neon_var_dict, main_gypd_file) |
+ CleanGypdFiles(tmp_folder) |
+ |
+ print '.' |
+ |
+ # Now do the same for x86. |
+ x86_var_dict = VarsDict() |
+ if INCLUDE_X86_OPTS: |
+ android_framework_gyp.main(tmp_folder, main_gyp_file, 'x86', False) |
+ ParseGypd(x86_var_dict, main_gypd_file) |
+ CleanGypdFiles(tmp_folder) |
+ |
+ # 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 INCLUDE_X86_OPTS: |
+ var_dict_list.append(x86_var_dict) |
+ common = 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 = Intersect([arm_var_dict, arm_neon_var_dict]) |
+ |
+ WriteAndroidMk(target_dir, common, arm_var_dict, arm_neon_var_dict, |
+ x86_var_dict, default_var_dict) |
+ |
+ finally: |
+ shutil.rmtree(tmp_folder) |
if __name__ == '__main__': |
main() |