Permalink
Browse files

🚧 Port ActionKit, WIP on ProjectKit

  • Loading branch information...
1 parent 86a0477 commit a19bff2eaaee494882b7f89012b6847e0df84cce @andreyvit andreyvit committed Oct 19, 2015
Showing with 1,457 additions and 510 deletions.
  1. +1 βˆ’1 ATPathSpec
  2. +1 βˆ’1 ExpressiveFoundation
  3. +30 βˆ’32 LRActionKit/LRActionKit.xcodeproj/project.pbxproj
  4. +14 βˆ’8 LRActionKit/Source/Action/Action.swift
  5. +1 βˆ’1 LRActionKit/Source/Action/LRAssetPackageConfiguration.swift
  6. +1 βˆ’1 LRActionKit/Source/Action/Manifest/LRActionManifest.swift
  7. +1 βˆ’1 LRActionKit/Source/Action/Manifest/LRManifestLayer.swift
  8. +0 βˆ’21 LRActionKit/Source/ActionKitSingleton.h
  9. +0 βˆ’28 LRActionKit/Source/ActionKitSingleton.m
  10. +34 βˆ’0 LRActionKit/Source/ActionKitSingleton.swift
  11. +3 βˆ’3 LRActionKit/Source/Analysis/Deriver.swift
  12. +10 βˆ’11 LRActionKit/Source/Analysis/TagEvidenceTree.swift
  13. +17 βˆ’5 LRActionKit/Source/Basics/ProjectFile.swift
  14. +8 βˆ’9 LRActionKit/Source/Build/LRBuild.swift
  15. +60 βˆ’0 LRActionKit/Source/EnvironmentErrors/EnvLog.swift
  16. +52 βˆ’0 LRActionKit/Source/Inputs/FilterOption.swift
  17. +1 βˆ’1 LRActionKit/Source/Inputs/LRVersionSpec.m
  18. +0 βˆ’8 LRActionKit/Source/LRActionKit.h
  19. +0 βˆ’39 LRActionKit/Source/Result/LROperationResult.h
  20. +0 βˆ’102 LRActionKit/Source/Result/LROperationResult.m
  21. +114 βˆ’0 LRActionKit/Source/Result/LROperationResult.swift
  22. +26 βˆ’27 LRActionKit/Source/Rule/Rule.swift
  23. +1 βˆ’1 LRActionKit/Source/Rule/Rulebook.swift
  24. +42 βˆ’25 LRActionKit/Source/Rule/Specific/CompileFile.swift
  25. +1 βˆ’1 LRActionKit/Source/Rule/Specific/CompileFolder.swift
  26. +3 βˆ’3 LRActionKit/Source/Rule/Specific/CustomCommand.swift
  27. +3 βˆ’3 LRActionKit/Source/Rule/Specific/Filter.swift
  28. +1 βˆ’1 LRActionKit/Source/Rule/Specific/RunTests.swift
  29. +3 βˆ’3 LRActionKit/Source/Rule/Specific/UserScript.swift
  30. +105 βˆ’1 LRActionKit/Source/Rule/Support/ScriptInvocation.swift
  31. +0 βˆ’37 LRActionKit/Source/Rule/Support/ScriptInvocationStep.h
  32. +0 βˆ’81 LRActionKit/Source/Rule/Support/ScriptInvocationStep.m
  33. +2 βˆ’2 LRActionKit/Source/Target/LRFileTarget.swift
  34. +0 βˆ’5 LRActionKit/Source/Utilities/LRPathProcessing.h
  35. +0 βˆ’29 LRActionKit/Source/Utilities/LRPathProcessing.m
  36. +56 βˆ’0 LRActionKit/Source/Utilities/OutputMask.swift
  37. +6 βˆ’2 LRActionKit/Source/Utilities/UserScript.h
  38. +11 βˆ’5 LRActionKit/Source/Utilities/UserScript.m
  39. +467 βˆ’0 LRProjectKit/LRProjectKit.xcodeproj/project.pbxproj
  40. +24 βˆ’0 LRProjectKit/Metadata/Info-Tests.plist
  41. +28 βˆ’0 LRProjectKit/Metadata/Info.plist
  42. +19 βˆ’0 LRProjectKit/Source/LRProjectKit.h
  43. +100 βˆ’0 LRProjectKit/Source/Plugin.swift
  44. +8 βˆ’0 LRProjectKit/Source/PluginContext.swift
  45. +126 βˆ’0 LRProjectKit/Source/PluginManager.swift
  46. +1 βˆ’0 LRProjectKit/Source/Project.swift
  47. +7 βˆ’0 LRProjectKit/Source/Workspace.swift
  48. +35 βˆ’0 LRProjectKit/Tests/LRProjectKitTests.swift
  49. +2 βˆ’2 PackageManagerKit/Source/GenericPackages/LRPackageContainer.h
  50. +10 βˆ’4 PackageManagerKit/Source/GenericPackages/LRPackageManager.h
  51. +7 βˆ’2 PackageManagerKit/Source/GenericPackages/LRPackageType.h
  52. +9 βˆ’4 PackageManagerKit/Source/GenericRuntime/RuntimeInstance.h
  53. +1 βˆ’0 mac/LRActionKit/LRActionKit.xcodeproj/project.pbxproj
  54. +1 βˆ’0 mac/LRActionsPresentationKit/LRActionsPresentationKit.xcodeproj/project.pbxproj
  55. +1 βˆ’0 mac/LRCommons/LRCommons.xcodeproj/project.pbxproj
  56. +1 βˆ’0 mac/LRMarketingKit/LRMarketingKit.xcodeproj/project.pbxproj
  57. +1 βˆ’0 mac/LiveReload.xcodeproj/project.pbxproj
  58. +1 βˆ’0 mac/SwiftyFoundation/SwiftyFoundation.xcodeproj/project.pbxproj
Oops, something went wrong.
@@ -31,7 +31,8 @@ public class Action : LRManifestBasedObject {
public init(manifest: [String: AnyObject], container: ActionContainer) {
self.container = container
- identifier = manifest["id"]~~~ ?? ""
+ let identifier = manifest["id"]~~~ ?? ""
+ self.identifier = identifier
name = manifest["name"]~~~ ?? identifier
// if (_identifier.length == 0)
// [self addErrorMessage:@"'id' attribute is required"];
@@ -103,14 +104,14 @@ public class Action : LRManifestBasedObject {
self.derivers = derivers
// Manifests
- let packageManager = ActionKitSingleton.sharedActionKit().packageManager
+ let packageManager = ActionKitSingleton.sharedActionKit.packageManager
let versionInfo = (manifest["versionInfo"] as? [String: AnyObject]) ?? [:]
let versionInfoLayers = versionInfo.mapIf { (packageRefString, info) -> LRManifestLayer? in
// no idea what this check means
if packageRefString.hasPrefix("__") {
return nil
}
- let reference = packageManager.packageReferenceWithString(packageRefString)
+ let reference = packageManager.packageReferenceWithString(packageRefString)!
return LRManifestLayer(manifest: info as! [String: AnyObject], requiredPackageReferences: [reference], errorSink: self)
}
@@ -134,20 +135,25 @@ public class Action : LRManifestBasedObject {
return "\(kind) '\(identifier)'"
}
- public func fakeChangeDestinationNameForSourceFile(file: ProjectFile) -> String? {
+ public func fakeChangeDestinationPathForSourceFile(file: ProjectFile) -> RelPath? {
if let fakeChangeExtension = fakeChangeExtension {
- let relativePath = file.relativePath
- if relativePath.pathExtension == fakeChangeExtension {
+ if file.path.hasPathExtension(fakeChangeExtension) {
return nil
} else {
- return relativePath.stringByDeletingPathExtension.stringByAppendingPathExtension(fakeChangeExtension)
+ // TODO: use the matched input extension instead of the shortest extension
+ let (path, found) = file.path.replaceShortestPathExtensionWith(fakeChangeExtension)
+ if found {
+ return path
+ } else {
+ return nil
+ }
}
} else {
return nil
}
}
- public func newRule(contextAction contextAction: LRContextAction, memento: NSDictionary?) -> Rule {
+ public func newRule(contextAction contextAction: LRContextAction, memento: JSONObject?) -> Rule {
return ruleType.init(contextAction: contextAction, memento: memento)
}
@@ -7,7 +7,7 @@ public class LRAssetPackageConfiguration: LRManifestBasedObject {
public let packageReferences: [LRPackageReference]
public override init(manifest: [String: AnyObject], errorSink: LRManifestErrorSink?) {
- let packageManager = ActionKitSingleton.sharedActionKit().packageManager
+ let packageManager = ActionKitSingleton.sharedActionKit.packageManager
let strings = ArrayValue(manifest["packages"]) { $0 as? String } ?? []
packageReferences = strings.mapIf { packageManager.packageReferenceWithString($0) }
@@ -21,7 +21,7 @@ public class LRActionManifest : LRManifestBasedObject {
public init(layers: [LRManifestLayer]) {
self.layers = layers
- let optionRegistry = ActionKitSingleton.sharedActionKit().optionRegistry!
+ let optionRegistry = ActionKitSingleton.sharedActionKit.optionRegistry
errorSpecs = layers.map { layer in
ArrayValue(layer.manifest["errors"]) { $0 as AnyObject } ?? []
@@ -9,7 +9,7 @@ public class LRManifestLayer: LRManifestBasedObject {
public let packageReferences: [LRPackageReference]
public convenience override init(manifest: [String: AnyObject], errorSink: LRManifestErrorSink?) {
- let packageManager = ActionKitSingleton.sharedActionKit().packageManager;
+ let packageManager = ActionKitSingleton.sharedActionKit.packageManager
let dicts = JSONObjectsArrayValue(manifest["applies_to"]) ?? []
let packageReferences = dicts.mapIf { packageManager.packageReferenceWithDictionary($0) }
@@ -1,21 +0,0 @@
-#import <Foundation/Foundation.h>
-
-@class LRPackageManager;
-@class OptionRegistry;
-
-
-// stopgap approach until we can pass a proper context everywhere
-
-@interface ActionKitSingleton : NSObject
-
-+ (instancetype)sharedActionKit;
-
-@property (nonatomic) OptionRegistry *optionRegistry;
-@property (nonatomic) LRPackageManager *packageManager;
-
-typedef void (^ActionKitPostMessageCompletionBlock)(NSError *error, NSDictionary *response);
-typedef void (^ActionKitPostMessageBlock)(NSDictionary *message, ActionKitPostMessageCompletionBlock completionBlock);
-
-@property (nonatomic, copy) ActionKitPostMessageBlock postMessageBlock;
-
-@end
@@ -1,28 +0,0 @@
-#import "ActionKitSingleton.h"
-#import "LRActionKit-Swift.h"
-
-
-@implementation ActionKitSingleton
-
-static ActionKitSingleton *sharedActionKit;
-
-+ (instancetype)sharedActionKit {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedActionKit = [ActionKitSingleton new];
- });
- return sharedActionKit;
-}
-
-- (instancetype)init {
- self = [super init];
- if (self) {
- _optionRegistry = [OptionRegistry new];
- [_optionRegistry addOptionType:[CheckboxOptionType new]];
- [_optionRegistry addOptionType:[MultipleChoiceOptionType new]];
- [_optionRegistry addOptionType:[TextOptionType new]];
- }
- return self;
-}
-
-@end
@@ -0,0 +1,34 @@
+import Foundation
+import PackageManagerKit
+import ExpressiveCasting
+
+@objc
+public final class ActionKitSingleton: NSObject {
+
+ public static let sharedActionKit = ActionKitSingleton()
+
+ public let optionRegistry: OptionRegistry = ({
+ let or = OptionRegistry()
+ or.addOptionType(CheckboxOptionType())
+ or.addOptionType(MultipleChoiceOptionType())
+ or.addOptionType(TextOptionType())
+ return or
+ })()
+
+ public var packageManager: LRPackageManager!
+
+ public var postMessageBlock: (message: JSONObject, completionBlock: (error: NSError?, response: JSONObject?) -> Void) -> Void
+
+ private override init() {
+ postMessageBlock = { message, completionBlock in
+ fatalError("postMessageBlock not set, sending message \(message)")
+ }
+
+ super.init()
+ }
+
+ public func postMessage(message: JSONObject, completionBlock: (error: NSError?, response: JSONObject?) -> Void) {
+ postMessageBlock(message: message, completionBlock: completionBlock)
+ }
+
+}
@@ -20,14 +20,14 @@ public class CompileFileRuleDeriver : Deriver {
public override func deriveRules(fromTagTree tree: TagEvidenceTree, forActionSet actionSet: ActionSet) -> [Rule] {
if let boundAction = actionSet.findBoundAction(action: action) {
let folders = tree.findCoveringFoldersForTag(action.compilableFileTag!)
- return folders.map { self._createRule(relativeFolder: $0, boundAction: boundAction) }
+ return folders.map { self._createRuleForDirectory($0, boundAction: boundAction) }
} else {
return []
}
}
- private func _createRule(relativeFolder relativeFolder: String, boundAction: LRContextAction) -> Rule {
- return CompileFileRule(contextAction: boundAction, memento: ["action": boundAction.action.identifier, "filter": FilterOption(subfolder: relativeFolder).memento, "output": FilterOption(subfolder: relativeFolder).memento])
+ private func _createRuleForDirectory(directory: RelPath, boundAction: LRContextAction) -> Rule {
+ return CompileFileRule(contextAction: boundAction, memento: ["action": boundAction.action.identifier, "filter": FilterOption(directory: directory).memento, "output": FilterOption(directory: directory).memento])
}
}
@@ -33,24 +33,23 @@ public final class TagEvidenceTree: CustomStringConvertible {
return lines.joinWithSeparator("\n");
}
- public func findCoveringFoldersForTag(tag: Tag) -> [String] {
+ public func findCoveringFoldersForTag(tag: Tag) -> [RelPath] {
print("findCoveringFoldersForTag(\(tag.name)):")
- var initialFolders: Set<String> = []
+ var initialFolders: Set<RelPath> = []
for file in tagsToFiles[tag] ?? [] {
- initialFolders.insert(file.relativePath.stringByDeletingLastPathComponent)
+ initialFolders.insert(file.path.parent!)
}
print(" initialFolders = \(initialFolders)")
- var nextFolders: Set<String> = initialFolders
- var folderChildren: [String: Set<String>] = [:]
+ var nextFolders: Set<RelPath> = initialFolders
+ var folderChildren: [RelPath: Set<RelPath>] = [:]
while !nextFolders.isEmpty {
let thisFolders = nextFolders
nextFolders = []
for folder in thisFolders {
- if folder != "" {
+ if let parent = folder.parent {
print(" visiting \(folder)")
- let parent = folder.stringByDeletingLastPathComponent
if folderChildren[parent] == nil {
folderChildren[parent] = [folder]
nextFolders.insert(parent)
@@ -61,21 +60,21 @@ public final class TagEvidenceTree: CustomStringConvertible {
}
}
- var junctions: [String] = []
+ var junctions: [RelPath] = []
print(" collecting junctions")
- _collectJunctionPoints("", folderChildren: folderChildren, initialFolders: initialFolders, junctions: &junctions)
+ _collectJunctionPoints(RelPath(), folderChildren: folderChildren, initialFolders: initialFolders, junctions: &junctions)
print(" result = \(junctions)")
return junctions
}
- private func _collectJunctionPoints(folder: String, folderChildren: [String: Set<String>], initialFolders: Set<String>, inout junctions: [String]) {
+ private func _collectJunctionPoints(folder: RelPath, folderChildren: [RelPath: Set<RelPath>], initialFolders: Set<RelPath>, inout junctions: [RelPath]) {
if initialFolders.contains(folder) {
print(" folder with leaf files \(folder)")
junctions.append(folder)
// don't descend into children
} else {
let children = folderChildren[folder] ?? []
- if folder != "" && children.count >= 2 {
+ if folder.hasParent && children.count >= 2 {
print(" non-root junction folder \(folder)")
junctions.append(folder)
// don't descend into children for now, although it would return useful alternative folders
@@ -1,18 +1,26 @@
import Foundation
+import ATPathSpec
public class ProjectFile: NSObject {
- public let relativePath: String
+ public let path: RelPath
public let project: ProjectContext
- public init(relativePath: String, project: ProjectContext) {
- self.relativePath = relativePath
+ public init(path: RelPath, project: ProjectContext) {
+ self.path = path
self.project = project
}
+ public convenience init(relativePath: String, project: ProjectContext) {
+ self.init(path: RelPath(relativePath, isDirectory: false), project: project)
+ }
+
+ public var relativePath: String {
+ return path.pathString
+ }
+
public var absoluteURL: NSURL {
- let rootURL: NSURL = project.rootURL
- return rootURL.URLByAppendingPathComponent(relativePath)
+ return path.resolve(baseURL: project.rootURL)
}
public var absolutePath: String {
@@ -27,4 +35,8 @@ public class ProjectFile: NSObject {
return "File<\(relativePath)>"
}
+ public func isSameFile(other: ProjectFile) -> Bool {
+ return (self.path == other.path) && (self.project === other.project)
+ }
+
}
@@ -1,6 +1,7 @@
import Foundation
import ExpressiveCollections
import ExpressiveFoundation
+import ExpressiveCasting
import ATPathSpec
public class LRBuild : NSObject {
@@ -36,7 +37,7 @@ public class LRBuild : NSObject {
self.rules = rules
}
- public func addReloadRequest(reloadRequest: NSDictionary) {
+ public func addReloadRequest(reloadRequest: JSONObject) {
reloadRequests.append(reloadRequest)
}
@@ -92,15 +93,13 @@ public class LRBuild : NSObject {
continue // compiled; wait for the destination file change event to send a reload request
}
- let fullPath = file.absolutePath as String
-
let actions = project.compilerActionsForFile(file)
- let fakeDestinationName = actions.findMapped { $0.fakeChangeDestinationNameForSourceFile(file) }
- if let fakeDestinationName = fakeDestinationName {
- let fakePath = fullPath.stringByDeletingLastPathComponent.stringByAppendingPathComponent(fakeDestinationName)
- addReloadRequest(["path": fakePath, "originalPath": fullPath, "localPath": NSNull()])
+ let fakeDestinationPath = actions.findMapped { $0.fakeChangeDestinationPathForSourceFile(file) }
+ if let fakeDestinationPath = fakeDestinationPath {
+ let fakeURL = fakeDestinationPath.resolve(baseURL: file.project.rootURL)
+ addReloadRequest(["path": fakeURL.path!, "originalPath": file.absolutePath, "localPath": NSNull()])
} else {
- addReloadRequest(["path": fullPath, "originalPath": NSNull(), "localPath": fullPath])
+ addReloadRequest(["path": file.absolutePath, "originalPath": NSNull(), "localPath": file.absolutePath])
}
}
}
@@ -197,7 +196,7 @@ public class LRBuild : NSObject {
firstFailure = result
}
- messages.appendContentsOf(result.messages as! [LRMessage])
+ messages.appendContentsOf(result.messages)
project.displayResult(result, key: key)
}
Oops, something went wrong.

0 comments on commit a19bff2

Please sign in to comment.