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

Commit b195e7ab authored by Dan Willemsen's avatar Dan Willemsen
Browse files

Use symlinks in the build graph for jni libs

Now that ninja uses lstat and can support installing arbitrary symlinks,
switch jni lib symlinks from LOCAL_POST_INSTALL_CMDS to real rules.

Bug: 128577186
Test: List of files under PRODUCT_OUT is the same before/after this change
Test: out/target/product/generic/.installable_files now includes the symlinks
Test: m installclean; m NfcNci -> symlinks installed with correct dest
Test: m NfcNci; m NfcNci -> ninja: no work to do
Change-Id: I078dca53ab3d93f74c36fa66d5577e6e3e0640d6
parent 99202ec0
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -2628,17 +2628,15 @@ $(foreach t,$(1),\
endef

# Define a rule to create a symlink to a file.
# $(1): full path to source
# $(1): any dependencies
# $(2): source (may be relative)
# $(3): full path to destination
define symlink-file
$(eval $(_symlink-file))
endef

# Order-only dependency because make/ninja will follow the link when checking
# the timestamp, so the file must exist
define _symlink-file
$(3): | $(1)
$(3): $(1)
	@echo "Symlink: $$@ -> $(2)"
	@mkdir -p $(dir $$@)
	@rm -rf $$@
+8 −16
Original line number Diff line number Diff line
@@ -49,29 +49,21 @@ else ifneq ($(my_jni_shared_libraries),) # not my_embed_jni
  my_shared_library_path := $(call get_non_asan_path,\
      $($(my_2nd_arch_prefix)TARGET_OUT$(partition_tag)_SHARED_LIBRARIES))
  my_installed_library := $(addprefix $(my_shared_library_path)/, $(my_jni_filenames))
  # Do not use order-only dependency, because we want to rebuild the image if an jni is updated.
  $(LOCAL_INSTALLED_MODULE) : $(my_installed_library)

  ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(my_installed_library)

  # Create symlink in the app specific lib path
  # Skip creating this symlink when running the second part of a target sanitization build.
  ifeq ($(filter address,$(SANITIZE_TARGET)),)
    ifdef LOCAL_POST_INSTALL_CMD
      # Add a shell command separator
      LOCAL_POST_INSTALL_CMD += ;
    endif

    my_symlink_target_dir := $(patsubst $(PRODUCT_OUT)%,%,\
      $(my_shared_library_path))
    LOCAL_POST_INSTALL_CMD += \
        mkdir -p $(my_app_lib_path) \
        $(foreach lib, $(my_jni_filenames), ;ln -sf $(my_symlink_target_dir)/$(lib) $(my_app_lib_path)/$(lib))
    $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
  else
    ifdef LOCAL_POST_INSTALL_CMD
      $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD)
    endif
    $(foreach lib,$(my_jni_filenames),\
      $(call symlink-file, \
        $(my_shared_library_path)/$(lib), \
        $(my_symlink_target_dir)/$(lib), \
        $(my_app_lib_path)/$(lib)) \
      $(eval $$(LOCAL_INSTALLED_MODULE) : $$(my_app_lib_path)/$$(lib)) \
      $(eval ALL_MODULES.$$(LOCAL_MODULE).INSTALLED += $$(my_app_lib_path)/$$(lib)))
  endif

  # Clear jni_shared_libraries to not embed it into the apk.