Skip to content

Commit

Permalink
Merging tzikis work during gsoc-10
Browse files Browse the repository at this point in the history
  • Loading branch information
juanger committed Oct 7, 2010
1 parent 7eb289f commit 4bef2fd
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 422 deletions.
10 changes: 8 additions & 2 deletions MPHelperTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
//I'll save that here when retrieving info.
//fromt he request dictionary
int notificationsFileDescriptor;
static int hasInstalledSignalToSocket = 0;
BOOL hasSetFileDescriptor = NO;
NSString * ipcFilePath;

Expand Down Expand Up @@ -590,7 +591,7 @@ void initIPC (ConnectionRef iConn) {
}

// Organise to have SIGINT delivered to a runloop callback.
if (err == 0) {
if (err == 0 && hasInstalledSignalToSocket == 0) {
sigset_t justSIGINT;

(void) sigemptyset(&justSIGINT);
Expand All @@ -603,6 +604,8 @@ void initIPC (ConnectionRef iConn) {
SIGINTRunLoopCallback,
NULL
);

hasInstalledSignalToSocket = 1;
//asl_NSLog(logClient , logMsg, ASL_LEVEL_DEBUG, @"MPHelperTool: IgnoreSigPipe Successful");
[ASLLogger logString:@"MPHelperTool: IgnoreSigPipe Successful"];
}
Expand Down Expand Up @@ -657,7 +660,7 @@ -(BOOL) initializeConnection {
}

// Organise to have SIGINT delivered to a runloop callback.
if (err == 0) {
if (err == 0 && hasInstalledSignalToSocket == 0) {
sigset_t justSIGINT;

(void) sigemptyset(&justSIGINT);
Expand All @@ -670,6 +673,9 @@ -(BOOL) initializeConnection {
SIGINTRunLoopCallback,
NULL
);

hasInstalledSignalToSocket = 1;

[ASLLogger logString:@"MPHelperTool: IgnoreSigPipe Successful"];
}

Expand Down
10 changes: 10 additions & 0 deletions MPPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@
- (void)upgradeWithError:(NSError**)mpError;


/*!
@brief Computes the NSMutableArray object for key "defaults_variants" of the port
*/
- (void)checkDefaults;

/*!
@brief Computes the conflicts of the port
*/
- (void)checkConflicts;

/*!
@brief Executes the specified target for this MPPort
@param target NSString target to be executed for this MPPort
Expand Down
152 changes: 146 additions & 6 deletions MPPort.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ - (void) setPortWithTclListAsString:(NSString *)string {
// tokenize the properties
// create sets of the depends_* tokenized properties that contain only the dependency name, not the dependency type
// make the descriptions readable

if([string rangeOfString:@"default_variants"].location != NSNotFound)
{
NSLog(@"%@", string);
}

if ([self objectForKey:@"maintainers"] != nil) {
[self setObject:[self objectForKey:@"maintainers"] forKey:@"maintainersAsString"];
[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"maintainers"]] forKey:@"maintainers"];
Expand Down Expand Up @@ -117,6 +123,24 @@ - (void) setPortWithTclListAsString:(NSString *)string {
[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_run"]] forKey:@"depends_run"];
[self addDependencyAsPortName:@"depends_run"];
}
if ([self objectForKey:@"depends_fetch"] != nil) {
[self setObject:[self objectForKey:@"depends_fetch"] forKey:@"depends_fetchAsString"];
[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_fetch"]] forKey:@"depends_fetch"];
[self addDependencyAsPortName:@"depends_fetch"];
}
if ([self objectForKey:@"depends_extract"] != nil) {
[self setObject:[self objectForKey:@"depends_extract"] forKey:@"depends_extractAsString"];
[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"depends_extract"]] forKey:@"depends_extract"];
[self addDependencyAsPortName:@"depends_extract"];
}

//Code for fetching default variants
if ([self objectForKey:@"default_variants"] != nil) {
//NSLog(@"Default Variants str: %@", string);
[self setObject:[self objectForKey:@"default_variants"] forKey:@"default_variantsAsString"];
[self setObject:[interpreter arrayFromTclListAsString:[self objectForKey:@"default_variants"]] forKey:@"default_variants"];
}


@try {
if ([[self valueForKey:@"description"] characterAtIndex:0] == '{') {
Expand Down Expand Up @@ -247,25 +271,39 @@ -(void) exec:(NSString *)target
variants:(NSArray *)variants
error:(NSError **)execError{

NSString *opts;
NSString *vrnts;
NSMutableString *opts;
NSMutableString *vrnts;
MPInterpreter *interpreter;
opts = [NSString stringWithString:@" "];
vrnts = [NSString stringWithString:@" "];
opts = [NSMutableString stringWithCapacity:50];
[opts setString:@"{ "];
vrnts = [NSMutableString stringWithCapacity:50];
[vrnts setString:@"{ "];
interpreter = [MPInterpreter sharedInterpreter];


if (options != NULL) {
opts = [NSString stringWithString:[options componentsJoinedByString:@" "]];
[opts appendString: [NSString stringWithString:[options componentsJoinedByString:@" "]]];
}

[opts appendString: @" }"];

if (variants != NULL) {
vrnts = [NSString stringWithString:[variants componentsJoinedByString:@" "]];
[vrnts appendString: [NSString stringWithString:[variants componentsJoinedByString:@" "]]];
}

[vrnts appendString: @" }"];

//NSLog(@"Variants String: %@", vrnts);
//Send Global Notifications and update MPNotifications variable
[self sendGlobalExecNotification:target withStatus:@"Started"];
//NSString * tclCmd = [@"YES_" stringByAppendingString:target];
[[MPNotifications sharedListener] setPerformingTclCommand:target];

/*
NSLog(@"Interpreter string:\n%@",[NSString stringWithFormat:
@"set portHandle [mportopen %@ %@ %@]; mportexec $portHandle %@; mportclose $portHandle",
[self valueForKey:@"porturl"], opts, vrnts, target]);
*/
[interpreter evaluateStringWithPossiblePrivileges:
[NSString stringWithFormat:
@"set portHandle [mportopen %@ %@ %@]; mportexec $portHandle %@; mportclose $portHandle",
Expand Down Expand Up @@ -351,6 +389,108 @@ - (void)upgradeWithError:(NSError **)mError {
[self execPortProc:@"mportupgrade" withOptions:nil version:@"" error:mError];
}

//This function is called to initialize the array for the'default_variants' key for a port, which we can't do for all ports when loading
- (void)checkDefaults
{
//Check for default variants only if this is the first time we are checking
if ([self objectForKey:@"default_variants"] == nil)
{
//NSArray *defaultVariants = [port valueForKey:@"defaultVariants"];
NSMutableArray *defaultVariants= [NSMutableArray arrayWithCapacity:10];
char port_command[256];

//Build the port variants command
strcpy(port_command, "port variants ");
strcat(port_command, [[self objectForKey:@"name"] cStringUsingEncoding: NSASCIIStringEncoding]);
strcat(port_command, " | grep \"\\[+]\" | sed 's/.*\\]//; s/:.*//' >> mpfw_default_variants");

//Make the CLI call
system(port_command);
//Open the output file
FILE * file = fopen("mpfw_default_variants", "r");

//Read all default_variants
char buffer[256];
while(!feof(file))
{
char * temp = fgets(buffer,256,file);
if(temp == NULL) continue;
buffer[strlen(buffer)-1]='\0';
//Add the variant in the Array
[defaultVariants addObject:[NSString stringWithCString:buffer]];
}
//Close and delete
fclose(file);
unlink("mpfw_default_variants");

NSLog(@"Default variants count: %i", [defaultVariants count]);
//Code for fetching default variants
[self setObject:[NSString stringWithString:[defaultVariants componentsJoinedByString:@" "]] forKey:@"default_variantsAsString"];
[self setObject:defaultVariants forKey:@"default_variants"];
}

}

//This function is called to initiate the conflicts for a specific port, which we can't do for all ports when loading, much like
//the default_variants
- (void)checkConflicts;
{
//Check for only if this is the first time we are checking
if ([self objectForKey:@"conflicts"] == nil)
{

NSMutableArray *conflicts = [NSMutableArray arrayWithCapacity:20];

char *script= " | python -c \"import re,sys;lines=sys.stdin.readlines();print '\\n'.join('%s,%s' % (re.sub(r'[\\W]','',lines[i-1].split()[0].rstrip(':')),','.join(l.strip().split()[3:])) for i, l in enumerate(lines) if l.strip().startswith('* conflicts'))\" >> /tmp/mpfw_conflict";
char command[512];
strcpy(command,"port variants ");
strcat(command, [[self name] UTF8String]);
strcat(command, script);
//printf("\n%s\n", command);
system(command);

//Open the output file
FILE * file = fopen("/tmp/mpfw_conflict", "r");

//Read all conflicts
char buffer[256];
while(!feof(file))
{
char * temp = fgets(buffer,256,file);
if(temp == NULL) continue;
buffer[strlen(buffer)-1]='\0';
//Add the variant in the Array
//printf("buffer:\n%s\n",buffer);

char *token;
char *search = ",";

token = strtok(buffer, search);
//printf("token: %s\n",token);
if(token == NULL) break;

NSString *variant = [NSString stringWithCString:token];
NSMutableArray *conflictsWith=[NSMutableArray arrayWithCapacity:10];
NSLog(@"%@", variant);
while ((token = strtok(NULL, search)) != NULL)
{
NSLog(@"token: %@",[NSString stringWithCString:token]);
[conflictsWith addObject:[NSString stringWithCString:token]];
//NSLog(@"count %i",[[checkboxes[i] conflictsWith] count]);
}

NSDictionary *variantConflictsWith = [NSDictionary dictionaryWithObject:conflictsWith forKey:variant];
[conflicts addObject:variantConflictsWith];
//[defaultVariants addObject:[NSString stringWithCString:buffer]];
}
//Close and delete
fclose(file);
unlink("/tmp/mpfw_conflict");

[self setObject:conflicts forKey:@"conflicts"];
}
}

-(void)configureWithOptions:(NSArray *)options variants:(NSArray *)variants error:(NSError **)mError {
[self exec:@"configure" withOptions:options variants:variants error:mError];
}
Expand Down
1 change: 0 additions & 1 deletion MPPortProcess.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ int main(int argc, char const * argv[]) {
NSConnection *portProcessConnection;
portProcessConnection = [NSConnection defaultConnection];
NSString *PKGPath = [[NSString alloc] initWithCString:argv[1] encoding:NSUTF8StringEncoding];
// NSString *portProcessInitPath = [[NSString alloc] initWithCString:argv[2] encoding:NSUTF8StringEncoding];

MPPortProcess *portProcess = [[MPPortProcess alloc] initWithPKGPath:PKGPath];

Expand Down
7 changes: 7 additions & 0 deletions MacPorts.Framework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,14 @@
};
buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "MacPorts.Framework" */;
compatibilityVersion = "Xcode 2.4";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 0867D691FE84028FC02AAC07 /* MacPorts Foundation */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
Expand Down
Loading

0 comments on commit 4bef2fd

Please sign in to comment.