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

Commit 9f63ec2

Browse files
authored
Merge pull request #12 from paulcastro/issue_11
Issue 11, Add ability to specify target
2 parents d843dc4 + 7382474 commit 9f63ec2

8 files changed

Lines changed: 165 additions & 100 deletions

File tree

WhiskSwiftTools.xcodeproj/project.pbxproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
isa = PBXProject;
260260
attributes = {
261261
LastSwiftUpdateCheck = 0800;
262-
LastUpgradeCheck = 0800;
262+
LastUpgradeCheck = 0810;
263263
ORGANIZATIONNAME = IBM;
264264
TargetAttributes = {
265265
D6BC1BF11D4017BE00C2334C = {
@@ -340,8 +340,10 @@
340340
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
341341
CLANG_WARN_EMPTY_BODY = YES;
342342
CLANG_WARN_ENUM_CONVERSION = YES;
343+
CLANG_WARN_INFINITE_RECURSION = YES;
343344
CLANG_WARN_INT_CONVERSION = YES;
344345
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
346+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
345347
CLANG_WARN_UNREACHABLE_CODE = YES;
346348
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
347349
CODE_SIGN_IDENTITY = "-";
@@ -386,8 +388,10 @@
386388
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
387389
CLANG_WARN_EMPTY_BODY = YES;
388390
CLANG_WARN_ENUM_CONVERSION = YES;
391+
CLANG_WARN_INFINITE_RECURSION = YES;
389392
CLANG_WARN_INT_CONVERSION = YES;
390393
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
394+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
391395
CLANG_WARN_UNREACHABLE_CODE = YES;
392396
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
393397
CODE_SIGN_IDENTITY = "-";
@@ -406,6 +410,7 @@
406410
MACOSX_DEPLOYMENT_TARGET = 10.11;
407411
MTL_ENABLE_DEBUG_INFO = NO;
408412
SDKROOT = macosx;
413+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
409414
};
410415
name = Release;
411416
};

WhiskSwiftTools/ConsoleIO.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
import Foundation
1818

19-
let version = "0.1.0"
19+
let version = "0.4.0"
2020

2121
enum OptionType: String {
2222
case Build = "build"
2323
case Version = "version"
2424
case Help = "help"
2525
case Delete = "delete"
26+
case Path = "path"
27+
case Target = "target"
2628
case Undefined
2729

2830
init(value: String) {
@@ -39,6 +41,16 @@ enum OptionType: String {
3941
self = .Help
4042
case "h":
4143
self = .Help
44+
case "path":
45+
self = .Path
46+
case "p":
47+
self = .Path
48+
case "target":
49+
self = .Target
50+
case "t":
51+
self = .Target
52+
53+
4254
default:
4355
self = .Undefined
4456
}
@@ -53,14 +65,14 @@ class ConsoleIO {
5365
print ("usage:")
5466
print ("To install a project:")
5567
print ("=====================")
56-
print ("\(executableName) install (for current directory)")
68+
print ("\(executableName) install (for current directory) -t <optional target name>")
5769
print ("or")
58-
print ("\(executableName) install <project directory>")
70+
print ("\(executableName) install -p <optional project path> -t <optional target name>")
5971
print ("To uninstall a project:")
6072
print ("=======================")
61-
print ("\(executableName) uninstall (for current directory)")
73+
print ("\(executableName) uninstall (for current directory) -t <optional target name>")
6274
print ("or")
63-
print ("\(executableName) uninstall <project directory>")
75+
print ("\(executableName) uninstall -p <project directory> -t <optional target name>")
6476

6577
print ("Type \(executableName) -h or --help to show usage information")
6678
}

WhiskSwiftTools/PBXProject.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum PBXParseState {
2222
class PBXProject {
2323

2424
let fullPath: String!
25-
let targetName: String!
25+
let targetName: String
2626
var filesForTarget = [String:[String]]()
2727

2828
init(file: String, targetName: String) {
@@ -47,7 +47,7 @@ class PBXProject {
4747
print("PBXParse: Error, line from parseFile is nil, aborting.")
4848
return
4949
}
50-
var trimmedLine = line.trimmingCharacters(in: CharacterSet.whitespaces)
50+
let trimmedLine = line.trimmingCharacters(in: CharacterSet.whitespaces)
5151

5252
switch parseState {
5353
case .inital:
@@ -56,7 +56,7 @@ class PBXProject {
5656

5757
}
5858
case .inTarget:
59-
if trimmedLine.range(of: "PBXNativeTarget \"\(targetName!)\" */;") != nil {
59+
if trimmedLine.range(of: "PBXNativeTarget \"\(targetName)\" */;") != nil {
6060
parseState = .inNamedTarget
6161
}
6262
case .inNamedTarget:

WhiskSwiftTools/ProjectManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ open class ProjectManager {
2222
let path: String!
2323
let projectReader: ProjectReader!
2424
let namespace: String!
25+
var target: String?
2526

2627

27-
public init(path: String, repo: String? = nil, release: String? = nil, xcodeDirectory: String? = nil, credentials: WhiskCredentials, namespace: String) {
28+
public init(path: String, repo: String? = nil, release: String? = nil, xcodeDirectory: String? = nil, credentials: WhiskCredentials, namespace: String, target: String?) {
2829
whisk = WhiskAPI(credentials: credentials)
2930
self.path = path
3031
self.namespace = namespace
32+
self.target = target
3133

3234
do {
33-
projectReader = try ProjectReader(path: path, repo: repo, release: release)
35+
projectReader = try ProjectReader(path: path, repo: repo, release: release, target: target)
3436
} catch {
3537
projectReader = nil
3638
print("Error creating project \(error)")
@@ -198,7 +200,8 @@ open class ProjectManager {
198200

199201
for (name, rule) in rules {
200202
print("Creating rule \(name)")
201-
try whisk.createRule(name: name as String, namespace: namespace, triggerName: rule.trigger as String, actionName: rule.action as String, group: group)
203+
204+
try whisk.createRule(name: name as String, namespace: namespace, triggerName: "/\(namespace!)/\(rule.trigger)", actionName: "/\(namespace!)/\(rule.action)" as String, group: group)
202205
}
203206

204207
switch group.wait(timeout: DispatchTime.distantFuture) {

WhiskSwiftTools/ProjectReader.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ open class ProjectReader {
9494
var manifestDict = [NSString: NSString]()
9595
var bindingsDict = [NSString: NSString]()
9696

97+
var target: String?
9798

9899

99-
public init(path: String, repo: String? = nil, release: String? = nil) throws {
100+
101+
public init(path: String, repo: String? = nil, release: String? = nil, target: String?) throws {
100102

103+
self.target = target
101104

102105
if let repo = repo {
103106

@@ -331,7 +334,7 @@ open class ProjectReader {
331334
} else {
332335

333336
print("Found xcode directory \(isXcode.projectName!)" )
334-
let xcodeProject = WhiskTokenizer(from: dirPath, to:projectPath, projectFile: isXcode.projectName!)
337+
let xcodeProject = WhiskTokenizer(from: dirPath, to:projectPath, projectFile: isXcode.projectName!, target: target)
335338

336339
do {
337340
let xcodeTuple = try xcodeProject.readXCodeProjectDirectory()

WhiskSwiftTools/WhiskInstaller.swift

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,65 @@ class WhiskInstaller {
2020

2121
let consoleIO = ConsoleIO()
2222
var projectPath: String!
23+
var argumentTarget: String?
2324

2425
init() {
2526
projectPath = getCurrentDirectory()
2627
}
2728

2829
func staticMode() {
29-
let argCount = CommandLine.argc
30+
let argCount = Int(CommandLine.argc)
3031
let argument = CommandLine.arguments[1]
32+
33+
var i = 1
34+
var isBuild = true
3135

32-
if argCount > 2 {
33-
projectPath = NSString(string: CommandLine.arguments[2]).expandingTildeInPath as String
34-
}
3536

36-
var offset = 0
37-
if argument.hasPrefix("--") {
38-
offset = 2
39-
} else if argument.characters.first == "-" {
40-
offset = 1
37+
while (i < argCount) {
38+
let arg = CommandLine.arguments[i]
39+
40+
var offset = 0
41+
if arg.hasPrefix("--") {
42+
offset = 2
43+
} else if arg.characters.first == "-" {
44+
offset = 1
45+
}
46+
47+
let skipDashIndex = arg.index(argument.startIndex, offsetBy: offset)
48+
let (option, _) = consoleIO.getOption(arg.substring(from: skipDashIndex))
49+
50+
switch option {
51+
case .Build:
52+
isBuild = true
53+
i = i + 1
54+
print("Got build")
55+
case .Delete:
56+
isBuild = false
57+
i = i + 1
58+
print("Got delete")
59+
case .Path:
60+
projectPath = CommandLine.arguments[i+1]
61+
i = i + 2
62+
print("Got path \(projectPath)")
63+
case .Target:
64+
argumentTarget = CommandLine.arguments[i+1]
65+
i = i + 2
66+
print("Got target \(argumentTarget)")
67+
case .Version:
68+
ConsoleIO.printVersion()
69+
i = i + 1
70+
case .Help:
71+
ConsoleIO.printUsage()
72+
i = i + 1
73+
case .Undefined:
74+
ConsoleIO.printUsage()
75+
i = i + 1
76+
77+
}
4178
}
4279

43-
let skipDashIndex = argument.index(argument.startIndex, offsetBy: offset)
44-
let (option, _) = consoleIO.getOption(argument.substring(from: skipDashIndex))
45-
46-
switch option {
47-
case .Build:
80+
if isBuild == true {
81+
4882
do {
4983
if let pm = try setupProjectManager() {
5084
try pm.deployProject()
@@ -54,7 +88,7 @@ class WhiskInstaller {
5488
} catch {
5589
print("Error installing OpenWhisk project \(error)")
5690
}
57-
case .Delete:
91+
} else {
5892
do {
5993
if let pm = try setupProjectManager() {
6094
try pm.deleteProject()
@@ -64,13 +98,8 @@ class WhiskInstaller {
6498
} catch {
6599
print("Error installing OpenWhisk project \(error)")
66100
}
67-
case .Version:
68-
ConsoleIO.printVersion()
69-
case .Help:
70-
ConsoleIO.printUsage()
71-
case .Undefined:
72-
ConsoleIO.printUsage()
73101
}
102+
74103
}
75104

76105
func getCurrentDirectory() -> String {
@@ -97,9 +126,13 @@ class WhiskInstaller {
97126
}
98127
}
99128

129+
if namespace == nil {
130+
namespace = "_"
131+
}
132+
100133
if let tokens = tokens, let namespace = namespace {
101134
let credentials = WhiskCredentials(accessKey: tokens[0], accessToken: tokens[1])
102-
return ProjectManager(path: projectPath!, credentials: credentials, namespace: namespace)
135+
return ProjectManager(path: projectPath!, credentials: credentials, namespace: namespace, target:argumentTarget)
103136
}
104137
} catch {
105138
print("Error reading ~/.wskprops")

0 commit comments

Comments
 (0)