Skip to content

Instantly share code, notes, and snippets.

@martijnthe
Created February 23, 2012 16:02
Show Gist options
  • Save martijnthe/1893437 to your computer and use it in GitHub Desktop.
Save martijnthe/1893437 to your computer and use it in GitHub Desktop.
Workaround-plugin for Xcode 4.4 to fix a crash when running unit tests
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.martijnthe.${PRODUCT_NAME:rfc1034identifier}.xcodeplugin</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>4.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CSResourcesFileMapped</key>
<string>yes</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2012 martijnthe.nl. All rights reserved.</string>
<key>CFBundleGetInfoString</key>
<string>v0.1 Copyright © 2012 martijnthe.nl. All rights reserved.</string>
<key>LoadAtLaunch</key>
<string>YES</string>
<key>XCGCReady</key>
<string>YES</string>
<key>XCPluginHasUI</key>
<string>NO</string>
<key>NSPrincipalClass</key>
<string>XcodeFixups</string>
<key>XC4Compatible</key>
<true/>
</dict>
</plist>
//
// Xcode4_4Fixups.m
// Xcode4_4Fixups
//
// Created by Martijn Thé on 2/23/12.
// Copyright (c) 2012 martijnthe.nl All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <objc/objc-runtime.h>
#import "IDETest.h"
NSComparisonResult localizedStandardCompare(IDETest* _self, SEL cmd, IDETest* other);
NSComparisonResult localizedStandardCompare(IDETest* _self, SEL cmd, IDETest* other) {
return [[_self identifier] localizedStandardCompare:[other identifier]];
}
@interface XcodeFixups : NSObject @end
@implementation XcodeFixups
+ (void)initialize {
NSLog(@"Xcode4_4Fixups_init...");
NSLog(@"Fixing -[IDETest localizedStandardCompare:] crashes...");
Class IDETestClass = NSClassFromString(@"IDETest");
if (IDETestClass) {
BOOL didAdd = class_addMethod(IDETestClass, @selector(localizedStandardCompare:), (IMP)localizedStandardCompare, "i@:@");
if (didAdd) {
NSLog(@"Added -[IDETest localizedStandardCompare:] method implementation.");
} else {
NSLog(@"Failed.");
}
} else {
NSLog(@"Class IDETest not (yet) loaded.");
}
}
@end
@martijnthe
Copy link
Author

Put into a Bundle project with "XcodeFixups.xcplugin" as product and put built plugin into ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/

@joefiorini
Copy link

Thanks for posting this! Where do I get IDETest.h? I'm trying to build and getting an error that it can't find that file.

@joefiorini
Copy link

I was able to get this working but had to change a few things. I'll post my xcodeproj to GitHub when I have a chance later tonight.

@martijnthe
Copy link
Author

You can get IDETest.h by doing a class-dump on Xcode's internal framework (I think it was IDEKit or IDEFoundation). Since it's a developer preview and private frameworks I'm a bit hesitant to post them here out in the open.

I've created a Xcode plugin in the mean time to fix this issue. I'll put it up in a Github project.

@martijnthe
Copy link
Author

Hi Joe, I've just created a repo for the fixup plugin:
https://github.com/martijnthe/Xcode4_4Fixups

It does not need the IDETest.h file any more.

@martijnthe
Copy link
Author

Huh, I see you already had done the same... :-) oh well.

@joefiorini
Copy link

Thanks Martijn. Yeah, guess it can't hurt to have the same plugin out there twice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment