Skip to content
Permalink
Browse files

Added setPortOptions method to MPMacPorts. Builds ok. Yet to document…

… funcionality and test method

git-svn-id: https://svn.macports.org/repository/macports/contrib/MacPorts_Framework@40518 d073be05-634f-4543-b044-5fe20cf6d1d6
  • Loading branch information
George Armah
George Armah committed Oct 5, 2008
1 parent fc57621 commit 7e71c042d9f853747ce8247deb1a540092b31dfe
@@ -97,25 +97,29 @@
*/
@interface MPInterpreter : NSObject {

Tcl_Interp* _interpreter;
NSString * helperToolInterpCommand;
NSString * helperToolCommandResult;
Tcl_Interp* _interpreter;
NSString * helperToolInterpCommand;
NSString * helperToolCommandResult;
NSArray * defaultPortOptions;

}


//Internal methods
-(BOOL) setOptionsForNewTclPort:(NSArray *)options;

/*!
@brief Return singleton shared MPInterpreter instance
*/
+ (MPInterpreter *)sharedInterpreter;




/*!
@brief Return singleton shared MPInterpreter instance for specified macports tcl package path
@param path An NSString specifying the absolute path for the macports tcl package
*/
+ (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path;
+ (MPInterpreter *)sharedInterpreterWithPkgPath:(NSString *)path portOptions:(NSArray *)options;



@@ -189,7 +193,6 @@


// METHODS FOR INTERNAL USE ONLY
- (id) initWithPkgPath:(NSString *)path;
- (Tcl_Interp *) sharedInternalTclInterpreter;
- (int) execute:(NSString *)pathToExecutable withArgs:(NSArray*)args;
- (void)setAuthorizationRef:(AuthorizationRef)authRef;
@@ -164,16 +164,12 @@ int Notifications_Command(ClientData clientData, Tcl_Interp *interpreter, int ob
//tool
static NSString * tclInterpreterPkgPath = nil;


- (id) init {
return [self initWithPkgPath:MP_DEFAULT_PKG_PATH];
}

//Internal method for initializing Tcl interpreter
#pragma mark -
#pragma mark Internal Methods
//Internal method for initializing actual C Tcl interpreter
//Should I be using a double pointer like is done for NSError ?
-(BOOL) initTclInterpreter:(Tcl_Interp * *)interp withPath:(NSString *)path {
BOOL result = NO;

*interp = Tcl_CreateInterp();

if(*interp == NULL) {
@@ -187,6 +183,9 @@ -(BOOL) initTclInterpreter:(Tcl_Interp * *)interp withPath:(NSString *)path {
return result;
}

if (path == nil)
path = MP_DEFAULT_PKG_PATH;


NSString * mport_fastload = [[@"source [file join \"" stringByAppendingString:path]
stringByAppendingString:@"\" macports1.0 macports_fastload.tcl]"];
@@ -205,8 +204,8 @@ -(BOOL) initTclInterpreter:(Tcl_Interp * *)interp withPath:(NSString *)path {
}

if( Tcl_EvalFile(*interp, [[[NSBundle bundleWithIdentifier:@"org.macports.frameworks.macports"]
pathForResource:@"init"
ofType:@"tcl"] UTF8String]) != TCL_OK) {
pathForResource:@"init"
ofType:@"tcl"] UTF8String]) != TCL_OK) {
NSLog(@"Error in Tcl_EvalFile init.tcl: %s", Tcl_GetStringResult(*interp));
Tcl_DeleteInterp(*interp);
return result;
@@ -227,8 +226,10 @@ -(BOOL) setOptions:(NSArray *)options forTclInterpreter:(Tcl_Interp * *)interp {
id opt;

while ((opt = [optionsEnum nextObject])) {
if (Tcl_Eval(*interp , [[NSString stringWithFormat:@"set ui_options(%@) \"yes\"", opt] UTF8String]) != TCL_OK)
if (Tcl_Eval(*interp , [[NSString stringWithFormat:@"set ui_options(%@) \"yes\"", opt] UTF8String]) != TCL_OK) {
NSLog(@"Error in Tcl_Eval for set ui_options: %s", Tcl_GetStringResult(*interp));
return result;
}
}
result = YES;
return result;
@@ -238,11 +239,37 @@ -(BOOL) setOptions:(NSArray *)options forTclInterpreter:(Tcl_Interp * *)interp {
return result;
}

- (id) initWithPkgPath:(NSString *)path {
//Wrapper method for above. Used when
-(BOOL) setOptionsForNewTclPort:(NSArray *)options {
BOOL result = NO;

//First delete our internal Tcl interpreter
Tcl_DeleteInterp(_interpreter);

if (tclInterpreterPkgPath == nil)
result = [self initTclInterpreter:&_interpreter withPath:MP_DEFAULT_PKG_PATH];
else
result = [self initTclInterpreter:&_interpreter withPath:tclInterpreterPkgPath];

BOOL tempResult = [self setOptions:options forTclInterpreter:&_interpreter];




return (result && tempResult) ;
}

- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
if (self = [super init]) {

[self initTclInterpreter:&_interpreter withPath:path];

//set port options maybe I should do this elsewhere?
defaultPortOptions = [NSArray arrayWithObjects: MPDEBUGOPTION, nil];
if (options == nil)
options = defaultPortOptions;
[self setOptions:options forTclInterpreter:&_interpreter];

//Initialize helperToolInterpCommand
helperToolInterpCommand = @"";
helperToolCommandResult = @"";
@@ -255,15 +282,30 @@ - (id) initWithPkgPath:(NSString *)path {
}


+ (MPInterpreter*)sharedInterpreter {
return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
#pragma mark API methods
- (id) init {
return [self initWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:nil];
}

+ (MPInterpreter*)sharedInterpreterWithPkgPath:(NSString *)path {
@synchronized(self) {
if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
[[self alloc] initWithPkgPath:path]; // assignment not done here
[[self alloc] initWithPkgPath:path portOptions:nil]; // assignment not done here
}
}
return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"];
}

+ (MPInterpreter*)sharedInterpreter{
return [self sharedInterpreterWithPkgPath:MP_DEFAULT_PKG_PATH];
}



+ (MPInterpreter*)sharedInterpreterWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
@synchronized(self) {
if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
[[self alloc] initWithPkgPath:path portOptions:options]; // assignment not done here
}
}
return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"];
@@ -81,9 +81,13 @@
*/
+ (MPMacPorts *)sharedInstance;

+ (MPMacPorts *)sharedInstanceWithPortOptions:(NSArray *)options;

//Names of messages below are subject to change
+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path;
- (id) initWithPkgPath:(NSString *)path;
+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path portOptions:(NSArray *)options;
- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options;
- (BOOL) setPortOptions:(NSArray *)options;

/*!
@brief Synchronizes the ports tree without checking for upgrades to the MacPorts base.
@@ -41,13 +41,13 @@ @implementation MPMacPorts


- (id) init {
return [self initWithPkgPath:MP_DEFAULT_PKG_PATH];
return [self initWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:nil];
}


- (id) initWithPkgPath:(NSString *)path {
- (id) initWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
if (self = [super init]) {
interpreter = [MPInterpreter sharedInterpreterWithPkgPath:path];
interpreter = [MPInterpreter sharedInterpreterWithPkgPath:path portOptions:nil];
//[self registerForLocalNotifications];
}
return self;
@@ -57,16 +57,31 @@ + (MPMacPorts *)sharedInstance {
return [self sharedInstanceWithPkgPath:MP_DEFAULT_PKG_PATH];
}

+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path {
+ (MPMacPorts *)sharedInstanceWithPortOptions:(NSArray *)options {
return [self sharedInstanceWithPkgPath:MP_DEFAULT_PKG_PATH portOptions:options];
}

+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path portOptions:(NSArray *)options {
@synchronized(self) {
if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"] == nil) {
[[self alloc] initWithPkgPath:path]; // assignment not done here
[[self alloc] initWithPkgPath:path portOptions:options ]; // assignment not done here
}
}
return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"];
}

+ (MPMacPorts *)sharedInstanceWithPkgPath:(NSString *)path {
@synchronized(self) {
if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"] == nil) {
[[self alloc] initWithPkgPath:path portOptions:nil ]; // assignment not done here
}
}
return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPMacPorts"];
}

- (BOOL) setPortOptions:(NSArray *)options {
return [interpreter setOptionsForNewTclPort:options];
}


+ (id)allocWithZone:(NSZone*)zone {
@@ -88,13 +88,6 @@
remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
remoteInfo = MacPorts;
};
6E31A2890E6F7910002804D0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
proxyType = 1;
remoteGlobalIDString = DFE353650CFB8F0C003BACFC;
remoteInfo = Docs;
};
6EC2608B0E4270110013BC48 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
@@ -521,7 +514,6 @@
dependencies = (
6ED12A530E3E55A50026773D /* PBXTargetDependency */,
6EC2608C0E4270110013BC48 /* PBXTargetDependency */,
6E31A28A0E6F7910002804D0 /* PBXTargetDependency */,
);
name = MacPorts;
productInstallPath = "$(HOME)/Library/Frameworks";
@@ -694,11 +686,6 @@
target = 8DC2EF4F0486A6940098B216 /* MacPorts */;
targetProxy = 6E1AE8460E232D0700F6D7BC /* PBXContainerItemProxy */;
};
6E31A28A0E6F7910002804D0 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = DFE353650CFB8F0C003BACFC /* Docs */;
targetProxy = 6E31A2890E6F7910002804D0 /* PBXContainerItemProxy */;
};
6EC2608C0E4270110013BC48 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 6EC260860E426FF10013BC48 /* MPHelperInstallTool */;

0 comments on commit 7e71c04

Please sign in to comment.
You can’t perform that action at this time.