-
-
Notifications
You must be signed in to change notification settings - Fork 506
ci(macos): Add App Bundle artifacts and runtime data discovery #2050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TmLev
wants to merge
2
commits into
OpenXRay:dev
Choose a base branch
from
TmLev:tmlev/1780-macos-app-bundle
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| if [[ $# -lt 2 ]]; then | ||
| echo "Usage: $0 <arch> <configuration>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| ARCH="$1" | ||
| CONFIGURATION="$2" | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| ROOT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)" | ||
| BIN_DIR="${ROOT_DIR}/bin/${ARCH}/${CONFIGURATION}" | ||
| ARTIFACTS_DIR="${ROOT_DIR}/build/artifacts" | ||
|
|
||
| APP_DIR="${ARTIFACTS_DIR}/OpenXRay.app" | ||
| CONTENTS_DIR="${APP_DIR}/Contents" | ||
| MACOS_DIR="${CONTENTS_DIR}/MacOS" | ||
| LIBS_DIR="${CONTENTS_DIR}/libs" | ||
| RESOURCES_DIR="${CONTENTS_DIR}/Resources" | ||
| OXR_RES_DIR="${RESOURCES_DIR}/openxray" | ||
|
|
||
| if [[ ! -x "${BIN_DIR}/xr_3da" ]]; then | ||
| echo "Cannot find executable: ${BIN_DIR}/xr_3da" | ||
| exit 1 | ||
| fi | ||
|
|
||
| for tool in install_name_tool dylibbundler ditto hdiutil; do | ||
| if ! command -v "${tool}" >/dev/null 2>&1; then | ||
| echo "Required tool is missing: ${tool}" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| mkdir -p "${ARTIFACTS_DIR}" | ||
| rm -rf "${APP_DIR}" | ||
| mkdir -p "${MACOS_DIR}" "${LIBS_DIR}" "${OXR_RES_DIR}" | ||
|
|
||
| cat > "${CONTENTS_DIR}/Info.plist" <<'PLIST' | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleName</key> | ||
| <string>OpenXRay</string> | ||
| <key>CFBundleDisplayName</key> | ||
| <string>OpenXRay</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>org.openxray.xray-16</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>APPL</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>xr_3da</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>1</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>1.0</string> | ||
| <key>LSApplicationCategoryType</key> | ||
| <string>public.app-category.games</string> | ||
| <key>NSHighResolutionCapable</key> | ||
| <true/> | ||
| </dict> | ||
| </plist> | ||
| PLIST | ||
|
|
||
| printf 'APPL????' > "${CONTENTS_DIR}/PkgInfo" | ||
|
|
||
| cp "${BIN_DIR}/xr_3da" "${MACOS_DIR}/xr_3da" | ||
| chmod +x "${MACOS_DIR}/xr_3da" | ||
|
|
||
| find "${BIN_DIR}" -maxdepth 1 -type f -name '*.dylib' -exec cp {} "${LIBS_DIR}/" \; | ||
|
|
||
| # Bundle only open-source engine resources from this repository. | ||
| cp "${ROOT_DIR}/res/fsgame.ltx" "${OXR_RES_DIR}/fsgame.ltx" | ||
| cp -R "${ROOT_DIR}/res/gamedata" "${OXR_RES_DIR}/gamedata" | ||
|
|
||
| # Ensure runtime can resolve in-bundle libraries. | ||
| install_name_tool -add_rpath "@executable_path/../libs" "${MACOS_DIR}/xr_3da" || true | ||
| for lib in "${LIBS_DIR}"/*.dylib; do | ||
| [[ -e "${lib}" ]] || continue | ||
| install_name_tool -add_rpath "@loader_path" "${lib}" || true | ||
| done | ||
|
|
||
| # Bundle non-system dynamic libraries (Homebrew deps etc.). | ||
| dylibbundler \ | ||
| -of -cd -b \ | ||
| -x "${MACOS_DIR}/xr_3da" \ | ||
| -d "${LIBS_DIR}" \ | ||
| -s "${BIN_DIR}" \ | ||
| -s "${LIBS_DIR}" | ||
|
|
||
| APP_ZIP="${ARTIFACTS_DIR}/openxray-${CONFIGURATION}-${ARCH}.app.zip" | ||
| DMG_PATH="${ARTIFACTS_DIR}/openxray-${CONFIGURATION}-${ARCH}.dmg" | ||
|
|
||
| rm -f "${APP_ZIP}" "${DMG_PATH}" | ||
| ditto -c -k --sequesterRsrc --keepParent "${APP_DIR}" "${APP_ZIP}" | ||
| hdiutil create -volname "OpenXRay ${CONFIGURATION} ${ARCH}" -srcfolder "${APP_DIR}" -format UDZO -ov "${DMG_PATH}" | ||
|
|
||
| echo "Created:" | ||
| echo " ${APP_ZIP}" | ||
| echo " ${DMG_PATH}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -799,6 +799,182 @@ bool CLocatorAPI::Recurse(pcstr path) | |||||||||
| bool file_handle_internal(pcstr file_name, size_t& size, int& file_handle); | ||||||||||
| void* FileDownload(pcstr file_name, const int& file_handle, size_t& file_size); | ||||||||||
|
|
||||||||||
| #if defined(XR_PLATFORM_APPLE) | ||||||||||
| static bool IsDirectory(pcstr path) | ||||||||||
| { | ||||||||||
| struct stat st; | ||||||||||
| return stat(path, &st) == 0 && S_ISDIR(st.st_mode); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool IsFile(pcstr path) | ||||||||||
| { | ||||||||||
| struct stat st; | ||||||||||
| return stat(path, &st) == 0 && S_ISREG(st.st_mode); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool HasRequiredGameData(pcstr rootPath) | ||||||||||
| { | ||||||||||
| if (!rootPath || !rootPath[0]) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| string_path path; | ||||||||||
| xr_sprintf(path, "%s/levels", rootPath); | ||||||||||
| if (!IsDirectory(path)) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| xr_sprintf(path, "%s/resources", rootPath); | ||||||||||
| if (!IsDirectory(path)) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| xr_sprintf(path, "%s/localization", rootPath); | ||||||||||
| return IsDirectory(path); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool PromptForGameRoot(string_path& outPath) | ||||||||||
| { | ||||||||||
| static constexpr pcstr command = | ||||||||||
| "osascript " | ||||||||||
| "-e 'try' " | ||||||||||
| "-e 'POSIX path of (choose folder with prompt \"Select S.T.A.L.K.E.R. game data directory (levels/resources/localization)\")' " | ||||||||||
| "-e 'on error number -128' " | ||||||||||
| "-e 'return \"\"' " | ||||||||||
| "-e 'end try'"; | ||||||||||
|
|
||||||||||
| FILE* pipe = popen(command, "r"); | ||||||||||
| if (!pipe) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| string_path buffer; | ||||||||||
| buffer[0] = 0; | ||||||||||
| const bool hasValue = fgets(buffer, sizeof(buffer), pipe) != nullptr; | ||||||||||
| pclose(pipe); | ||||||||||
| if (!hasValue) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| size_t len = SDL_strlen(buffer); | ||||||||||
| while (len > 0 && (buffer[len - 1] == '\n' || buffer[len - 1] == '\r')) | ||||||||||
| buffer[--len] = 0; | ||||||||||
|
|
||||||||||
| if (len == 0) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| SDL_strlcpy(outPath, buffer, sizeof(outPath)); | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static void LinkIfMissing(pcstr prefPath, pcstr gameRoot, pcstr dirName) | ||||||||||
| { | ||||||||||
| string_path targetPath; | ||||||||||
| xr_sprintf(targetPath, "%s/%s", gameRoot, dirName); | ||||||||||
| if (!IsDirectory(targetPath)) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| string_path linkPath; | ||||||||||
| xr_sprintf(linkPath, "%s%s", prefPath, dirName); | ||||||||||
|
|
||||||||||
| struct stat st; | ||||||||||
| if (lstat(linkPath, &st) == 0) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| symlink(targetPath, linkPath); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static void LinkGameDataIntoPrefPath(pcstr prefPath, pcstr gameRoot) | ||||||||||
| { | ||||||||||
| static constexpr pcstr dirs[] = {"levels", "resources", "localization", "mp", "patches"}; | ||||||||||
| for (const auto dir : dirs) | ||||||||||
| LinkIfMissing(prefPath, gameRoot, dir); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool TryUseGameRoot(pcstr prefPath, pcstr gameRoot) | ||||||||||
| { | ||||||||||
| if (!HasRequiredGameData(gameRoot)) | ||||||||||
| return false; | ||||||||||
|
|
||||||||||
| LinkGameDataIntoPrefPath(prefPath, gameRoot); | ||||||||||
| return HasRequiredGameData(prefPath); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool ResolveFromPopularGameLocations(pcstr prefPath) | ||||||||||
| { | ||||||||||
| const char* home = SDL_getenv("HOME"); | ||||||||||
| if (home && home[0]) | ||||||||||
| { | ||||||||||
| string_path steamPath; | ||||||||||
| xr_sprintf(steamPath, "%s/Library/Application Support/Steam/steamapps/common/STALKER Call of Pripyat", home); | ||||||||||
| if (TryUseGameRoot(prefPath, steamPath)) | ||||||||||
| return true; | ||||||||||
|
|
||||||||||
| string_path gogPath; | ||||||||||
| xr_sprintf(gogPath, "%s/GOG Games/S.T.A.L.K.E.R. - Call of Pripyat", home); | ||||||||||
| if (TryUseGameRoot(prefPath, gogPath)) | ||||||||||
| return true; | ||||||||||
|
|
||||||||||
| string_path applicationsPath; | ||||||||||
| xr_sprintf(applicationsPath, "%s/Applications/S.T.A.L.K.E.R. - Call of Pripyat", home); | ||||||||||
| if (TryUseGameRoot(prefPath, applicationsPath)) | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return TryUseGameRoot(prefPath, "/Applications/S.T.A.L.K.E.R. - Call of Pripyat"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static void ResolveGameDataForMac(pcstr prefPath) | ||||||||||
| { | ||||||||||
| if (HasRequiredGameData(prefPath)) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| const bool runningFromBundle = strstr(Core.ApplicationPath, ".app/Contents/MacOS/") != nullptr; | ||||||||||
| if (!runningFromBundle) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| string_path bundleNeighborRoot; | ||||||||||
| xr_sprintf(bundleNeighborRoot, "%s../../..", Core.ApplicationPath); | ||||||||||
| if (TryUseGameRoot(prefPath, bundleNeighborRoot)) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| if (ResolveFromPopularGameLocations(prefPath)) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| string_path selectedRoot; | ||||||||||
| selectedRoot[0] = 0; | ||||||||||
| if (PromptForGameRoot(selectedRoot) && TryUseGameRoot(prefPath, selectedRoot)) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| SDL_ShowSimpleMessageBox( | ||||||||||
| SDL_MESSAGEBOX_WARNING, | ||||||||||
| "OpenXRay: game files are required", | ||||||||||
| "OpenXRay could not find required game files (levels/resources/localization).\n" | ||||||||||
| "Please select the game directory when prompted or copy the game files into\n" | ||||||||||
| "~/Library/Application Support/GSC Game World/S.T.A.L.K.E.R. - Call of Pripyat/", | ||||||||||
| nullptr); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| static bool ResolveOpenXRayResourcesPath(string_path& outPath) | ||||||||||
| { | ||||||||||
| string_path bundleResourcesPath; | ||||||||||
| xr_sprintf(bundleResourcesPath, "%s../Resources/openxray", Core.ApplicationPath); | ||||||||||
|
|
||||||||||
| string_path bundleFsgamePath; | ||||||||||
| xr_sprintf(bundleFsgamePath, "%s/fsgame.ltx", bundleResourcesPath); | ||||||||||
| if (IsFile(bundleFsgamePath)) | ||||||||||
| { | ||||||||||
| SDL_strlcpy(outPath, bundleResourcesPath, sizeof(outPath)); | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| string_path installedFsgamePath; | ||||||||||
| xr_sprintf(installedFsgamePath, "%s/openxray/fsgame.ltx", CMAKE_INSTALL_FULL_DATAROOTDIR); | ||||||||||
| if (IsFile(installedFsgamePath)) | ||||||||||
| { | ||||||||||
| xr_sprintf(outPath, "%s/openxray", CMAKE_INSTALL_FULL_DATAROOTDIR); | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return false; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| void CLocatorAPI::setup_fs_path(pcstr fs_name, string_path& fs_path) | ||||||||||
| { | ||||||||||
| xr_strcpy(fs_path, fs_name ? fs_name : ""); | ||||||||||
|
|
@@ -851,8 +1027,10 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name) | |||||||||
| * I propose adding shaders from <CMAKE_INSTALL_FULL_DATAROOTDIR>/openxray/gamedata/shaders so that we remove unnecessary questions from users who want to start | ||||||||||
| * the game using resources not from the proposed ~/.local/share/GSC Game World/Game in this case, this section of code can be safely removed */ | ||||||||||
| chdir(pref_path); | ||||||||||
| static constexpr pcstr install_dir = CMAKE_INSTALL_FULL_DATAROOTDIR; | ||||||||||
| string_path tmp, tmp_link; | ||||||||||
| #if defined(XR_PLATFORM_APPLE) | ||||||||||
| ResolveGameDataForMac(pref_path); | ||||||||||
| #endif | ||||||||||
| xr_sprintf(tmp, "%sfsgame.ltx", pref_path); | ||||||||||
| struct stat statbuf; | ||||||||||
| ZeroMemory(&statbuf, sizeof(statbuf)); | ||||||||||
|
|
@@ -868,7 +1046,13 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name) | |||||||||
| res = lstat(tmp, &statbuf); | ||||||||||
| if (res == 0) | ||||||||||
| xr_unlink(tmp); | ||||||||||
| xr_sprintf(tmp_link, "%s/openxray/fsgame.ltx", install_dir); | ||||||||||
| #if defined(XR_PLATFORM_APPLE) | ||||||||||
| string_path resourcesRoot; | ||||||||||
| if (ResolveOpenXRayResourcesPath(resourcesRoot)) | ||||||||||
| xr_sprintf(tmp_link, "%s/fsgame.ltx", resourcesRoot); | ||||||||||
| else | ||||||||||
| #endif | ||||||||||
| xr_sprintf(tmp_link, "%s/openxray/fsgame.ltx", CMAKE_INSTALL_FULL_DATAROOTDIR); | ||||||||||
| symlink(tmp_link, tmp); | ||||||||||
| } | ||||||||||
| xr_sprintf(tmp, "%sgamedata/shaders/gl", pref_path); | ||||||||||
|
|
@@ -885,7 +1069,13 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name) | |||||||||
| mkdir("gamedata", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); | ||||||||||
| mkdir("gamedata/shaders", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); | ||||||||||
| } | ||||||||||
| xr_sprintf(tmp_link, "%s/openxray/gamedata/shaders/gl", install_dir); | ||||||||||
| #if defined(XR_PLATFORM_APPLE) | ||||||||||
| string_path resourcesRoot; | ||||||||||
| if (ResolveOpenXRayResourcesPath(resourcesRoot)) | ||||||||||
| xr_sprintf(tmp_link, "%s/gamedata/shaders/gl", resourcesRoot); | ||||||||||
| else | ||||||||||
| #endif | ||||||||||
| xr_sprintf(tmp_link, "%s/openxray/gamedata/shaders/gl", CMAKE_INSTALL_FULL_DATAROOTDIR); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always enclose the else body into {} when if and else are under the #ifdef.
Suggested change
|
||||||||||
| symlink(tmp_link, tmp); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always enclose the else body into {} when if and else are under the #ifdef.