aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Turner <digit@android.com>2015-03-20 22:17:05 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-20 22:17:05 +0000
commit2b1c8636b873d7fbe07c697532b3bbcdd2681da9 (patch)
tree9800922492b7ed5d2651fe06e72ec555161aaad4
parent6809c4484af80640c3f4dbb80a71b3a92ea2853a (diff)
parent7915a19f8fc6b9a581a6b10e3d9b62caed444083 (diff)
downloadsdk-2b1c8636b873d7fbe07c697532b3bbcdd2681da9.zip
sdk-2b1c8636b873d7fbe07c697532b3bbcdd2681da9.tar.gz
sdk-2b1c8636b873d7fbe07c697532b3bbcdd2681da9.tar.bz2
am 7915a19f: am 1af9ef83: Merge "Support dynamic lib name without ".dylib" on Mac"
* commit '7915a19f8fc6b9a581a6b10e3d9b62caed444083': Support dynamic lib name without ".dylib" on Mac
-rw-r--r--emulator/opengl/shared/emugl/common/shared_library.cpp10
-rw-r--r--emulator/opengl/shared/emugl/common/shared_library.h13
-rw-r--r--emulator/opengl/shared/emugl/common/shared_library_unittest.cpp25
3 files changed, 44 insertions, 4 deletions
diff --git a/emulator/opengl/shared/emugl/common/shared_library.cpp b/emulator/opengl/shared/emugl/common/shared_library.cpp
index db1c75c..e78e36b 100644
--- a/emulator/opengl/shared/emugl/common/shared_library.cpp
+++ b/emulator/opengl/shared/emugl/common/shared_library.cpp
@@ -75,7 +75,17 @@ SharedLibrary* SharedLibrary::open(const char* libraryName) {
libPath = path;
}
+#ifdef __APPLE__
+ // On OSX, some libraries don't include an extension (notably OpenGL)
+ // On OSX we try to open |libraryName| first. If that doesn't exist,
+ // we try |libraryName|.dylib
+ void* lib = dlopen(libraryName, RTLD_NOW);
+ if (lib == NULL) {
+ lib = dlopen(libPath, RTLD_NOW);
+ }
+#else
void* lib = dlopen(libPath, RTLD_NOW);
+#endif
if (path) {
free(path);
diff --git a/emulator/opengl/shared/emugl/common/shared_library.h b/emulator/opengl/shared/emugl/common/shared_library.h
index 38d25bd..f1d82fc 100644
--- a/emulator/opengl/shared/emugl/common/shared_library.h
+++ b/emulator/opengl/shared/emugl/common/shared_library.h
@@ -38,9 +38,16 @@ namespace emugl {
//
class SharedLibrary {
public:
- // Open a given library. |libraryName| can be either a full library
- // path, or a simple name without an extension. On success, returns
- // a new SharedLibrary instance that must be deleted by the caller.
+ // Open a given library. If |libraryName| has no extension, a
+ // platform-appropriate extension is added and that path is opened.
+ // If the |libraryName| has an extension, that form is opened.
+ //
+ // On OSX, some libraries don't include an extension (notably OpenGL)
+ // On OSX we try to open |libraryName| first. If that doesn't exist,
+ // we try |libraryName|.dylib
+ //
+ // On success, returns a new SharedLibrary instance that must be
+ // deleted by the caller.
static SharedLibrary* open(const char* libraryName);
// Closes an existing SharedLibrary instance.
diff --git a/emulator/opengl/shared/emugl/common/shared_library_unittest.cpp b/emulator/opengl/shared/emugl/common/shared_library_unittest.cpp
index cec4c73..cb74efa 100644
--- a/emulator/opengl/shared/emugl/common/shared_library_unittest.cpp
+++ b/emulator/opengl/shared/emugl/common/shared_library_unittest.cpp
@@ -100,6 +100,11 @@ public:
SharedLibrary* operator->() { return mLib; }
+ void release() {
+ delete mLib;
+ mLib = NULL;
+ }
+
private:
SharedLibrary* mLib;
};
@@ -111,19 +116,37 @@ TEST_F(SharedLibraryTest, Open) {
EXPECT_TRUE(lib.get());
}
-TEST_F(SharedLibraryTest, OpenWithExtension) {
+TEST_F(SharedLibraryTest, OpenLibraryWithExtension) {
std::string path = library_path();
+
+ // test extension append
+ ScopedSharedLibrary libNoExtension(SharedLibrary::open(path.c_str()));
+ EXPECT_TRUE(libNoExtension.get());
+ libNoExtension.release();
+
#ifdef _WIN32
path += ".dll";
#elif defined(__APPLE__)
+ // try to open the library without an extension
+
path += ".dylib";
#else
path += ".so";
#endif
+
+ // test open with prepended extension
ScopedSharedLibrary lib(SharedLibrary::open(path.c_str()));
EXPECT_TRUE(lib.get());
}
+#ifdef __APPLE__
+TEST_F(SharedLibraryTest, OpenLibraryWithoutExtension) {
+ const char* library = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
+ ScopedSharedLibrary lib(SharedLibrary::open(library));
+ EXPECT_TRUE(lib.get());
+}
+#endif
+
TEST_F(SharedLibraryTest, FindSymbol) {
ScopedSharedLibrary lib(SharedLibrary::open(library_path()));
EXPECT_TRUE(lib.get());