| #!/usr/bin/env python |
| # |
| # Copyright (C) 2012 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the 'License'); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an 'AS IS' BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # script to copy PDK_eng build result into a dir for PDK_rel build |
| |
| import os, string, sys, shutil |
| import pdk_utils as pu |
| |
| |
| # currently javalib.jar is not used and target jar is just copied in raw copy process |
| def copy_jar(src_jar_dir, dest_dir, jar_name): |
| """copy classes.jar and javalib.jar to dest_dir/jar_name dir""" |
| pu.copy_file_if_exists(src_jar_dir, dest_dir + "/" + jar_name, "classes.jar") |
| pu.copy_file_if_exists(src_jar_dir, dest_dir + "/" + jar_name, "javalib.jar") |
| |
| def copy_classes_or_javalib(src_jar_dir, dest_dir, jar_name): |
| """For host, either classes.jar or javalib.jar is enough. |
| Use javalib only when there is no classes.jar""" |
| if pu.copy_file_new_name_if_exists(src_jar_dir + "/classes.jar", dest_dir + "/" + jar_name, |
| jar_name + ".jar"): |
| return |
| pu.copy_file_new_name_if_exists(src_jar_dir + "/javalib.jar", dest_dir + "/" + jar_name, |
| jar_name + ".jar") |
| |
| class DependencyMk(object): |
| def __init__(self, file_full_name): |
| self.f = open(file_full_name, "a+") |
| |
| def __del__(self): |
| self.f.flush() |
| self.f.close() |
| |
| def addHostA(self, a_name): |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_PREBUILT_LIBS := " + "host/lib/" + a_name + ".a\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("include $(BUILD_HOST_PREBUILT)\n") |
| |
| def addHostSo(self, so_name): |
| # same as .a in makefile, distinguished by extension in build/core/multi_prebuilt.mk |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_PREBUILT_LIBS := " + "host/lib/" + so_name + ".so\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("include $(BUILD_HOST_PREBUILT)\n") |
| |
| def addHostJar(self, jar_name): |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("LOCAL_PREBUILT_JAVA_LIBRARIES := " + "host/java_lib/" + jar_name |
| + "/" + jar_name + ".jar\n") |
| self.f.write("include $(BUILD_HOST_PREBUILT)\n") |
| |
| def addTargetA(self, a_name): |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_MODULE := " + a_name + "\n") |
| self.f.write("LOCAL_SRC_FILES := target/lib/" + a_name + ".a\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("LOCAL_MODULE_SUFFIX := .a\n") |
| self.f.write("LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n") |
| self.f.write("include $(BUILD_PREBUILT)\n") |
| |
| def addTargetSo(self, so_name): |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_MODULE := " + so_name + "\n") |
| self.f.write("LOCAL_SRC_FILES := target/lib/" + so_name + ".so\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("LOCAL_MODULE_SUFFIX := .so\n") |
| self.f.write("LOCAL_MODULE_CLASS := SHARED_LIBRARIES\n") |
| self.f.write("LOCAL_MODULE_PATH := $(TARGET_OUT)/lib\n") |
| self.f.write("OVERRIDE_BUILT_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)\n") |
| self.f.write("include $(BUILD_PREBUILT)\n") |
| |
| def addTargetJar(self, jar_name): |
| self.f.write("include $(CLEAR_VARS)\n") |
| self.f.write("LOCAL_MODULE_TAGS := optional\n") |
| self.f.write("LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := " + jar_name + ":target/java_lib/" + |
| jar_name + "/classes.jar\n") |
| self.f.write("include $(BUILD_MULTI_PREBUILT)\n") |
| |
| def addString(self, message): |
| self.f.write(message) |
| |
| # individual files top copy as it is |
| # product/maguro will be substituted into product/target_name later |
| raw_file_list = [ |
| # "target/common/obj/PACKAGING/public_api.txt", |
| "host/linux-x86/bin/dx", |
| "host/linux-x86/bin/aapt", |
| # necessary for bootstrapping in host as the path is always assumed |
| "host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/classes.jar", |
| "host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/javalib.jar", |
| "host/common/obj/JAVA_LIBRARIES/core-junit-hostdex_intermediates/classes.jar", |
| "host/common/obj/JAVA_LIBRARIES/core-junit-hostdex_intermediates/javalib.jar", |
| # these permission stuffs are not copied as frameworks is not built |
| "target/product/maguro/system/etc/permissions/com.android.location.provider.xml", |
| "target/product/maguro/system/etc/permissions/platform.xml", |
| ] |
| |
| # the whole dir to copy as it is |
| raw_dir_list = [ |
| "target/product/maguro/system/etc/dhcpcd", |
| "target/product/maguro/system/etc/ppp", |
| "target/product/maguro/system/app", |
| "target/product/maguro/system/bin", |
| "target/product/maguro/system/etc/security", |
| "target/product/maguro/system/framework", |
| "target/product/maguro/system/lib", |
| # tools for debugging, not all of them are built in pdk_rel build |
| "target/product/maguro/system/xbin" |
| ] |
| |
| # from host/linux-x86/obj/STATIC_LIBRARIES/XYZ_intermediates |
| host_a_list = [ |
| "libandroidfw", |
| "libRS" |
| ] |
| |
| # from host/linux-x86/obj/lib |
| host_so_list = [ |
| ] |
| |
| # from host/commom/JAVA_LIBRARIES/XYZ_intermediates |
| host_jar_list = [ |
| "core-hostdex", |
| "dx", |
| "core-junit-hostdex" |
| ] |
| |
| # from target/product/product_name/obj/STATIC_LIBRARIES/XYZ_intermediates |
| target_a_list = [ |
| "libdrmframeworkcommon", |
| "libcpustats", |
| "libv8", |
| "libmedia_helper" |
| ] |
| |
| # from target/product/product_name/obj/lib |
| target_so_list = [ |
| "libandroid", |
| "libandroidfw", |
| "libandroid_runtime", |
| "libandroid_servers", |
| "libjnigraphics", |
| "libnativehelper", |
| "libemoji", |
| "libdrmframework", |
| "libdvm", |
| "libchromium_net", |
| "libcamera_client", |
| "libmedia", |
| "libstagefright", |
| "libstagefright_foundation", |
| "libRS", |
| "libmedia_native" # TODO temp fix for build error: should be removed after moving to f/native |
| ] |
| |
| |
| # from target/common/obj/JAVA_LIBRARIES |
| target_jar_list = [ |
| "core", |
| "core-junit", |
| "ext", |
| "framework", |
| "android.test.runner", |
| "android_stubs_current", |
| "filterfw" |
| ] |
| |
| # files unnecessarily built for PDK. remove after copy |
| raw_target_files_to_remove = [ |
| # redundant |
| "target/product/maguro/system/app/Home.apk", |
| # stingray build included due to wrong mk file |
| "target/product/maguro/system/app/StingrayProgramMenu*.apk", |
| "target/product/maguro/system/app/SprintMenu.apk", |
| "target/product/maguro/system/app/WiMAX*.apk", |
| # wallpaper, not necessary |
| "target/product/maguro/system/app/Microbes.apk", |
| # H/W depedent anyway |
| "target/procuct/maguro/system/hw", |
| "target/product/maguro/system/lib/hw", |
| "target/product/maguro/system/lib/libOMX.SEC.*.so", |
| "target/product/maguro/system/lib/libSEC_OMX*.so", |
| "target/product/maguro/system/lib/libWiMAX*.so", |
| "target/product/maguro/system/lib/libOMX.TI.*.so", |
| "target/product/maguro/system/lib/libOMX_Core.so" |
| ] |
| |
| def main(argv): |
| if len(argv) != 4: |
| print "Usage: copy_pdk_bins.py src_top_dir dest_top_dir src_target_device" |
| print " ex: copy_pdk_bins.py ../master vendor/pdk_bin_j_arm maguro" |
| sys.exit(1) |
| src_top_dir = argv[1] |
| src_out_dir = argv[1] + "/out/" |
| dest_top_dir = argv[2] |
| target_name = argv[3] |
| |
| # now replace product/maguro to product/target_name for all lists |
| replacement_list = [ |
| raw_file_list, |
| raw_dir_list, |
| raw_target_files_to_remove |
| ] |
| for dir_list in replacement_list: |
| for i in xrange(len(dir_list)): |
| replacement = dir_list[i].replace("product/maguro", "product/" + target_name) |
| dir_list[i] = replacement |
| |
| src_target_top_dir = src_out_dir + "/target/product/" + target_name + "/" |
| # delete existing binaries |
| os.system("rm -rf " + dest_top_dir + "/host") |
| os.system("rm -rf " + dest_top_dir + "/raw_copy") |
| os.system("rm -rf " + dest_top_dir + "/target") |
| # copy template for mk |
| pu.copy_file_if_exists(src_top_dir + "/pdk/build", dest_top_dir, "pdk_prebuilt.mk") |
| mkFile = DependencyMk(dest_top_dir + "/pdk_prebuilt.mk") |
| mkFile.addString("\n\n\n") |
| mkFile.addString("PDK_BIN_ORIGINAL_TARGET := " + target_name + "\n") |
| |
| for file_name in raw_file_list: |
| pu.copy_file_if_exists(src_out_dir, dest_top_dir + "/raw_copy", file_name) |
| |
| for raw_dir in raw_dir_list: |
| pu.copy_dir(src_out_dir, dest_top_dir + "/raw_copy", raw_dir) |
| |
| for host_a in host_a_list: |
| pu.copy_file_if_exists(src_out_dir + "/host/linux-x86/obj/STATIC_LIBRARIES/" + host_a + |
| "_intermediates", dest_top_dir + "/host/lib", host_a + ".a") |
| mkFile.addHostA(host_a) |
| |
| for host_so in host_so_list: |
| pu.copy_file_if_exists(src_out_dir + "/host/linux-x86/obj/lib/", |
| dest_top_dir + "/host/lib", host_so + ".so") |
| mkFile.addHostSo(host_so) |
| |
| src_host_jar_top = src_out_dir + "/host/common/obj/JAVA_LIBRARIES/" |
| for host_jar in host_jar_list: |
| src_host_jar_dir = src_host_jar_top + host_jar + "_intermediates/" |
| copy_classes_or_javalib(src_host_jar_dir, dest_top_dir + "/host/java_lib/", host_jar) |
| mkFile.addHostJar(host_jar) |
| |
| for target_a in target_a_list: |
| pu.copy_file_if_exists(src_target_top_dir + "obj/STATIC_LIBRARIES/" + target_a + |
| "_intermediates", dest_top_dir + "/target/lib", target_a + ".a") |
| mkFile.addTargetA(target_a) |
| |
| for target_so in target_so_list: |
| pu.copy_file_if_exists(src_target_top_dir + "obj/lib/", |
| dest_top_dir + "/target/lib", target_so + ".so") |
| mkFile.addTargetSo(target_so) |
| |
| src_target_jar_top = src_out_dir + "/target/common/obj/JAVA_LIBRARIES/" |
| for target_jar in target_jar_list: |
| src_target_jar_dir = src_target_jar_top + target_jar + "_intermediates/" |
| copy_jar(src_target_jar_dir, dest_top_dir + "/target/java_lib", target_jar) |
| mkFile.addTargetJar(target_jar) |
| |
| for file_to_remove in raw_target_files_to_remove: |
| os.system("rm -rf " + dest_top_dir + "/raw_copy/" + file_to_remove) |
| |
| # rename raw_copy/target/product/target_name to target/product/pdk_target |
| os.system("mv " + dest_top_dir + "/raw_copy/target/product/" + target_name \ |
| + " " + dest_top_dir + "/raw_copy/target/product/pdk_target") |
| |
| if __name__ == '__main__': |
| main(sys.argv) |