瀏覽代碼

Add support from properly exporting shared objects, needed for GDNative export

Juan Linietsky 7 年之前
父節點
當前提交
6e2ed15ff1
共有 4 個文件被更改,包括 60 次插入5 次删除
  1. 14 1
      drivers/unix/os_unix.cpp
  2. 13 1
      editor/editor_export.cpp
  3. 24 1
      platform/osx/export/export.cpp
  4. 9 2
      platform/windows/os_windows.cpp

+ 14 - 1
drivers/unix/os_unix.cpp

@@ -362,7 +362,20 @@ String OS_Unix::get_locale() const {
 }
 }
 
 
 Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
 Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
-	p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW);
+
+	String path = p_path;
+
+	if (!FileAccess::exists(path)) {
+		//this code exists so gdnative can load .so files from within the executable path
+		path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
+	}
+
+	if (!FileAccess::exists(path)) {
+		//this code exists so gdnative can load .so files from a standard unix location
+		path = get_executable_path().get_base_dir().plus_file("../lib").plus_file(p_path.get_file());
+	}
+
+	p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
 	if (!p_library_handle) {
 	if (!p_library_handle) {
 		ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror());
 		ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror());
 		ERR_FAIL_V(ERR_CANT_OPEN);
 		ERR_FAIL_V(ERR_CANT_OPEN);

+ 13 - 1
editor/editor_export.cpp

@@ -1361,7 +1361,19 @@ Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_pr
 
 
 	String pck_path = p_path.get_basename() + ".pck";
 	String pck_path = p_path.get_basename() + ".pck";
 
 
-	return save_pack(p_preset, pck_path);
+	Vector<SharedObject> so_files;
+
+	err = save_pack(p_preset, pck_path, &so_files);
+
+	if (err != OK || so_files.empty())
+		return err;
+	//if shared object files, copy them
+	da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+	for (int i = 0; i < so_files.size(); i++) {
+		da->copy(so_files[i].path, p_path.get_base_dir().plus_file(so_files[i].path.get_file()));
+	}
+	memdelete(da);
+	return OK;
 }
 }
 
 
 void EditorExportPlatformPC::set_extension(const String &p_extension, const String &p_feature_key) {
 void EditorExportPlatformPC::set_extension(const String &p_extension, const String &p_feature_key) {

+ 24 - 1
platform/osx/export/export.cpp

@@ -541,7 +541,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 		} else {
 		} else {
 
 
 			String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
 			String pack_path = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".pck");
-			Error err = save_pack(p_preset, pack_path);
+
+			Vector<SharedObject> shared_objects;
+			Error err = save_pack(p_preset, pack_path, &shared_objects);
 
 
 			if (err == OK) {
 			if (err == OK) {
 				zipOpenNewFileInZip(dst_pkg_zip,
 				zipOpenNewFileInZip(dst_pkg_zip,
@@ -567,11 +569,32 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
 							break;
 							break;
 						zipWriteInFileInZip(dst_pkg_zip, buf, r);
 						zipWriteInFileInZip(dst_pkg_zip, buf, r);
 					}
 					}
+
 					zipCloseFileInZip(dst_pkg_zip);
 					zipCloseFileInZip(dst_pkg_zip);
 					memdelete(pf);
 					memdelete(pf);
 				} else {
 				} else {
 					err = ERR_CANT_OPEN;
 					err = ERR_CANT_OPEN;
 				}
 				}
+
+				//add shared objects
+				for (int i = 0; i < shared_objects.size(); i++) {
+					Vector<uint8_t> file = FileAccess::get_file_as_array(shared_objects[i].path);
+					ERR_CONTINUE(file.empty());
+
+					zipOpenNewFileInZip(dst_pkg_zip,
+							(pkg_name + ".app/Contents/MacOS/").plus_file(shared_objects[i].path.get_file()).utf8().get_data(),
+							NULL,
+							NULL,
+							0,
+							NULL,
+							0,
+							NULL,
+							Z_DEFLATED,
+							Z_DEFAULT_COMPRESSION);
+
+					zipWriteInFileInZip(dst_pkg_zip, file.ptr(), file.size());
+					zipCloseFileInZip(dst_pkg_zip);
+				}
 			}
 			}
 		}
 		}
 	}
 	}

+ 9 - 2
platform/windows/os_windows.cpp

@@ -1633,6 +1633,13 @@ void OS_Windows::_update_window_style(bool repaint) {
 
 
 Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
 Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
 
 
+	String path = p_path;
+
+	if (!FileAccess::exists(path)) {
+		//this code exists so gdnative can load .dll files from within the executable path
+		path = get_executable_path().get_base_dir().plus_file(p_path.get_file());
+	}
+
 	typedef DLL_DIRECTORY_COOKIE(WINAPI * PAddDllDirectory)(PCWSTR);
 	typedef DLL_DIRECTORY_COOKIE(WINAPI * PAddDllDirectory)(PCWSTR);
 	typedef BOOL(WINAPI * PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
 	typedef BOOL(WINAPI * PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
 
 
@@ -1643,10 +1650,10 @@ Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_han
 	DLL_DIRECTORY_COOKIE cookie;
 	DLL_DIRECTORY_COOKIE cookie;
 
 
 	if (p_also_set_library_path && has_dll_directory_api) {
 	if (p_also_set_library_path && has_dll_directory_api) {
-		cookie = add_dll_directory(p_path.get_base_dir().c_str());
+		cookie = add_dll_directory(path.get_base_dir().c_str());
 	}
 	}
 
 
-	p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
+	p_library_handle = (void *)LoadLibraryExW(path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
 
 
 	if (p_also_set_library_path && has_dll_directory_api) {
 	if (p_also_set_library_path && has_dll_directory_api) {
 		remove_dll_directory(cookie);
 		remove_dll_directory(cookie);