Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #87 from DyCI/feature/xcode-plugin-compilation-flags
Browse files Browse the repository at this point in the history
Allow Xcode to search correct compilation flags, before falling back to the dyci-recompile.py
  • Loading branch information
PaulTaykalo committed May 28, 2015
2 parents bed46e4 + 5adc89a commit 7b347b2
Show file tree
Hide file tree
Showing 39 changed files with 2,349 additions and 137 deletions.
98 changes: 52 additions & 46 deletions Install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# ============= Logging support ======================
_V=0
_SKIP_CLANG_PROXY=0

while getopts "v" OPTION
while getopts "vs" OPTION
do
case $OPTION in
v) _V=1
;;
s) _SKIP_CLANG_PROXY=1
;;
esac
done

Expand All @@ -34,52 +37,55 @@ CLANG_REAL_LOCATION=$CLANG_LOCATION-real
CLANG_REAL_LOCATION_PP="$CLANG_LOCATION-real++"

echo
echo -n "== Backing up clang : "

if [[ ! -f ${CLANG_BACKUP_LOCATION} ]]; then
# Checking, if it isn't our script laying in clang
echo grep -Fq "== CLANG_PROXY ==" "$CLANG_LOCATION"
if grep -Fq "== CLANG_PROXY ==" "$CLANG_LOCATION"
then
# code if found
# This is bad....
echo "Original clang compiler was already proxied via dyci and no backup can be found."
echo "This can be because of Xcode update without dyci uninstallation."
echo "In case, if you see this, clang is little broken now, and you need to update it manually."
echo "By running next command in your terminal : "
echo "echo ""${CLANG_LOCATION}"" ""${CLANG_BACKUP_LOCATION}"" | xargs -n 1 sudo cp /usr/bin/clang"
exit 1
if [[ $_SKIP_CLANG_PROXY -eq 0 ]]; then
echo -n "== Backing up clang : "
if [[ ! -f ${CLANG_BACKUP_LOCATION} ]]; then
# Checking, if it isn't our script laying in clang
echo grep -Fq "== CLANG_PROXY ==" "$CLANG_LOCATION"
if grep -Fq "== CLANG_PROXY ==" "$CLANG_LOCATION"
then
# code if found
# This is bad....
echo "Original clang compiler was already proxied via dyci and no backup can be found."
echo "This can be because of Xcode update without dyci uninstallation."
echo "In case, if you see this, clang is little broken now, and you need to update it manually."
echo "By running next command in your terminal : "
echo "echo ""${CLANG_LOCATION}"" ""${CLANG_BACKUP_LOCATION}"" | xargs -n 1 cp /usr/bin/clang"
exit 1
fi
# We should backup clang ONLY if it is an binary file only
log " cp ${CLANG_LOCATION} ${CLANG_BACKUP_LOCATION}"
cp "${CLANG_LOCATION}" "${CLANG_BACKUP_LOCATION}"
log "echo Backup is at : ${CLANG_BACKUP_LOCATION}"
echo "Done."
else
echo "Skipped."
echo " Seems dyci-clang has already been installed"
log "Backup is at : ${CLANG_BACKUP_LOCATION}"
fi
# We should backup clang ONLY if it is an binary file only
log "sudo cp ${CLANG_LOCATION} ${CLANG_BACKUP_LOCATION}"
sudo cp "${CLANG_LOCATION}" "${CLANG_BACKUP_LOCATION}"
log "echo Backup is at : ${CLANG_BACKUP_LOCATION}"
echo "Done."
else
echo "Skipped."
echo " Seems dyci-clang has already been installed"
log "Backup is at : ${CLANG_BACKUP_LOCATION}"
fi

echo -n "== Faking up clang : "
echo -n "== Faking up clang : "

log "sudo cp ${CLANG_BACKUP_LOCATION} ${CLANG_REAL_LOCATION}"
sudo cp "${CLANG_BACKUP_LOCATION}" "${CLANG_REAL_LOCATION}"
log "cp ${CLANG_BACKUP_LOCATION} ${CLANG_REAL_LOCATION}"
cp "${CLANG_BACKUP_LOCATION}" "${CLANG_REAL_LOCATION}"

log "sudo cp ${CLANG_BACKUP_LOCATION} ${CLANG_REAL_LOCATION_PP}"
sudo cp "${CLANG_BACKUP_LOCATION}" "${CLANG_REAL_LOCATION_PP}"
log " cp ${CLANG_BACKUP_LOCATION} ${CLANG_REAL_LOCATION_PP}"
cp "${CLANG_BACKUP_LOCATION}" "${CLANG_REAL_LOCATION_PP}"

#DYCI-CLANG RIGHTS
sudo chmod +x Scripts/dyci-clang.py
sudo chmod +x Scripts/dyci-recompile.py
#DYCI-CLANG RIGHTS
chmod +x Scripts/dyci-clang.py
chmod +x Scripts/dyci-recompile.py

log "sudo cp Scripts/dyci-clang.py ${CLANG_LOCATION}"
log "sudo cp Scripts/clangParams.py ${CLANG_USR_BIN}"
log "sudo cp Scripts/dyci-clang.py ${CLANG_LOCATION}"
log "sudo cp Scripts/clangParams.py ${CLANG_USR_BIN}"

sudo cp Scripts/dyci-clang.py "${CLANG_LOCATION}"
sudo cp Scripts/clangParams.py "${CLANG_USR_BIN}"

echo "Done."
fi

sudo cp Scripts/dyci-clang.py "${CLANG_LOCATION}"
sudo cp Scripts/clangParams.py "${CLANG_USR_BIN}"

echo "Done."

USER_HOME=$(eval echo ~${SUDO_USER})
log "USER_HOME = ${USER_HOME}"
Expand All @@ -91,13 +97,13 @@ echo -n "== Preparing dyci-recompile directories: "
log "if [[ ! -d ${DYCI_ROOT_DIR}/index ]]; then"
if [[ ! -d "${DYCI_ROOT_DIR}/index" ]]; then

sudo mkdir -p "${DYCI_ROOT_DIR}/index"
sudo mkdir -p "${DYCI_ROOT_DIR}/scripts"
mkdir -p "${DYCI_ROOT_DIR}/index"
mkdir -p "${DYCI_ROOT_DIR}/scripts"

# not sure about this really
sudo chmod 777 "${DYCI_ROOT_DIR}"
sudo chmod 777 "${DYCI_ROOT_DIR}/index"
sudo chmod 777 "${DYCI_ROOT_DIR}/scripts"
chmod 777 "${DYCI_ROOT_DIR}"
chmod 777 "${DYCI_ROOT_DIR}/index"
chmod 777 "${DYCI_ROOT_DIR}/scripts"
echo "Done."
else
echo "Skipped. (Already prepared)."
Expand All @@ -106,8 +112,8 @@ fi
#Copying scripts
echo -n "== Copying scripts : "

sudo cp Scripts/dyci-recompile.py "${DYCI_ROOT_DIR}/scripts/"
sudo cp Scripts/clangParams.py "${DYCI_ROOT_DIR}/scripts/"
cp Scripts/dyci-recompile.py "${DYCI_ROOT_DIR}/scripts/"
cp Scripts/clangParams.py "${DYCI_ROOT_DIR}/scripts/"

echo "Done."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
<string>A16FF353-8441-459E-A50C-B071F53F51B7</string>
<string>992275C1-432A-4CF7-B659-D84ED6D42D3F</string>
<string>9F75337B-21B4-4ADC-B558-F9CADF7073A7</string>
<string>E969541F-E6F9-4D25-8158-72DC3545A6C6</string>
</array>
<key>NSPrincipalClass</key>
<string>SFDYCIHelper</string>
<string>SFDYCIPlugin</string>
<key>XC4Compatible</key>
<true/>
<key>XCGCReady</key>
Expand Down
Binary file not shown.
22 changes: 22 additions & 0 deletions Support/Xcode/Source/Classes/Plugin/SFDYCIPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// SFDYCIPlugin.h
// SFDYCIPlugin
//
// Created by Paul Taykalo on 09/07/12.
//
//

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@class SFDYCIViewsHelper;
@class SFDYCIRecompileController;
@class SFDYCIXCodeHelper;


/*
Dyci Plugin is th main class, where the magic happens
*/
@interface SFDYCIPlugin : NSObject

@end
173 changes: 173 additions & 0 deletions Support/Xcode/Source/Classes/Plugin/SFDYCIPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#import <sys/cdefs.h>//
// SFDYCIPlugin.m
// SFDYCIPlugin
//
// Created by Paul Taykalo on 09/07/12.
//
//

#import "SFDYCIPlugin.h"
#import "SFDYCIXCodeHelper.h"
#import "SFDYCIClangProxyRecompiler.h"
#import "SFDYCIXcodeObjectiveCRecompiler.h"
#import "SFDYCIViewsHelper.h"
#import "SFDYCICompositeRecompiler.h"
#import "DYCI_CCPXCodeConsole.h"


@interface SFDYCIPlugin ()
@property(nonatomic, strong) id <SFDYCIRecompilerProtocol> recompiler;
@property(nonatomic, strong) SFDYCIViewsHelper *viewHelper;
@property(nonatomic, strong) SFDYCIXCodeHelper *xcodeStructureManager;
@end


@implementation SFDYCIPlugin

#pragma mark - Plugin Initialization

+ (void)pluginDidLoad:(NSBundle *)plugin {
static id sharedPlugin = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedPlugin = [[self alloc] init];
});
}


- (id)init {
if (self = [super init]) {
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

// Waiting for application start
[notificationCenter addObserver:self
selector:@selector(applicationDidFinishLaunching:)
name:NSApplicationDidFinishLaunchingNotification
object:nil];
}
return self;
}


- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSLog(@"App finished launching");

// Selecting Xcode Recompiler first
// We'll use Xcode recompiler, and if that one fails, we'll fallback to dyci-recompile.py
self.recompiler = [[SFDYCICompositeRecompiler alloc]
initWithCompilers:@[[SFDYCIXcodeObjectiveCRecompiler new], [SFDYCIClangProxyRecompiler new]]];

self.viewHelper = [SFDYCIViewsHelper new];

self.xcodeStructureManager = [SFDYCIXCodeHelper instance];

[self setupMenu];

}

#pragma mark - Preferences

- (void)setupMenu {
NSMenuItem *runMenuItem = [[NSApp mainMenu] itemWithTitle:@"Product"];
if (runMenuItem) {

NSMenu *subMenu = [runMenuItem submenu];

// Adding separator
[subMenu addItem:[NSMenuItem separatorItem]];

// Adding inject item
NSMenuItem *recompileAndInjectMenuItem = [[NSMenuItem alloc] initWithTitle:@"Recompile and inject" action:@selector(recompileAndInject:) keyEquivalent:@"x"];
[recompileAndInjectMenuItem setKeyEquivalentModifierMask:NSControlKeyMask];
[recompileAndInjectMenuItem setTarget:self];

[subMenu addItem:recompileAndInjectMenuItem];

NSMenuItem *verboseRecompilationItem = [[NSMenuItem alloc] initWithTitle:@"Use verbose recompilation" action:@selector(useVerboseRecompilationAction:) keyEquivalent:@""];
[verboseRecompilationItem setTarget:self];
[subMenu addItem:verboseRecompilationItem];


}
}

- (void)useVerboseRecompilationAction:(NSMenuItem *)useVerboseRecompilationItem {
DYCI_CCPXCodeConsole * console = [DYCI_CCPXCodeConsole consoleForKeyWindow];
if (useVerboseRecompilationItem.state == NSOffState) {
useVerboseRecompilationItem.state = NSOnState;
[console log:@"DYCI verbose recompilation turned ON"];
console.shouldShowDebugInfo = YES;
} else {
useVerboseRecompilationItem.state = NSOffState;
console.shouldShowDebugInfo = NO;
[console log:@"DYCI verbose recompilation turned OFF"];
}
}


- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
// TODO : We need correct checks, when we can use Inject, and where we cannot
// Validate when we need to be called
// if ([menuItem action] == @selector(recompileAndInject:)) {
// NSResponder * firstResponder = [[NSApp keyWindow] firstResponder];
//
// NSLog(@"Validation check");
// while (firstResponder) {
// firstResponder = [firstResponder nextResponder];
// NSLog(@"firstResponder = %@", firstResponder);
// }
// return ([firstResponder isKindOfClass:NSClassFromString(@"DVTSourceTextView")] && [firstResponder isKindOfClass:[NSTextView class]]);
// }
return YES;
}


- (void)recompileAndInject:(id)sender {
NSDocument<CDRSXcode_IDEEditorDocument> *currentDocument = (NSDocument<CDRSXcode_IDEEditorDocument> *)[self.xcodeStructureManager currentDocument];
if ([currentDocument isDocumentEdited]) {
[currentDocument saveDocumentWithDelegate:self didSaveSelector:@selector(document:didSave:contextInfo:) contextInfo:nil];
} else {
[self recompileAndInjectAfterSave:nil];
}

}

- (void)document:(NSDocument *)document didSave:(BOOL)didSaveSuccessfully contextInfo:(void *)contextInfo {
[self recompileAndInjectAfterSave:nil];
}


- (void)recompileAndInjectAfterSave:(id)sender {
DYCI_CCPXCodeConsole * console = [DYCI_CCPXCodeConsole consoleForKeyWindow];
[console log:@"Starting Injection"];
__weak SFDYCIPlugin *weakSelf = self;


NSURL *openedFileURL = self.xcodeStructureManager.activeDocumentFileURL;

if (openedFileURL) {

[console log:[NSString stringWithFormat:@"Injecting %@(%@)", openedFileURL.lastPathComponent, openedFileURL]];

[self.recompiler recompileFileAtURL:openedFileURL completion:^(NSError *error) {
if (error) {
[weakSelf.viewHelper showError:error];
[console error:[NSString stringWithFormat:@"Recompilation failed %@", error]];
} else {
[weakSelf.viewHelper showSuccessResult];
[console log:@"Recompilation was successful"];
}
}];

} else {
[console error:[NSString stringWithFormat:@"Cannot inject this file right now. If you think that this file is injectable, try again bit later"]];
}
}

#pragma mark - Dealloc

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SFDYCIResultView.h
// SFDYCIHelper
// SFDYCIPlugin
//
// Created by Paul Taykalo on 10/14/12.
//
Expand Down
Loading

0 comments on commit 7b347b2

Please sign in to comment.