From 5c49152d9decb82ce33267b1f0d938a8c1f0b18a Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Fri, 17 Aug 2018 10:46:37 +0100 Subject: [PATCH] CLion: Launch the .app bundle from the Projucer on OSX to pass environment variables --- .../ProjectSaving/jucer_ProjectExport_CLion.h | 22 ++++++++++--------- modules/juce_core/native/juce_mac_Files.mm | 16 +++++++------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h index 9dd20e1b5a..9dfc51ac36 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_CLion.h @@ -117,14 +117,14 @@ public: #endif if (getProject().getExporters().getChildWithName (exporterName).isValid()) - return getCLionExecutable().existsAsFile(); + return getCLionExecutableOrApp().exists(); return false; } bool launchProject() override { - return getCLionExecutable().startAsProcess (getTargetFolder().getFullPathName().quoted()); + return getCLionExecutableOrApp().startAsProcess (getTargetFolder().getFullPathName().quoted()); } String getDescription() override @@ -224,19 +224,21 @@ public: private: //============================================================================== - static File getCLionExecutable() + static File getCLionExecutableOrApp() { - File clionExe (getAppSettings() - .getStoredPath (Ids::clionExePath) - .toString() - .replace ("${user.home}", File::getSpecialLocation (File::userHomeDirectory).getFullPathName())); + File clionExeOrApp (getAppSettings() + .getStoredPath (Ids::clionExePath) + .toString() + .replace ("${user.home}", File::getSpecialLocation (File::userHomeDirectory).getFullPathName())); #if JUCE_MAC - if (clionExe.getFileName().endsWith (".app")) - clionExe = clionExe.getChildFile ("Contents/MacOS/clion"); + if (clionExeOrApp.getFullPathName().endsWith ("/Contents/MacOS/clion")) + clionExeOrApp = clionExeOrApp.getParentDirectory() + .getParentDirectory() + .getParentDirectory(); #endif - return clionExe; + return clionExeOrApp; } //============================================================================== diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm index c055621e03..e337b56e95 100644 --- a/modules/juce_core/native/juce_mac_Files.mm +++ b/modules/juce_core/native/juce_mac_Files.mm @@ -105,12 +105,12 @@ namespace MacFileHelpers #else static bool launchExecutable (const String& pathAndArguments) { - const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 }; - const int cpid = fork(); if (cpid == 0) { + const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 }; + // Child process if (execve (argv[0], (char**) argv, 0) < 0) exit (0); @@ -412,10 +412,8 @@ bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& JUCE_AUTORELEASEPOOL { NSString* fileNameAsNS (juceStringToNS (fileName)); - NSURL* filenameAsURL ([NSURL URLWithString: fileNameAsNS]); - - if (filenameAsURL == nil) - filenameAsURL = [NSURL fileURLWithPath: fileNameAsNS]; + NSURL* filenameAsURL = File (fileName).exists() ? [NSURL fileURLWithPath: fileNameAsNS] + : [NSURL URLWithString: fileNameAsNS]; #if JUCE_IOS ignoreUnused (parameters); @@ -442,11 +440,13 @@ bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& StringArray params; params.addTokens (parameters, true); - NSMutableArray* paramArray = [[[NSMutableArray alloc] init] autorelease]; + NSMutableDictionary* dict = [[NSMutableDictionary new] autorelease]; + + NSMutableArray* paramArray = [[NSMutableArray new] autorelease]; + for (int i = 0; i < params.size(); ++i) [paramArray addObject: juceStringToNS (params[i])]; - NSMutableDictionary* dict = [[[NSMutableDictionary alloc] init] autorelease]; [dict setObject: paramArray forKey: nsStringLiteral ("NSWorkspaceLaunchConfigurationArguments")];