Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ jobs:
# The unit tests assume the downloadable resources they need are already downloaded
# (see Packages/Resources/ResourceDownloadList.json). Unzip them from the Packages
# checkout into where the program looks for them, DOWNLOADED_RESOURCE_PATH():
# the working directory on Windows/Linux, and ~/Library/Application Support/SerialPrograms
# on macOS.
# the working directory on Windows/Linux, and ~/Library/Application Support/SerialPrograms/Profiles/unit-tests
# on macOS (the isolated test profile).
- name: Install downloadable resources for tests
if: inputs.run-tests
shell: bash
run: |
if [[ "${{inputs.os}}" == mac* ]]; then
DOWNLOADED_RESOURCES="$HOME/Library/Application Support/SerialPrograms/DownloadedResources"
DOWNLOADED_RESOURCES="$HOME/Library/Application Support/SerialPrograms/Profiles/unit-tests/DownloadedResources"
else
DOWNLOADED_RESOURCES="Arduino-Source/SerialPrograms/bin/DownloadedResources"
fi
Expand Down Expand Up @@ -289,6 +289,27 @@ jobs:
cd Arduino-Source/SerialPrograms/bin
./SerialPrograms --command-line-test-mode

- name: Reject unsafe lab launches (Mac)
if: startsWith(inputs.os, 'mac') && inputs.run-tests
shell: bash
run: |
cd Arduino-Source/SerialPrograms/bin
binary=./SerialPrograms.app/Contents/MacOS/SerialPrograms
expect_rejection() {
local status=0
"$binary" "$@" || status=$?
if [[ "$status" != 2 ]]; then
echo "Expected startup rejection (2), read $status"
exit 1
fi
}
expect_rejection --test bdsp
expect_rejection --profile
expect_rejection --profile ../lab-A
expect_rejection --command-line-test-mode --profile lab-A
# CI's default build has no PA_LAB_PROFILE: unprofiled relaunch must fail.
expect_rejection

- name: Run tests (Mac)
if: startsWith(inputs.os, 'mac') && inputs.run-tests
run: |
Expand Down
9 changes: 5 additions & 4 deletions Common/Cpp/Filesystem/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef PokemonAutomation_Filesystem_Filesystem_H
#define PokemonAutomation_Filesystem_Filesystem_H

#include <string_view>
#include <cstdint>
#include <vector>
#include "FilePath.h"
Expand Down Expand Up @@ -115,11 +116,11 @@ Path application_install_path();
Path application_scratch_path();


// Set a profile for program settings (/UserSettings/PROFILE_NAME/) on MacOS.
// Have to run the program with command-line argument "open -n PATH_TO_APP --args --profile PROFILE_NAME" to set the profile and launch a new window.
// This allows multiple instances of the program to run since settings are no longer shared.
#if defined(__APPLE__)
void set_startup_profile(int& argc, char* argv[]);
// Set a validated macOS settings profile before any settings paths are cached.
// GUI launch uses --profile NAME or the build-bound PA_LAB_PROFILE identity.
void set_startup_profile(std::string_view profile);
// Return the identity used for the window title and scratch directory.
const std::string& STARTUP_PROFILE();
#endif

Expand Down
19 changes: 3 additions & 16 deletions Common/Cpp/Filesystem/Filesystem_Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,9 @@ namespace Filesystem{

static std::string g_startup_profile;

void set_startup_profile(int& argc, char* argv[]){
for (int i = 1; i + 1 < argc; i++){
if (strcmp(argv[i], "--profile") == 0){
std::string profile = argv[i + 1];
for (char c : profile){
if (!(std::isalpha(c) || std::isdigit(c)) && c != u'_' && c != u'-') c = u'_';
}
g_startup_profile = std::move(profile);
// Shift everything after --profile <name> down by 2.
for (int j = i; j + 2 < argc; j++){
argv[j] = argv[j + 2];
}
argc -= 2;
return;
}
}
// Store the already-validated identity before any scratch/settings path is cached.
void set_startup_profile(std::string_view profile){
g_startup_profile = profile;
}

const std::string& STARTUP_PROFILE(){
Expand Down
9 changes: 9 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ if (APPLE)
# https://stackoverflow.com/questions/53560288/how-to-create-a-macos-app-bundle-with-cmake
# https://cmake.org/cmake/help/latest/command/add_executable.html
add_executable(SerialPrograms MACOSX_BUNDLE ${SerialPrograms_ICON} ${EXECUTABLE_SOURCES})
# Compiled identity survives Finder/TCC relaunch without command-line arguments.
set(PA_LAB_PROFILE "" CACHE STRING "Bind this lab binary to one macOS settings profile")
if(NOT PA_LAB_PROFILE STREQUAL "")
if(NOT PA_LAB_PROFILE MATCHES "^[A-Za-z0-9_][A-Za-z0-9_-]*$")
message(FATAL_ERROR "PA_LAB_PROFILE must contain only ASCII letters, digits, '_' or '-'.")
endif()
target_compile_definitions(SerialPrograms PRIVATE PA_LAB_PROFILE="${PA_LAB_PROFILE}")
endif()

set_target_properties(SerialPrograms PROPERTIES
BUNDLE True
MACOSX_BUNDLE_GUI_IDENTIFIER PokemonAutomation.SerialPrograms
Expand Down
Loading
Loading