Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cf8ee61 authored by Jiyong Park's avatar Jiyong Park
Browse files

Export SDK library names

A java module exports SDK library names that it is using directly or
indirectly via its dependencies. Manifest fixer uses the SDK lib names
to automatically add <uses-library> tags for the apk.

The SDK library names are exported via exported-sdk-libs file in make.
From Soong, they are exported via LOCAL_EXPORT_SDK_LIBRARIES flag.

Bug: 77575606
Test: m -j

Change-Id: I4e7a9bdc5bf845af85168abf55f8063900bacc72
parent 6291a4a2
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -43,24 +43,27 @@ else
endif

# Set up rules to merge library manifest files
my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs
$(full_android_manifest): PRIVATE_EXPORTED_SDK_LIBS_FILE := $(my_exported_sdk_libs_file)
$(full_android_manifest): $(my_exported_sdk_libs_file)
$(full_android_manifest): $(MANIFEST_FIXER)

ifneq (,$(strip $(my_full_libs_manifest_files)))

$(full_android_manifest): PRIVATE_LIBS_MANIFESTS := $(my_full_libs_manifest_files)
$(full_android_manifest): $(ANDROID_MANIFEST_MERGER_CLASSPATH)
$(full_android_manifest): $(MANIFEST_FIXER)
$(full_android_manifest) : $(main_android_manifest) $(my_full_libs_manifest_files)
	@echo "Merge android manifest files: $@ <-- $< $(PRIVATE_LIBS_MANIFESTS)"
	@mkdir -p $(dir $@)
	$(MANIFEST_FIXER) $< $@.tmp --minSdkVersion $(PRIVATE_MIN_SDK_VERSION)
	$(call fix-manifest,$<,$@.tmp,$(PRIVATE_MIN_SDK_VERSION),$(PRIVATE_EXPORTED_SDK_LIBS_FILE))
	$(hide) $(ANDROID_MANIFEST_MERGER) --main $@.tmp \
	    --libs $(call normalize-path-list,$(PRIVATE_LIBS_MANIFESTS)) \
	    --out $@
	rm $@.tmp

else
$(full_android_manifest): $(MANIFEST_FIXER)
$(full_android_manifest): $(main_android_manifest)
	@echo "Fix manifest: $@"
	$(MANIFEST_FIXER) $< $@ --minSdkVersion $(PRIVATE_MIN_SDK_VERSION)
	$(call fix-manifest,$<,$@,$(PRIVATE_MIN_SDK_VERSION),$(PRIVATE_EXPORTED_SDK_LIBS_FILE))

endif
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ LOCAL_EXPORT_C_INCLUDE_DIRS:=
LOCAL_EXPORT_HEADER_LIBRARY_HEADERS:=
LOCAL_EXPORT_PACKAGE_RESOURCES:=
LOCAL_EXPORT_PROGUARD_FLAG_FILES:=
LOCAL_EXPORT_SDK_LIBRARIES:=
LOCAL_EXPORT_SHARED_LIBRARY_HEADERS:=
LOCAL_EXPORT_STATIC_LIBRARY_HEADERS:=
LOCAL_EXTRACT_APK:=
+19 −0
Original line number Diff line number Diff line
@@ -731,6 +731,25 @@ $(call app-lib-files,$(1))
endef
endif

# Get the exported-sdk-libs files which collectively give you the list of exported java sdk
# lib names that are (transitively) exported from the given set of java libs
# $(1): library name list
define exported-sdk-libs-files
$(foreach lib,$(1),$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/exported-sdk-libs)
endef

# Fix manifest
# $(1): input manifest path
# $(2): output manifest path
# $(3): min sdk version
# $(4): (optional) exported-sdk-libs file
define fix-manifest
$(MANIFEST_FIXER) \
--minSdkVersion $(3) \
$(if $(4),$$(cat $(4) | sort -u | sed -e 's/^/\ --uses-library\ /' | tr '\n' ' ')) \
$(1) $(2)
endef

###########################################################
## Returns true if $(1) and $(2) are equal.  Returns
## the empty string if they are not equal.
+26 −0
Original line number Diff line number Diff line
@@ -237,6 +237,8 @@ endif
full_java_bootclasspath_libs :=
empty_bootclasspath :=
my_system_modules :=
exported_sdk_libs_files :=
my_exported_sdk_libs_file :=

ifndef LOCAL_IS_HOST_MODULE
  sdk_libs :=
@@ -326,6 +328,14 @@ ifndef LOCAL_IS_HOST_MODULE
  full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
  full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
  sdk_libs :=

  # Files that contains the names of SDK libraries exported from dependencies. These will be re-exported.
  # Note: No need to consider LOCAL_*_ANDROID_LIBRARIES and LOCAL_STATIC_JAVA_AAR_LIBRARIES. They are all appended to
  # LOCAL_*_JAVA_LIBRARIES in java.mk
  exported_sdk_libs_files := $(call exported-sdk-libs-files,$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
  # The file that contains the names of all SDK libraries that this module exports and re-exports
  my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs

else # LOCAL_IS_HOST_MODULE

  ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
@@ -362,6 +372,22 @@ else # LOCAL_IS_HOST_MODULE
  endif # USE_CORE_LIB_BOOTCLASSPATH
endif # !LOCAL_IS_HOST_MODULE


# Export the SDK libs. The sdk library names listed in LOCAL_SDK_LIBRARIES are first exported.
# Then sdk library names exported from dependencies are all re-exported.
$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS_FILES := $(exported_sdk_libs_files)
$(my_exported_sdk_libs_file): PRIVATE_SDK_LIBS := $(sort $(LOCAL_SDK_LIBRARIES))
$(my_exported_sdk_libs_file): $(exported_sdk_libs_files)
	@echo "Export SDK libs $@"
	$(hide) mkdir -p $(dir $@) && rm -f $@ $@.temp
	$(if $(PRIVATE_SDK_LIBS),\
		echo $(PRIVATE_SDK_LIBS) | tr ' ' '\n' > $@.temp,\
		touch $@.temp)
	$(if $(PRIVATE_EXPORTED_SDK_LIBS_FILES),\
		cat $(PRIVATE_EXPORTED_SDK_LIBS_FILES) >> $@.temp)
	$(hide) cat $@.temp | sort -u > $@
	$(hide) rm -f $@.temp

ifdef empty_bootclasspath
  ifdef full_java_bootclasspath_libs
    $(call pretty-error,internal error: empty_bootclasspath and full_java_bootclasspath_libs should not both be set)
+9 −0
Original line number Diff line number Diff line
@@ -674,6 +674,15 @@ endif # LOCAL_USE_AAPT2
# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
$(built_module) : $(common_javalib_jar)

my_exported_sdk_libs_file := $(intermediates.COMMON)/exported-sdk-libs
$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS := $(LOCAL_EXPORT_SDK_LIBRARIES)
$(my_exported_sdk_libs_file):
	@echo "Export SDK libs $@"
	$(hide) mkdir -p $(dir $@) && rm -f $@
	$(if $(PRIATE_EXPORTED_SDK_LIBS),\
		$(hide) echo $(PRIVATE_EXPORTED_SDK_LIBS) | tr ' ' '\n' > $@,\
		$(hide) touch $@)

endif # ! prebuilt_module_is_dex_javalib
endif # LOCAL_IS_HOST_MODULE is not set

Loading