Chromium Code Reviews| 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 9d887c4c2d5320a0c675f7eb1a4c189d33ee5214..9134a830973ac16f3be4bbc20629ae69305ff07d 100644 |
| --- a/platform_tools/android/bin/gyp_to_android.py |
| +++ b/platform_tools/android/bin/gyp_to_android.py |
| @@ -11,6 +11,8 @@ |
| """ |
| import os |
| +import shutil |
| +import tempfile |
| # Folder containing all gyp files and generated gypd files. |
| GYP_FOLDER = 'gyp' |
| @@ -121,9 +123,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 |
| @@ -138,7 +142,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('BASE_PATH := $(call my-dir)\n') |
| f.write('LOCAL_PATH:= $(call my-dir)\n') |
| @@ -340,79 +347,102 @@ 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__) |
| 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=os.getcwd()) |
|
epoger
2014/01/22 21:35:03
This will work, but maybe set dir=skia_dir so that
scroggo
2014/01/22 23:33:08
Done.
|
| + os.rmdir(tmp_folder) |
| + shutil.copytree(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() |