Android編譯腳本中,PRODUCT_COPY_FILES保存的是一組src:dest的字符串列表,如果碰到裏面有重複的dest怎麼辦?
# filter out the duplicate <source file>:<dest file> pairs.
unique_product_copy_files_pairs :=
$(foreach cf,$(PRODUCT_COPY_FILES), \
$(if $(filter $(unique_product_copy_files_pairs),$(cf)),,\
$(eval unique_product_copy_files_pairs += $(cf))))
unique_product_copy_files_destinations :=
$(foreach cf,$(unique_product_copy_files_pairs), \
$(eval _src := $(call word-colon,1,$(cf))) \
$(eval _dest := $(call word-colon,2,$(cf))) \
$(call check-product-copy-files,$(cf)) \
$(if $(filter $(unique_product_copy_files_destinations),$(_dest)), \
$(info PRODUCT_COPY_FILES $(cf) ignored.), \
$(eval _fulldest := $(call append-path,$(PRODUCT_OUT),$(_dest))) \
$(if $(filter %.xml,$(_dest)),\
$(eval $(call copy-xml-file-checked,$(_src),$(_fulldest))),\
$(eval $(call copy-one-file,$(_src),$(_fulldest)))) \
$(eval ALL_DEFAULT_INSTALLED_MODULES += $(_fulldest)) \
$(eval unique_product_copy_files_destinations += $(_dest))))
明顯,第一部將src:dest的重複去除,第二步,將dest的重複去除。
從去除重複的算法來看,是從第一個字符串開始,如果目標中沒有就添加,如果已經有就不做任何處理,因此只有最先描述的目標有效。
如果在兩個地方定義system/etc/apns-conf.xml:
./device/lge/mako/full_mako.mk:28:PRODUCT_COPY_FILES := device/lge/mako/apns-full-conf.xml:system/etc/apns-conf.xml
./build/target/product/full_base_telephony.mk:PRODUCT_COPY_FILES := device/generic/goldfish/data/etc/apns-conf.xml:system/etc/apns-conf.xml
則先出現定義的有效,即device/lge/mako/apns-full-conf.xml會有效。