diff --git a/NEWS b/NEWS index 2f84ee83..61a5715d 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ * Fixed a bug with the `activate' CLI command. Thanks to Joffrey Jaffeux for the patch. * Added a feature to support Subscripting (Objective-C Literals). + * Made the REPL for a OS X application work in development mode when it is + sandboxed. = RubyMotion 2.22 = diff --git a/bin/sim.m b/bin/sim.m index 3f9b12ce..9498ced2 100644 --- a/bin/sim.m +++ b/bin/sim.m @@ -1334,16 +1334,20 @@ main(int argc, char **argv) environment] mutableCopy]; if (debug_mode != DEBUG_NOTHING) { // Prepare repl socket path. - NSString *tmpdir = NSTemporaryDirectory(); - assert(tmpdir != nil); - char path[PATH_MAX]; - snprintf(path, sizeof path, "%s/rubymotion-repl-XXXXXX", - [tmpdir fileSystemRepresentation]); - assert(mktemp(path) != NULL); - replSocketPath = [[[NSFileManager defaultManager] - stringWithFileSystemRepresentation:path length:strlen(path)] - retain]; - [appEnvironment setObject:replSocketPath forKey:@"REPL_SOCKET_PATH"]; + replSocketPath = [appEnvironment[@"REPL_SOCKET_PATH"] retain]; + if (replSocketPath == nil) { + NSString *tmpdir = NSTemporaryDirectory(); + assert(tmpdir != nil); + char path[PATH_MAX]; + snprintf(path, sizeof path, "%s/rubymotion-repl-XXXXXX", + [tmpdir fileSystemRepresentation]); + assert(mktemp(path) != NULL); + replSocketPath = [[[NSFileManager defaultManager] + stringWithFileSystemRepresentation:path length:strlen(path)] + retain]; + [appEnvironment setObject:replSocketPath + forKey:@"REPL_SOCKET_PATH"]; + } // Make sure the unix socket path does not exist. [[NSFileManager defaultManager] removeItemAtPath:replSocketPath diff --git a/lib/motion/project/template/osx.rb b/lib/motion/project/template/osx.rb index 77def4fe..0f150a76 100644 --- a/lib/motion/project/template/osx.rb +++ b/lib/motion/project/template/osx.rb @@ -58,7 +58,10 @@ task :run do end exec = App.config.app_bundle_executable('MacOSX') env = '' - env << 'SIM_SPEC_MODE=1' if App.config.spec_mode + env << 'SIM_SPEC_MODE=1 ' if App.config.spec_mode + if App.config.needs_repl_sandbox_entitlements? + env << "REPL_SOCKET_PATH='#{App.config.app_sandbox_repl_socket_path}' " + end sim = File.join(App.config.bindir, 'osx/sim') debug = (ENV['debug'] ? 1 : (App.config.spec_mode ? '0' : '2')) target = App.config.sdk_version diff --git a/lib/motion/project/template/osx/config.rb b/lib/motion/project/template/osx/config.rb index 9c63acbc..ef8fb024 100644 --- a/lib/motion/project/template/osx/config.rb +++ b/lib/motion/project/template/osx/config.rb @@ -100,8 +100,16 @@ module Motion; module Project; super('Mac') end + def needs_repl_sandbox_entitlements? + development? && codesign_for_development && entitlements['com.apple.security.app-sandbox'] + end + def entitlements_data - dict = entitlements + dict = entitlements.dup + if needs_repl_sandbox_entitlements? + files = (dict['com.apple.security.temporary-exception.files.absolute-path.read-only'] ||= []) + files << datadir('librubymotion-repl.dylib') + end Motion::PropertyList.to_s(dict) end @@ -135,6 +143,10 @@ module Motion; module Project; File.join(app_bundle(platform), 'Resources') end + def app_sandbox_repl_socket_path + File.expand_path(File.join('~/Library/Containers', identifier, "Data/rubymotion-repl-#{Time.now.to_i}")) + end + def info_plist_data(platform) Motion::PropertyList.to_s({ 'NSHumanReadableCopyright' => copyright,