From fa51c1584981db26c4b547f748a86423dc9f7bf8 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Wed, 6 Jun 2018 14:29:53 -0700 Subject: [PATCH] Use binary resources on OSX --- interface/CMakeLists.txt | 42 ++++++++++++------------- interface/src/Application.cpp | 10 +----- libraries/shared/src/PathUtils.cpp | 50 +++++++++++++----------------- libraries/shared/src/PathUtils.h | 1 + 4 files changed, 45 insertions(+), 58 deletions(-) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index ac9441319b..4204718976 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -133,13 +133,7 @@ if (APPLE) # set where in the bundle to put the resources file set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/icon/${INTERFACE_ICON_FILENAME} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - set(DISCOVERED_RESOURCES "") - - # use the add_resources_to_os_x_bundle macro to recurse into resources - add_resources_to_os_x_bundle("${CMAKE_CURRENT_SOURCE_DIR}/resources") - # append the discovered resources to our list of interface sources - list(APPEND INTERFACE_SRCS ${DISCOVERED_RESOURCES}) list(APPEND INTERFACE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/icon/${INTERFACE_ICON_FILENAME}) endif() @@ -316,18 +310,27 @@ if (APPLE) set(SCRIPTS_INSTALL_DIR "${INTERFACE_INSTALL_APP_PATH}/Contents/Resources") set(RESOURCES_DEV_DIR "$/../Resources") - # copy script files beside the executable add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + # copy script files beside the executable COMMAND "${CMAKE_COMMAND}" -E copy_directory - "${CMAKE_SOURCE_DIR}/scripts" - "${RESOURCES_DEV_DIR}/scripts" - ) - - # copy JSDoc files beside the executable - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + "${CMAKE_SOURCE_DIR}/scripts" + "${RESOURCES_DEV_DIR}/scripts" + # copy JSDoc files beside the executable COMMAND "${CMAKE_COMMAND}" -E copy_directory - "${CMAKE_SOURCE_DIR}/tools/jsdoc/out" - "${RESOURCES_DEV_DIR}/jsdoc" + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out" + "${RESOURCES_DEV_DIR}/jsdoc" + # copy the resources files beside the executable + COMMAND "${CMAKE_COMMAND}" -E copy_if_different + "${RESOURCES_RCC}" + "${RESOURCES_DEV_DIR}" + # FIXME, the edit script code loads HTML from the scripts folder + # which in turn relies on CSS that refers to the fonts. In theory + # we should be able to modify the CSS to reference the QRC path to + # the ttf files, but doing so generates a CORS policy violation, + # so we have to retain a copy of the fonts outside of the resources binary + COMMAND "${CMAKE_COMMAND}" -E copy_directory + "${PROJECT_SOURCE_DIR}/resources/fonts" + "${RESOURCES_DEV_DIR}/fonts" ) # call the fixup_interface macro to add required bundling commands for installation @@ -356,13 +359,10 @@ else() COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${PROJECT_SOURCE_DIR}/resources/serverless/tutorial.json" "${RESOURCES_DEV_DIR}/serverless/tutorial.json" - ) - - # copy JSDoc files beside the executable - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD + # copy JSDoc files beside the executable COMMAND "${CMAKE_COMMAND}" -E copy_directory - "${CMAKE_SOURCE_DIR}/tools/jsdoc/out" - "${INTERFACE_EXEC_DIR}/jsdoc" + "${CMAKE_SOURCE_DIR}/tools/jsdoc/out" + "${INTERFACE_EXEC_DIR}/jsdoc" ) # link target to external libraries diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index cbe713127d..baafdd1fcd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -802,15 +802,8 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { qApp->setProperty(hifi::properties::APP_LOCAL_DATA_PATH, cacheDir); } - // FIXME fix the OSX installer to install the resources.rcc binary instead of resource files and remove - // this conditional exclusion -#if !defined(Q_OS_OSX) { -#if defined(Q_OS_ANDROID) - const QString resourcesBinaryFile = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/resources.rcc"; -#else - const QString resourcesBinaryFile = QCoreApplication::applicationDirPath() + "/resources.rcc"; -#endif + const QString resourcesBinaryFile = PathUtils::getRccPath(); if (!QFile::exists(resourcesBinaryFile)) { throw std::runtime_error("Unable to find primary resources"); } @@ -818,7 +811,6 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { throw std::runtime_error("Unable to load primary resources"); } } -#endif // Tell the plugin manager about our statically linked plugins auto pluginManager = PluginManager::getInstance(); diff --git a/libraries/shared/src/PathUtils.cpp b/libraries/shared/src/PathUtils.cpp index b5c76257ef..7fc94db6af 100644 --- a/libraries/shared/src/PathUtils.cpp +++ b/libraries/shared/src/PathUtils.cpp @@ -32,15 +32,13 @@ #include "shared/GlobalAppProperties.h" #include "SharedUtil.h" + // Format: AppName-PID-Timestamp // Example: ... QString TEMP_DIR_FORMAT { "%1-%2-%3" }; #if !defined(Q_OS_ANDROID) && defined(DEV_BUILD) static bool USE_SOURCE_TREE_RESOURCES() { -#if defined(Q_OS_OSX) - return true; -#else static bool result = false; static std::once_flag once; std::call_once(once, [&] { @@ -48,10 +46,28 @@ static bool USE_SOURCE_TREE_RESOURCES() { result = QProcessEnvironment::systemEnvironment().contains(USE_SOURCE_TREE_RESOURCES_FLAG); }); return result; -#endif } #endif +const QString& PathUtils::getRccPath() { + static QString rccLocation; + static std::once_flag once; + std::call_once(once, [&] { + static const QString rccName{ "/resources.rcc" }; +#if defined(Q_OS_OSX) + char buffer[8192]; + uint32_t bufferSize = sizeof(buffer); + _NSGetExecutablePath(buffer, &bufferSize); + rccLocation = QDir::cleanPath(QFileInfo(buffer).dir().absoluteFilePath("../Resources")) + rccName; +#elif defined(Q_OS_ANDROID) + rccLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + rccName; +#else + rccLocation = QCoreApplication::applicationDirPath() + rccName; +#endif + }); + return rccLocation; +} + #ifdef DEV_BUILD const QString& PathUtils::projectRootPath() { static QString sourceFolder; @@ -65,23 +81,9 @@ const QString& PathUtils::projectRootPath() { #endif const QString& PathUtils::resourcesPath() { - static QString staticResourcePath; + static QString staticResourcePath{ ":/" }; static std::once_flag once; std::call_once(once, [&]{ - -#if defined(Q_OS_OSX) - // FIXME fix the OSX installer to install the resources.rcc instead of the - // individual resource files - // FIXME the first call to fetch the resources location seems to return - // nothing for QCoreApplication::applicationDirPath() - char buffer[8192]; - uint32_t bufferSize = sizeof(buffer); - _NSGetExecutablePath(buffer, &bufferSize); - staticResourcePath = QDir::cleanPath(QFileInfo(buffer).dir().absoluteFilePath("../Resources")) + "/"; -#else - staticResourcePath = ":/"; -#endif - #if !defined(Q_OS_ANDROID) && defined(DEV_BUILD) if (USE_SOURCE_TREE_RESOURCES()) { // For dev builds, optionally load content from the Git source tree @@ -90,21 +92,13 @@ const QString& PathUtils::resourcesPath() { #endif qDebug() << "Resource path resolved to " << staticResourcePath; }); - return staticResourcePath; } const QString& PathUtils::resourcesUrl() { - static QString staticResourcePath; + static QString staticResourcePath{ "qrc:///" }; static std::once_flag once; std::call_once(once, [&]{ - -#if defined(Q_OS_OSX) - staticResourcePath = QUrl::fromLocalFile(resourcesPath()).toString(); -#else - staticResourcePath = "qrc:///"; -#endif - #if !defined(Q_OS_ANDROID) && defined(DEV_BUILD) if (USE_SOURCE_TREE_RESOURCES()) { // For dev builds, optionally load content from the Git source tree diff --git a/libraries/shared/src/PathUtils.h b/libraries/shared/src/PathUtils.h index fc933b6b8c..2247f4cc6a 100644 --- a/libraries/shared/src/PathUtils.h +++ b/libraries/shared/src/PathUtils.h @@ -37,6 +37,7 @@ class PathUtils : public QObject, public Dependency { Q_PROPERTY(QString resources READ resourcesPath CONSTANT) Q_PROPERTY(QUrl defaultScripts READ defaultScriptsLocation CONSTANT) public: + static const QString& getRccPath(); static const QString& resourcesUrl(); static QUrl resourcesUrl(const QString& relative); static const QString& resourcesPath();