From af55b5585462a5f053072d211b9ca82c065522d1 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Thu, 26 Nov 2026 04:14:35 +1100 Subject: [PATCH] Add macOS "Bundle data folder into .app" checkbox / --bundle-data flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The oF osx / macos templates ship an APPSTORE block that's commented out by default: //OF_CODESIGN = 1 //OF_BUNDLE_DATA_FOLDER = 1 //OF_BUNDLE_DYLIBS = 1 Uncommenting OF_BUNDLE_DATA_FOLDER = 1 makes xcode_project.sh rsync bin/data/ into the built .app on macOS — required for App Store builds and generally nicer for shipping a single bundle. Users were having to hand-edit Project.xcconfig every regen because .xcodeproj/ (and the xcconfig sitting next to it) is typically gitignored, so the toggle got lost on every update. Add an explicit toggle: - CLI: --bundle-data=1 uncomments the line; --bundle-data=0 re-comments it; no flag leaves the file alone. Applied after saveAppleSettings so the merge can't carry the previous project state past an explicit flag; if the merge happened to leave both commented and uncommented copies (a known quirk when the user had hand-enabled it), the toggle also collapses the duplicate. osx / macos targets only; a no-op for every other target. - GUI: a Semantic UI checkbox under Bundle ID in advanced mode, shown only when the selected platform includes osx or macos. The current state is read back from the project's Project.xcconfig on load (via readProjectSettings), so re-generating preserves what's on disk, and the user's own toggle is the last word. GUI 0.126.0, CLI 0.131.0. --- commandLine/src/defines.h | 2 +- commandLine/src/main.cpp | 18 ++++++++++-- commandLine/src/projects/baseProject.h | 4 +++ commandLine/src/projects/xcodeProject.cpp | 35 +++++++++++++++++++++++ frontend/app.js | 17 ++++++++++- frontend/index.html | 10 +++++++ frontend/index.js | 6 ++++ frontend/locales/en.json | 2 ++ frontend/npm-shrinkwrap.json | 4 +-- frontend/package.json | 2 +- frontend/project-settings.js | 5 +++- 11 files changed, 97 insertions(+), 8 deletions(-) diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index 69503b06..2cb13da0 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION "0" -#define OFPROJECTGENERATOR_MINOR_VERSION "130" +#define OFPROJECTGENERATOR_MINOR_VERSION "131" #define OFPROJECTGENERATOR_PATCH_VERSION "0" #define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION) diff --git a/commandLine/src/main.cpp b/commandLine/src/main.cpp index e43eef20..e8537f85 100644 --- a/commandLine/src/main.cpp +++ b/commandLine/src/main.cpp @@ -41,7 +41,8 @@ enum optionIndex { UNKNOWN, EMSCRIPTEN_WASM, APP_VERSION, APP_BUILD, - BUNDLE_ID + BUNDLE_ID, + BUNDLE_DATA }; constexpr option::Descriptor usage[] = { @@ -77,6 +78,7 @@ constexpr option::Descriptor usage[] = { { APP_VERSION, 0, "", "app-version", option::Arg::Optional, " --app-version \tapp version, eg 1.2.3 (default 1.0): config.make / CMake APP_VERSION, Xcode MARKETING_VERSION, Android versionName" }, { APP_BUILD, 0, "", "app-build", option::Arg::Optional, " --app-build \tbuild number, eg 42 (default 1): config.make / CMake APP_BUILD, Xcode CURRENT_PROJECT_VERSION, Android versionCode" }, { BUNDLE_ID, 0, "", "bundle-id", option::Arg::Optional, " --bundle-id \tbundle id, eg com.example.myApp (default cc.openFrameworks.): config.make / CMake APP_BUNDLE_ID, Xcode PRODUCT_BUNDLE_IDENTIFIER, Android applicationId" }, + { BUNDLE_DATA, 0, "", "bundle-data", option::Arg::Optional, " --bundle-data \tbundle the project's bin/data/ folder into the macOS .app on build: 1 (uncomment OF_BUNDLE_DATA_FOLDER in Project.xcconfig) | 0 (re-comment it). Only applied for osx / macos targets; empty leaves the xcconfig unchanged" }, { 0, 0, 0, 0, 0, 0 } }; @@ -114,6 +116,7 @@ string emscriptenWasm; // empty keeps the project's config.make value string appVersion; // empty keeps the project's value string appBuild; string appBundleId; // empty keeps the project's value +string bundleDataFolder; // empty = leave Project.xcconfig alone; "1" uncomments OF_BUNDLE_DATA_FOLDER, "0" re-comments it string ofPathEnv; string templateName; string msys2Env = "ucrt64"; @@ -290,6 +293,7 @@ void updateProject(const fs::path & path, const string & target, bool bConsiderP project->setEmscriptenWasm(emscriptenWasm); project->setAppVersion(appVersion, appBuild); project->setAppBundleId(appBundleId); + project->setBundleDataFolder(bundleDataFolder); project->setProjectDefinesPassed(bDefinesPassedIn); project->setSystemFrameworks(frameworks, bFrameworksPassedIn, systemLibs, bSystemLibsPassedIn); if (!project->create(path, templateName)) throw std::runtime_error("could not update project: " + path.string()); @@ -487,7 +491,7 @@ int pgMain(int argc, char ** argv) { // optionparser only takes attached values (-posx, --platforms=osx); join -p osx / --platforms osx, // but leave the last argument as the project path: -t"" (scripts, the GUI) is an empty -t static const std::string valueShort { "paotsmfDPkW" }; - static const std::vector valueLong { "platforms", "addons", "ofPath", "template", "source", "ofmenu", "frameworks", "system-libs", "defines", "postbuild", "msys2env", "emscripten-wasm", "app-version", "app-build", "bundle-id" }; + static const std::vector valueLong { "platforms", "addons", "ofPath", "template", "source", "ofmenu", "frameworks", "system-libs", "defines", "postbuild", "msys2env", "emscripten-wasm", "app-version", "app-build", "bundle-id", "bundle-data" }; std::vector joinedArgs; std::string platformBeforePath; for (int i = 0; i < argc; i++) { @@ -775,6 +779,15 @@ int pgMain(int argc, char ** argv) { } } + if (options[BUNDLE_DATA].count() > 0 && options[BUNDLE_DATA].arg != NULL) { + std::string v = ofTrim(options[BUNDLE_DATA].arg); + if (v == "0" || v == "1") { + bundleDataFolder = v; + } else { + ofLogWarning() << "bundle-data " << v << " should be 0 or 1 - keeping the project's Project.xcconfig"; + } + } + if (options[POSTBUILD].count() > 0 && options[POSTBUILD].arg != NULL) { postBuildScript = ofTrim(options[POSTBUILD].arg); } @@ -946,6 +959,7 @@ int pgMain(int argc, char ** argv) { project->setEmscriptenWasm(emscriptenWasm); project->setAppVersion(appVersion, appBuild); project->setAppBundleId(appBundleId); + project->setBundleDataFolder(bundleDataFolder); project->setProjectDefinesPassed(bDefinesPassedIn); project->setSystemFrameworks(frameworks, bFrameworksPassedIn, systemLibs, bSystemLibsPassedIn); if (!project->create(projectPath, templateName)) return EXIT_FAILURE; diff --git a/commandLine/src/projects/baseProject.h b/commandLine/src/projects/baseProject.h index 15b3d435..7b6b8c1d 100644 --- a/commandLine/src/projects/baseProject.h +++ b/commandLine/src/projects/baseProject.h @@ -126,6 +126,9 @@ class baseProject { void setAppVersion(const std::string & version, const std::string & build) { appVersionOption = version; appBuildOption = build; } // bundle id (--bundle-id), written to config.make APP_BUNDLE_ID; empty keeps the project's (default cc.openFrameworks.) void setAppBundleId(const std::string & bundleId) { appBundleIdOption = bundleId; } + // Bundle data folder (--bundle-data=0|1): toggle OF_BUNDLE_DATA_FOLDER in Project.xcconfig for osx / macos targets. + // Empty leaves the xcconfig unchanged; "1" uncomments the line so the macOS .app bundles bin/data/ on build; "0" re-comments it. + virtual void setBundleDataFolder(const std::string & value) { bundleDataFolderOption = value; } #ifdef OFADDON_OUTPUT_JSON_DEBUG @@ -214,6 +217,7 @@ class baseProject { std::string appBundleIdOption; // from the CLI, empty = keep std::string appBundleId; // value for this project, empty = the template's cc.openFrameworks. void saveAppBundleIdFiles(); + std::string bundleDataFolderOption; // from --bundle-data, empty = leave Project.xcconfig alone, "1" / "0" = uncomment / comment OF_BUNDLE_DATA_FOLDER //cached addons - if an addon is requested more than once, avoid loading from disk as it's quite slow std::map> addonsCache; //indexed by [platform][supplied path] diff --git a/commandLine/src/projects/xcodeProject.cpp b/commandLine/src/projects/xcodeProject.cpp index cef1870e..7e7b86b8 100644 --- a/commandLine/src/projects/xcodeProject.cpp +++ b/commandLine/src/projects/xcodeProject.cpp @@ -2008,6 +2008,41 @@ bool xcodeProject::saveProjectFile() { ofLogError(LOG_NAME) << "Cannot save Apple settings: " << e.what(); return false; } + // --bundle-data=1|0 (osx / macos only): toggle the APPSTORE line that bundles bin/data/ + // into the .app. The templates ship it commented out; this is applied after + // saveAppleSettings' merge so the explicit flag is the final word, overriding both the + // template default and any previous project state the merge would otherwise carry over. + // If the merge left multiple OF_BUNDLE_DATA_FOLDER lines (template-commented + user- + // uncommented), the first matching line is rewritten and the rest are dropped. + if ((target == "osx" || target == "macos") && !bundleDataFolderOption.empty()) { + fs::path xcconfig = projectDir / "Project.xcconfig"; + if (fs::exists(xcconfig)) { + try { + static const std::regex lineRe(R"(^[ \t]*(?://)?[ \t]*OF_BUNDLE_DATA_FOLDER[ \t]*=.*$)"); + string replacement = bundleDataFolderOption == "1" ? "OF_BUNDLE_DATA_FOLDER = 1" : "//OF_BUNDLE_DATA_FOLDER = 1"; + std::vector lines = fileToStrings(xcconfig); + bool wrote = false; + bool changed = false; + string updated; + for (auto & l : lines) { + if (std::regex_match(l, lineRe)) { + if (!wrote) { + if (l != replacement) changed = true; + updated += replacement + "\n"; + wrote = true; + } else { + changed = true; // collapsing a duplicate + } + } else { + updated += l + "\n"; + } + } + if (changed) writeSettingsFile(xcconfig, updated); + } catch (const std::exception & e) { + ofLogWarning(LOG_NAME) << "Cannot toggle OF_BUNDLE_DATA_FOLDER in Project.xcconfig: " << e.what(); + } + } + } } // for (auto & c : commands) cout << c << endl; diff --git a/frontend/app.js b/frontend/app.js index c3f087e7..84b67281 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -223,6 +223,8 @@ ipcRenderer.on('setGenerateMode', (event, arg) => { function clearProjectSettings() { for (const id of ['appVersion', 'appBuild', 'bundleId', 'systemFrameworks', 'systemLibs', 'customDefines']) $('#' + id).val(''); + $('#bundleData').prop('checked', false); + $('#bundleData').closest('.ui.checkbox').removeClass('checked'); $('#appVersionNote').text('').hide(); $('#rendererDropdown, #glDropdown, #webglDropdown, #glesDropdown').dropdown('set exactly', 'default'); loadedProjectSettings = null; @@ -238,9 +240,14 @@ ipcRenderer.on('setProjectSettings', (event, values) => { for (const [id, value] of Object.entries(fields)) { if (!keepEdits || $('#' + id).val().trim() === loadedProjectSettings[id]) $('#' + id).val(value); } + const bundleDataChecked = !!values.bundleDataFolder; + if (!keepEdits || $('#bundleData').is(':checked') === !!loadedProjectSettings?.bundleDataFolder) { + $('#bundleData').prop('checked', bundleDataChecked); + $('#bundleData').closest('.ui.checkbox').toggleClass('checked', bundleDataChecked); + } $('#appVersionNote').text('').hide(); if (!keepEdits) $('#rendererDropdown, #glDropdown, #webglDropdown, #glesDropdown').dropdown('set exactly', 'default'); - loadedProjectSettings = { projectName: values.projectName, projectPath: values.projectPath, ...fields }; + loadedProjectSettings = { projectName: values.projectName, projectPath: values.projectPath, ...fields, bundleDataFolder: bundleDataChecked }; }); function projectFieldValue(id) { @@ -972,6 +979,9 @@ function setup() { $("#detachConsole").checkbox(); $("#detachConsole").prop('checked', !!defaultSettings['detachConsole']); updateConsoleDockVisibility(); + + // bundle data folder (osx / macos): Semantic UI init; state is set by setProjectSettings + $("#bundleData").checkbox(); $("#detachConsole").on('change', function(){ const enabled = $(this).is(':checked'); defaultSettings['detachConsole'] = enabled; @@ -1318,6 +1328,9 @@ function generate() { appVersion: projectFieldValue('appVersion') || '', appBuild: projectFieldValue('appBuild') || '', appBundleId: projectFieldValue('bundleId') || '', + // osx / macos checkbox for OF_BUNDLE_DATA_FOLDER in Project.xcconfig; hidden = keep + // the project's current xcconfig (don't send the flag at all) + bundleDataFolder: $('#bundleDataField').css('display') !== 'none' ? ($('#bundleData').is(':checked') ? '1' : '0') : '', // only for Apple targets; hidden = keep the project's config.make values systemFrameworks: $('#systemFrameworksField').css('display') !== 'none' && projectFieldValue('systemFrameworks') !== null ? $('#systemFrameworks').val().split(/[\s,]+/).filter(Boolean) : null, systemLibs: $('#systemFrameworksField').css('display') !== 'none' && projectFieldValue('systemLibs') !== null ? $('#systemLibs').val().split(/[\s,]+/).filter(Boolean) : null @@ -1516,6 +1529,8 @@ function updateRendererFieldVisibility() { // advanced only; hidden fields keep the project's values, so updating still keeps them $('#appVersionField').css('display', defaultSettings.advancedMode ? 'flex' : 'none'); $('#bundleIdField').toggle(!!defaultSettings.advancedMode); + // bundle data folder checkbox is osx / macos only (the APPSTORE block it toggles only exists in those templates) + $('#bundleDataField').toggle(!!defaultSettings.advancedMode && selectedPlatforms.some((p) => ['osx', 'macos'].includes(p))); $('#appVersionNote').toggle(!!defaultSettings.advancedMode && $('#appVersionNote').text().length > 0); $('#systemFrameworksField').css('display', defaultSettings.advancedMode && selectedPlatforms.some((p) => ['osx', 'ios', 'macos', 'tvos'].includes(p)) ? 'flex' : 'none'); diff --git a/frontend/index.html b/frontend/index.html index 8a0cc118..bd3b5f27 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -339,6 +339,16 @@ +