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

Commit

Permalink
Safer plugin, Xcode 8 unsigned support
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulTaykalo committed Feb 21, 2017
1 parent 2a671d0 commit 094dd03
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ DerivedData
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#Pods/
Source/.idea
13 changes: 7 additions & 6 deletions Binary/SFDYCIPlugin.xcplugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>14F27</string>
<string>16D32</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>7A220</string>
<string>8C1002</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>15A278</string>
<string>16C58</string>
<key>DTSDKName</key>
<string>macosx10.11</string>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0700</string>
<string>0821</string>
<key>DTXcodeBuild</key>
<string>7A220</string>
<string>8C1002</string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>640F884E-CE55-4B40-87C0-8869546CAB7A</string>
Expand All @@ -57,6 +57,7 @@
<string>7265231C-39B4-402C-89E1-16167C4CC990</string>
<string>F41BD31E-2683-44B8-AE7F-5F09E919790E</string>
<string>ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C</string>
<string>E0A62D1F-3C18-4D74-BFE5-A4167D643966</string>
</array>
<key>NSPrincipalClass</key>
<string>SFDYCIPlugin</string>
Expand Down
Binary file modified Binary/SFDYCIPlugin.xcplugin/Contents/MacOS/SFDYCIPlugin
Binary file not shown.
115 changes: 115 additions & 0 deletions Binary/SFDYCIPlugin.xcplugin/Contents/_CodeSignature/CodeResources
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?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>files</key>
<dict/>
<key>files2</key>
<dict/>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ - (void)recompileFileAtURL:(NSURL *)fileURL completion:(void (^)(NSError *error)
commands = [buildContext commands];
} else {
// Xcode 7.0
[buildContext waitForDependencyGraph];
[buildContext lockDependencyGraph];
commands = [[[buildContext dependencyNodeForPath:fileURL.path] consumerCommands] allObjects];
[buildContext unlockDependencyGraph];
@try {
[buildContext waitForDependencyGraph];
[buildContext lockDependencyGraph];
commands = [[[buildContext dependencyNodeForPath:fileURL.path] consumerCommands] allObjects];
[buildContext unlockDependencyGraph];
}
@catch (NSException *exception) {
[self.console error:@"Cannot get file relation to the target. Please run project again. ¯\\_(ツ)_/¯"];
}
}

[self.console debug:[NSString stringWithFormat:@"Commands : %@", commands]];
Expand Down Expand Up @@ -115,29 +120,12 @@ - (void)runCompilationCommand:(id<CDRSXcode_XCDependencyCommand>)command complet
[self.console debug:[NSString stringWithFormat:@"Task started %@ + %@", command.commandPath, command.arguments]];
[self.console log:[NSString stringWithFormat:@"Injection started"]];

[DYCI_CCPShellRunner runShellCommand:command.commandPath withArgs:command.arguments directory:command.workingDirectoryPath environment:[command.environment mutableCopy]
completion:^(NSTask *t) {
@try {
if (t.terminationStatus != 0) {
[self.console error:[NSString stringWithFormat:@"Task failed %@ + %@", command.commandPath, command.arguments]];
[self.console error:[NSString stringWithFormat:@"Task failed %i", t.terminationStatus]];
[self.console error:[NSString stringWithFormat:@"Task failed %@", t.standardError]];
if (completion) {
completion([SFDYCIErrorFactory compilationErrorWithMessage:[t.standardError copy]]);
}
} else {
[self.console log:[NSString stringWithFormat:@"Task completed %@", @(t.terminationStatus)]];
if (completion) {
completion(nil);
}
}
} @catch (NSException * e) {
[self.console error:[NSString stringWithFormat:@"Task failed %@ + %@", command.commandPath, command.arguments]];
if (completion) {
completion([SFDYCIErrorFactory compilationErrorWithMessage:[t.standardError copy]]);
}
}
}];
[DYCI_CCPShellRunner runShellCommand:command.commandPath
withArgs:command.arguments
directory:command.workingDirectoryPath
environment:[command.environment mutableCopy]
console:self.console
completion:completion];

}

Expand All @@ -154,6 +142,8 @@ - (DYCI_CCPXCodeConsole *)console {

- (void)createDynamiclibraryWithCommand:(id <CDRSXcode_XCDependencyCommand>)command completion:(void (^)(NSError *))completion {

void (^safeCompletion)(NSError *) = completion ?: ^(NSError * error){};

SFDYCIClangParams * clangParams = [self.clangParamsExtractor extractParamsFromArguments:command.arguments];
[self.console debug:[NSString stringWithFormat:@"Clang params extracted : %@", clangParams]];

Expand Down Expand Up @@ -200,52 +190,60 @@ - (void)createDynamiclibraryWithCommand:(id <CDRSXcode_XCDependencyCommand>)comm
[dlybArguments addObjectsFromArray:clangParams.LParams];
[dlybArguments addObjectsFromArray:clangParams.FParams];

NSString *outputPath = [[@"~/.dyci" stringByExpandingTildeInPath] stringByAppendingPathComponent:libraryName];
[dlybArguments addObjectsFromArray:
@[
clangParams.objectCompilationPath,
@"-install_name", [NSString stringWithFormat:@"/usr/local/lib/%@", libraryName],
@"-Xlinker",
@"-objc_abi_version",
@"-Xlinker",
@"2",
@"-ObjC",
@"-undefined",
@"dynamic_lookup",
@"-fobjc-arc",
@"-fobjc-link-runtime",
@"-Xlinker",
@"-no_implicit_dylibs",
clangParams.minOSParams,
@"-single_module",
@"-compatibility_version",
@"5",
@"-current_version",
@"5",
@"-o",
[[@"~/.dyci" stringByExpandingTildeInPath] stringByAppendingPathComponent:libraryName]
//, @"-v"
]
@[
clangParams.objectCompilationPath,
@"-install_name", [NSString stringWithFormat:@"/usr/local/lib/%@", libraryName],
@"-Xlinker",
@"-objc_abi_version",
@"-Xlinker",
@"2",
@"-ObjC",
@"-undefined",
@"dynamic_lookup",
@"-fobjc-arc",
@"-fobjc-link-runtime",
@"-Xlinker",
@"-no_implicit_dylibs",
clangParams.minOSParams,
@"-single_module",
@"-compatibility_version",
@"5",
@"-current_version",
@"5",
@"-o",
outputPath
//, @"-v"
]
];


DYCI_CCPXCodeConsole *console = [DYCI_CCPXCodeConsole consoleForKeyWindow];
[console debug:[NSString stringWithFormat:@"Task started %@ + %@", command.commandPath, dlybArguments]];

[DYCI_CCPShellRunner runShellCommand:command.commandPath withArgs:dlybArguments directory:command.workingDirectoryPath environment:[command.environment mutableCopy]
completion:^(NSTask *t) {
if (t.terminationStatus != 0) {
[console error:[NSString stringWithFormat:@"Task failed %@ + %@", command.commandPath, command.arguments]];
[console error:[NSString stringWithFormat:@"Task failed %i", t.terminationStatus]];
[console error:[NSString stringWithFormat:@"Task failed %@", t.standardError]];
if (completion) {
completion([SFDYCIErrorFactory compilationErrorWithMessage:[t.standardError copy]]);
}
} else {
[console log:[NSString stringWithFormat:@"Task completed %@", @(t.terminationStatus)]];
if (completion) {
completion(nil);
}
[DYCI_CCPShellRunner runShellCommand:command.commandPath
withArgs:dlybArguments
directory:command.workingDirectoryPath
environment:[command.environment mutableCopy]
console:self.console
completion:^(NSError *error) {
if (error) {
safeCompletion(error);
return;
}

[DYCI_CCPShellRunner runShellCommand:@"/usr/bin/codesign"
withArgs:@[@"--force", @"--sign", @"-", outputPath]
directory:command.workingDirectoryPath
environment:[command.environment mutableCopy]
console:self.console
completion:^(NSError *error2) {
safeCompletion(error2);
}];

;

}];

}
Expand Down Expand Up @@ -280,4 +278,4 @@ - (BOOL)canRecompileFileAtURL:(NSURL *)fileURL {
return NO;
}

@end
@end
10 changes: 10 additions & 0 deletions Source/Classes/Xcode/Helpers/DYCI_CCPShellRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@

#import <Foundation/Foundation.h>

@protocol DYCI_CCPXCodeConsoleProtocol;

@interface DYCI_CCPShellRunner : NSObject

+ (void)runShellCommand:(NSString *)command withArgs:(NSArray *)args directory:(NSString *)directory environment:(NSMutableDictionary *)environment completion:(void (^)(NSTask *t))completion;

@end


@interface DYCI_CCPShellRunner (ConsoleRunning)

+ (void)runShellCommand:(NSString *)command withArgs:(NSArray *)args directory:(NSString *)directory environment:(NSMutableDictionary *)environment
console:(id<DYCI_CCPXCodeConsoleProtocol>)console completion:(void (^)(NSError *))completion;

@end
Loading

0 comments on commit 094dd03

Please sign in to comment.