Implement 10.13 methods for NSTask

This commit is contained in:
Gregory John Casamento 2022-06-08 14:08:55 -04:00
parent 6c7386f5e1
commit bcc87bccda
2 changed files with 34 additions and 10 deletions

View file

@ -36,7 +36,7 @@
extern "C" { extern "C" {
#endif #endif
DEFINE_BLOCK_TYPE_NO_ARGS(GSTaskTerminatorHandler, void); DEFINE_BLOCK_TYPE_NO_ARGS(GSTaskTerminationHandler, void);
@class NSThread; @class NSThread;
@ -68,6 +68,7 @@ GS_EXPORT_CLASS
BOOL _hasNotified; BOOL _hasNotified;
NSThread *_launchingThread; NSThread *_launchingThread;
NSTaskTerminationReason _terminationReason; NSTaskTerminationReason _terminationReason;
GSTaskTerminationHandler _handler;
#endif #endif
#if GS_NONFRAGILE #if GS_NONFRAGILE
#else #else
@ -138,9 +139,9 @@ GS_EXPORT_CLASS
+ (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url + (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url
arguments: (NSArray *)arguments arguments: (NSArray *)arguments
error: (NSError **)error error: (NSError **)error
terminationHandler: (GSTaskTerminatorHandler)terminationHandler; terminationHandler: (GSTaskTerminationHandler)terminationHandler;
- (BOOL) launchAndReturnError:(out NSError **)error; - (BOOL) launchAndReturnError: (NSError **)error;
- (NSURL *) executableURL; - (NSURL *) executableURL;

View file

@ -38,12 +38,13 @@
#import "Foundation/NSMapTable.h" #import "Foundation/NSMapTable.h"
#import "Foundation/NSProcessInfo.h" #import "Foundation/NSProcessInfo.h"
#import "Foundation/NSRunLoop.h" #import "Foundation/NSRunLoop.h"
#import "Foundation/NSLock.h"
#import "Foundation/NSNotification.h" #import "Foundation/NSNotification.h"
#import "Foundation/NSNotificationQueue.h" #import "Foundation/NSNotificationQueue.h"
#import "Foundation/NSTask.h" #import "Foundation/NSTask.h"
#import "Foundation/NSThread.h" #import "Foundation/NSThread.h"
#import "Foundation/NSTimer.h" #import "Foundation/NSTimer.h"
#import "Foundation/NSLock.h" #import "Foundation/NSURL.h"
#import "GNUstepBase/NSString+GNUstepBase.h" #import "GNUstepBase/NSString+GNUstepBase.h"
#import "GNUstepBase/NSTask+GNUstepBase.h" #import "GNUstepBase/NSTask+GNUstepBase.h"
#import "GSPrivate.h" #import "GSPrivate.h"
@ -877,27 +878,44 @@ pty_slave(const char* name)
LEAVE_POOL LEAVE_POOL
} }
// macOS 10.13 methods...
+ (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url + (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url
arguments: (NSArray *)arguments arguments: (NSArray *)arguments
error: (NSError **)error error: (NSError **)error
terminationHandler: (GSTaskTerminatorHandler)terminationHandler terminationHandler: (GSTaskTerminationHandler)terminationHandler
{ {
return nil; NSTask *task = [self launchedTaskWithLaunchPath: [url path]
arguments: arguments];
task->_handler = terminationHandler;
*error = nil;
return task;
} }
- (BOOL) launchAndReturnError:(out NSError **)error - (BOOL) launchAndReturnError: (NSError **)error
{ {
return NO; return NO;
} }
- (NSURL *) executableURL - (NSURL *) executableURL
{ {
return nil; return [NSURL URLWithString: [self launchPath]];;
}
- (void) setExecutableURL: (NSURL *)url
{
[self setLaunchPath: [url path]];
} }
- (NSURL *) currentDirectoryURL - (NSURL *) currentDirectoryURL
{ {
return nil; return [NSURL URLWithString: [self currentDirectoryPath]];
}
- (void) setCurrentDirectoryURL: (NSURL *)url
{
[self setCurrentDirectoryPath: [url path]];
} }
@end @end
@ -941,6 +959,11 @@ pty_slave(const char* name)
postingStyle: NSPostASAP postingStyle: NSPostASAP
coalesceMask: NSNotificationNoCoalescing coalesceMask: NSNotificationNoCoalescing
forModes: nil]; forModes: nil];
if (_handler != nil)
{
CALL_BLOCK_NO_ARGS(_handler);
}
} }
- (void) _terminatedChild: (int)status reason: (NSTaskTerminationReason)reason - (void) _terminatedChild: (int)status reason: (NSTaskTerminationReason)reason
@ -1174,7 +1197,7 @@ quotedFromString(NSString *aString)
} }
[super launch]; [super launch];
)
lpath = [self _fullLaunchPath]; lpath = [self _fullLaunchPath];
wexecutable = (const unichar*)[lpath fileSystemRepresentation]; wexecutable = (const unichar*)[lpath fileSystemRepresentation];