From a49d9bd160e1a55bee7529d71498c7251f5de03e Mon Sep 17 00:00:00 2001 From: Sam Tupy Date: Wed, 9 Oct 2024 21:01:08 -0500 Subject: [PATCH] resolving more MacOS edgecases * Finally fixes app bundle include path resolution on the command line! * NVGT now changes to the current directory of the script when the open command is invoked as well. * Shared libraries in the MacOS app bundle are now located for copying properly. This rereleases 0.89.1-beta. --- doc/src/appendix/Changelog.md | 3 ++- .../manual/compiling your project for distribution.md | 2 +- src/nvgt.cpp | 9 ++++++--- src/xplatform.cpp | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/src/appendix/Changelog.md b/doc/src/appendix/Changelog.md index 9d88a13b..6f0d60a1 100644 --- a/doc/src/appendix/Changelog.md +++ b/doc/src/appendix/Changelog.md @@ -3,7 +3,8 @@ This document lists all major changes that have taken place in NVGT since we sta ## New in 0.89.1-beta (10/09/2024): * Fixes copying of shared libraries while bundling on MacOS which was resulting in an assertion violation from Poco. -* Fixes MacOS not changing to the directory of scripts launched from finder. +* Fixes MacOS not changing to the directory of scripts launched from finder or the open command. +* Hopefully we've finally resolved all of the MacOS includes resolution issues, there should be no more manually adding include paths to your scripts or command line invocations! * Fixes the enter key not pressing the default button in audio form lists. * Linux cross compilation should work again, the Linux build script was pulling down the wrong version of Angelscript. * `#pragma platform` has been deprecated, you should use the command line / menu options / UI to specify platforms instead. diff --git a/doc/src/manual/compiling your project for distribution.md b/doc/src/manual/compiling your project for distribution.md index f0ee2487..006b4207 100644 --- a/doc/src/manual/compiling your project for distribution.md +++ b/doc/src/manual/compiling your project for distribution.md @@ -36,7 +36,7 @@ When compiling on a non-windows platform, the executable permission bitt on the * Now run /path/to/nvgt -c scriptname.nvgt where scriptname.nvgt should of course be replaced with the name of your script file. You can select a platform with the -p argument E. -pwindows. * On Mac OS, it's best to just click on the NVGT application directly. * After launching NVGT you can select compile a script in release/debug mode, choose a platform, and browse to your script file. - * If, however, you wish to build on MacOS using the command line, cd to the directory containing a .nvgt script and run the convoluted and to be improved command /applications/nvgt.app/Contents/MacOS/nvgt ``pwd``/scriptname.nvgt -I/applications/nvgt.app/Contents/Resources/include + * If, however, you wish to build on MacOS using the command line, cd to the directory containing a .nvgt script and run the command /applications/nvgt.app/Contents/MacOS/nvgt -c scriptname.nvgt, or alternatively open -a nvgt --args -c \`pwd\`/scriptname.nvgt You will receive a popup or STDOut print letting you know how long the compilation took. You should find a new file in the same folder you just compiled that has the same name it does but with a different extension e.g. when compiling my_game.nvgt you'll have my_game.exe. Distribute this along with the necessary libraries in what ever form is required. You can set it all up with an installer, such as Inno Setup, or if your game will be portable you can just zip it up, etc. diff --git a/src/nvgt.cpp b/src/nvgt.cpp index 13be1733..a784c3d9 100644 --- a/src/nvgt.cpp +++ b/src/nvgt.cpp @@ -92,10 +92,11 @@ class nvgt_application : public Poco::Util::Application { config().setString("application.gui", ""); #ifdef NVGT_STUB ChDir(resources_dir); - #else - g_IncludeDirs.push_back(Path(resources_dir).pushDirectory("include").toString()); #endif } + #ifndef NVGT_STUB + if (File(resources_dir).exists()) g_IncludeDirs.push_back(Path(resources_dir).pushDirectory("include").toString()); + #endif #elif defined(__ANDROID__) config().setString("application.gui", ""); #endif @@ -210,7 +211,6 @@ class nvgt_application : public Poco::Util::Application { string scriptfile = ""; #if defined(__APPLE__) || defined(__ANDROID__) scriptfile = event_requested_file(); // Files opened from external apps on MacOS, IOS, and Android do not use command line arguments. - if (!scriptfile.empty()) ChDir(Path(scriptfile).makeParent().toString()); #endif if (scriptfile.empty() && args.size() > 0) scriptfile = args[0]; if (scriptfile.empty() && config().hasOption("application.gui")) scriptfile = UILauncher(); @@ -227,6 +227,9 @@ class nvgt_application : public Poco::Util::Application { message("error, no input files.\nType " + commandName() + " --help for usage instructions\n", commandName()); return Application::EXIT_USAGE; } + #ifdef __APPLE__ // When run from an app bundle + if (!scriptfile.empty() && Path::current() == "/") ChDir(Path(scriptfile).makeParent().toString()); + #endif #ifndef __ANDROID__ // for now the following code would be highly unstable on android due to it's content URIs. try { // Parse the provided script path to insure it is valid and check if it is a file. diff --git a/src/xplatform.cpp b/src/xplatform.cpp index a385284a..ebcfd9ca 100644 --- a/src/xplatform.cpp +++ b/src/xplatform.cpp @@ -54,14 +54,15 @@ void xplatform_correct_path_to_stubs(Poco::Path& stubpath) { std::string get_nvgt_lib_directory(const std::string& platform) { // The directory containing the libraries for the NVGT currently running is usually just called lib, while all other directories are lib_platform. In any case try to return an absolute path to the libraries given a platform. std::string dir; + bool apple_bundle = File(Path(Path::self()).makeParent().makeParent().pushDirectory("Frameworks").toString()).exists(); if (platform == "windows") dir = Poco::Environment::isWindows()? "lib" : "lib_windows"; - else if (platform == "mac") dir = Environment::os() == POCO_OS_MAC_OS_X? (Environment::has("MACOS_BUNDLED_APP")? "Frameworks" : "lib") : "lib_mac"; + else if (platform == "mac") dir = Environment::os() == POCO_OS_MAC_OS_X? (apple_bundle? "Frameworks" : "lib") : "lib_mac"; else if (platform == "linux") dir = Poco::Environment::os() == POCO_OS_LINUX? "lib" : "lib_linux"; else return ""; // libs not applicable for this platform. Path result(Path::self()); result.makeParent(); #ifdef __APPLE__ - if (Environment::has("MACOS_BUNDLED_APP")) { + if (apple_bundle) { result.makeParent(); if (platform != "mac") result.append("Resources"); }