Skip to content

Commit

Permalink
Add support for exporting library dependencies.
Browse files Browse the repository at this point in the history
We supported `LOCAL_EXPORT_LDLIBS`, but not
`LOCAL_EXPORT_SHARED_LIBRARIES` or `LOCAL_EXPORT_STATIC_LIBRARIES`.

We need this feature to make ndk-build use libunwind with libc++ for
only arm32. This hasn't been a problem thus far because ndk-build
currently doesn't so much as warn about missing dependencies
(android/ndk#208).

Test: ./run_tests.py --filter export-libs
Bug: None
Change-Id: Ib6b326779115cc9f60cc8018a38cb57074f7618b
  • Loading branch information
DanAlbert committed Sep 27, 2016
1 parent b688289 commit a2244bc
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build/core/definitions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ modules-LOCALS := \
EXPORT_CPPFLAGS \
EXPORT_ASMFLAGS \
EXPORT_LDFLAGS \
EXPORT_SHARED_LIBRARIES \
EXPORT_STATIC_LIBRARIES \
EXPORT_LDLIBS \
EXPORT_C_INCLUDES \
FILTER_ASM \
Expand Down
11 changes: 11 additions & 0 deletions build/core/import-locals.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ imported_RENDERSCRIPT_FLAGS := $(call module-get-listed-export,$(all_depends),RE
imported_ASMFLAGS := $(call module-get-listed-export,$(all_depends),ASMFLAGS)
imported_C_INCLUDES := $(call module-get-listed-export,$(all_depends),C_INCLUDES)
imported_LDFLAGS := $(call module-get-listed-export,$(all_depends),LDFLAGS)
imported_SHARED_LIBRARIES := $(call module-get-listed-export,$(all_depends),SHARED_LIBRARIES)
imported_STATIC_LIBRARIES := $(call module-get-listed-export,$(all_depends),STATIC_LIBRARIES)

ifdef NDK_DEBUG_IMPORTS
$(info Imports for module $(LOCAL_MODULE):)
Expand All @@ -46,6 +48,8 @@ ifdef NDK_DEBUG_IMPORTS
$(info ASMFLAGS='$(imported_ASMFLAGS)')
$(info C_INCLUDES='$(imported_C_INCLUDES)')
$(info LDFLAGS='$(imported_LDFLAGS)')
$(info SHARED_LIBRARIES='$(imported_SHARED_LIBRARIES)')
$(info STATIC_LIBRARIES='$(imported_STATIC_LIBRARIES)')
$(info All depends='$(all_depends)')
endif

Expand All @@ -60,6 +64,13 @@ LOCAL_RENDERSCRIPT_FLAGS := $(strip $(imported_RENDERSCRIPT_FLAGS) $(LOCAL_RENDE
LOCAL_ASMFLAGS := $(strip $(imported_ASMFLAGS) $(LOCAL_ASMFLAGS))
LOCAL_LDFLAGS := $(strip $(imported_LDFLAGS) $(LOCAL_LDFLAGS))

__ndk_modules.$(LOCAL_MODULE).STATIC_LIBRARIES += \
$(strip $(call strip-lib-prefix,$(imported_STATIC_LIBRARIES)))
__ndk_modules.$(LOCAL_MODULE).SHARED_LIBRARIES += \
$(strip $(call strip-lib-prefix,$(imported_SHARED_LIBRARIES)))
$(call module-add-static-depends,$(LOCAL_MODULE),$(imported_STATIC_LIBRARIES))
$(call module-add-shared-depends,$(LOCAL_MODULE),$(imported_SHARED_LIBRARIES))

#
# The imported include directories are appended to their LOCAL_XXX value
# (this allows the module to override them)
Expand Down
35 changes: 35 additions & 0 deletions tests/build/export-libs/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
LOCAL_PATH := $(call my-dir)

# Provides foo.
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_SRC_FILES := foo.c
include $(BUILD_STATIC_LIBRARY)

# Provides bar.
include $(CLEAR_VARS)
LOCAL_MODULE := libbar
LOCAL_SRC_FILES := bar.c
include $(BUILD_SHARED_LIBRARY)

# Provides baz, which needs foo and bar. Since this is a static library, we need
# to link both libfoo and libbar into any of out callers.
include $(CLEAR_VARS)
LOCAL_MODULE := libbaz
LOCAL_SRC_FILES := baz.c
# NB: Normally we'd want to add these libraries to LOCAL_STATIC_LIBRARIES and
# LOCAL_SHARED_LIBRARIES to pick up any exported values from those libraries,
# but we want to make sure that these exports are used even if nothing depends
# on the module in question since there are actually two separate places this
# information needs to be recorded (this problem did come up in testing).
LOCAL_EXPORT_STATIC_LIBRARIES := libfoo
LOCAL_EXPORT_SHARED_LIBRARIES := libbar
include $(BUILD_STATIC_LIBRARY)

# Calls baz, which needs definitions of foo and bar. We get those libraries
# added to our module even though we only depend on libbaz.
include $(CLEAR_VARS)
LOCAL_MODULE := qux
LOCAL_SRC_FILES := qux.c
LOCAL_STATIC_LIBRARIES := libbaz
include $(BUILD_EXECUTABLE)
1 change: 1 addition & 0 deletions tests/build/export-libs/jni/bar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void bar() {}
7 changes: 7 additions & 0 deletions tests/build/export-libs/jni/baz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern void foo();
extern void bar();

void baz() {
foo();
bar();
}
1 change: 1 addition & 0 deletions tests/build/export-libs/jni/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void foo() {}
5 changes: 5 additions & 0 deletions tests/build/export-libs/jni/qux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern void baz();

int main(int argc, char** argv) {
baz();
}

0 comments on commit a2244bc

Please sign in to comment.