def test_intersection(self): v_dict_list = [] RANGE = 10 for i in range(RANGE): v_dict = VarsDict() # Add something common to each field, as well as a unique entry v_dict.LOCAL_CFLAGS.add('cflag') v_dict.LOCAL_CFLAGS.add(str(i)) v_dict.LOCAL_CPPFLAGS.add('cppflag') v_dict.LOCAL_CPPFLAGS.add(str(i)) v_dict.LOCAL_SRC_FILES.add('src') v_dict.LOCAL_SRC_FILES.add(str(i)) v_dict.LOCAL_SHARED_LIBRARIES.add('shared') v_dict.LOCAL_SHARED_LIBRARIES.add(str(i)) v_dict.LOCAL_STATIC_LIBRARIES.add('static') v_dict.LOCAL_STATIC_LIBRARIES.add(str(i)) v_dict.LOCAL_C_INCLUDES.add('includes') v_dict.LOCAL_C_INCLUDES.add(str(i)) v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add('exports') v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(str(i)) v_dict.KNOWN_TARGETS.add('known') v_dict.KNOWN_TARGETS.add(str(i)) self.assert_consistency(v_dict) v_dict_list.append(v_dict) intersection = vars_dict_lib.intersect(v_dict_list) self.assert_consistency(intersection) for key in intersection.keys(): # Each field had one common item self.assertEqual(len(intersection[key]), 1) for item in intersection[key]: for other_v_dict in v_dict_list: self.assertNotIn(item, other_v_dict[key])
def test_intersection(self): v_dict_list = [] RANGE = 10 for i in range(RANGE): v_dict = VarsDict() # Add something common to each field, as well as a unique entry for key in v_dict.keys(): v_dict[key].add(key.lower()) v_dict[key].add(str(i)) self.assert_consistency(v_dict) v_dict_list.append(v_dict) intersection = vars_dict_lib.intersect(v_dict_list) self.assert_consistency(intersection) for key in intersection.keys(): # Each field had one common item self.assertEqual(len(intersection[key]), 1) for item in intersection[key]: for other_v_dict in v_dict_list: self.assertNotIn(item, other_v_dict[key])
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) x86_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'x86', False) mips_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'mips', False) # 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, x86_var_dict, mips_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]) # Now create a list of VarsDictData holding everything but common. deviations_from_common = [] deviations_from_common.append( makefile_writer.VarsDictData(arm_var_dict, 'arm')) deviations_from_common.append( makefile_writer.VarsDictData(arm_neon_var_dict, 'arm', 'ARCH_ARM_HAVE_NEON')) deviations_from_common.append( makefile_writer.VarsDictData(x86_var_dict, 'x86')) # Currently, x86_64 is identical to x86 deviations_from_common.append( makefile_writer.VarsDictData(x86_var_dict, 'x86_64')) deviations_from_common.append( makefile_writer.VarsDictData(mips_var_dict, 'mips')) makefile_writer.write_android_mk( target_dir=target_dir, common=common, deviations_from_common=deviations_from_common) finally: shutil.rmtree(tmp_folder)
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) x86_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'x86', False) mips_var_dict = generate_var_dict(tmp_folder, main_gyp_file, 'mips', False) # 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, x86_var_dict, mips_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]) # Now create a list of VarsDictData holding everything but common. deviations_from_common = [] deviations_from_common.append(makefile_writer.VarsDictData( arm_var_dict, 'arm')) deviations_from_common.append(makefile_writer.VarsDictData( arm_neon_var_dict, 'arm', 'ARCH_ARM_HAVE_NEON')) deviations_from_common.append(makefile_writer.VarsDictData(x86_var_dict, 'x86')) # Currently, x86_64 is identical to x86 deviations_from_common.append(makefile_writer.VarsDictData(x86_var_dict, 'x86_64')) deviations_from_common.append(makefile_writer.VarsDictData(mips_var_dict, 'mips')) makefile_writer.write_android_mk(target_dir=target_dir, common=common, deviations_from_common=deviations_from_common) finally: shutil.rmtree(tmp_folder)