Permalink
Browse files

🚧 Add LRActionKit (doesn't build yet)

  • Loading branch information...
1 parent ecada77 commit 86a047736e845b98916b9cf1bb7ef2225ab07172 @andreyvit andreyvit committed Oct 2, 2015
Showing with 4,954 additions and 3 deletions.
  1. +1 βˆ’1 ExpressiveCocoa
  2. +1 βˆ’1 ExpressiveCollections
  3. +1 βˆ’1 ExpressiveFoundation
  4. +823 βˆ’0 LRActionKit/LRActionKit.xcodeproj/project.pbxproj
  5. +24 βˆ’0 LRActionKit/Metadata/Info-Tests.plist
  6. +28 βˆ’0 LRActionKit/Metadata/Info.plist
  7. +154 βˆ’0 LRActionKit/Source/Action/Action.swift
  8. +8 βˆ’0 LRActionKit/Source/Action/ActionContainer.swift
  9. +31 βˆ’0 LRActionKit/Source/Action/LRActionVersion.swift
  10. +22 βˆ’0 LRActionKit/Source/Action/LRAssetPackageConfiguration.swift
  11. +103 βˆ’0 LRActionKit/Source/Action/LRContextAction.swift
  12. +54 βˆ’0 LRActionKit/Source/Action/Manifest/LRActionManifest.swift
  13. +25 βˆ’0 LRActionKit/Source/Action/Manifest/LRManifestLayer.swift
  14. +37 βˆ’0 LRActionKit/Source/ActionKitGlobals.h
  15. +39 βˆ’0 LRActionKit/Source/ActionKitGlobals.m
  16. +21 βˆ’0 LRActionKit/Source/ActionKitSingleton.h
  17. +28 βˆ’0 LRActionKit/Source/ActionKitSingleton.m
  18. +46 βˆ’0 LRActionKit/Source/Analysis/ActionSet.swift
  19. +33 βˆ’0 LRActionKit/Source/Analysis/Deriver.swift
  20. +42 βˆ’0 LRActionKit/Source/Analysis/FileClassifier.swift
  21. +29 βˆ’0 LRActionKit/Source/Analysis/ImportGraph.h
  22. +144 βˆ’0 LRActionKit/Source/Analysis/ImportGraph.m
  23. +50 βˆ’0 LRActionKit/Source/Analysis/ProjectAnalysis.swift
  24. +32 βˆ’0 LRActionKit/Source/Analysis/Tag.swift
  25. +90 βˆ’0 LRActionKit/Source/Analysis/TagEvidenceTree.swift
  26. +30 βˆ’0 LRActionKit/Source/Analysis/Tagger.swift
  27. +31 βˆ’0 LRActionKit/Source/Basics/LRManifestBasedObject.swift
  28. +7 βˆ’0 LRActionKit/Source/Basics/LRManifestErrorSink.h
  29. +33 βˆ’0 LRActionKit/Source/Basics/ProjectContext.swift
  30. +30 βˆ’0 LRActionKit/Source/Basics/ProjectFile.swift
  31. +204 βˆ’0 LRActionKit/Source/Build/LRBuild.swift
  32. +25 βˆ’0 LRActionKit/Source/Inputs/FilterOption.h
  33. +69 βˆ’0 LRActionKit/Source/Inputs/FilterOption.m
  34. +46 βˆ’0 LRActionKit/Source/Inputs/LRVersionSpec.h
  35. +162 βˆ’0 LRActionKit/Source/Inputs/LRVersionSpec.m
  36. +13 βˆ’0 LRActionKit/Source/Inputs/LRVersionTag.h
  37. +39 βˆ’0 LRActionKit/Source/LRActionKit.h
  38. +95 βˆ’0 LRActionKit/Source/Options/CheckboxOption.swift
  39. +36 βˆ’0 LRActionKit/Source/Options/CustomArgumentsOption.swift
  40. +171 βˆ’0 LRActionKit/Source/Options/MultipleChoiceOption.swift
  41. +52 βˆ’0 LRActionKit/Source/Options/Option.swift
  42. +57 βˆ’0 LRActionKit/Source/Options/OptionProtocols.swift
  43. +32 βˆ’0 LRActionKit/Source/Options/OptionRegistry.swift
  44. +103 βˆ’0 LRActionKit/Source/Options/TextOption.swift
  45. +30 βˆ’0 LRActionKit/Source/Options/VersionOption.swift
  46. +26 βˆ’0 LRActionKit/Source/Result/LRMessage.swift
  47. +39 βˆ’0 LRActionKit/Source/Result/LROperationResult.h
  48. +102 βˆ’0 LRActionKit/Source/Result/LROperationResult.m
  49. +312 βˆ’0 LRActionKit/Source/Rule/Rule.swift
  50. +119 βˆ’0 LRActionKit/Source/Rule/Rulebook.swift
  51. +81 βˆ’0 LRActionKit/Source/Rule/Specific/CompileFile.swift
  52. +31 βˆ’0 LRActionKit/Source/Rule/Specific/CompileFolder.swift
  53. +87 βˆ’0 LRActionKit/Source/Rule/Specific/CustomCommand.swift
  54. +45 βˆ’0 LRActionKit/Source/Rule/Specific/Filter.swift
  55. +43 βˆ’0 LRActionKit/Source/Rule/Specific/RunTests.swift
  56. +75 βˆ’0 LRActionKit/Source/Rule/Specific/UserScript.swift
  57. +35 βˆ’0 LRActionKit/Source/Rule/Support/ScriptInvocation.swift
  58. +37 βˆ’0 LRActionKit/Source/Rule/Support/ScriptInvocationStep.h
  59. +81 βˆ’0 LRActionKit/Source/Rule/Support/ScriptInvocationStep.m
  60. +31 βˆ’0 LRActionKit/Source/Target/LRFileTarget.swift
  61. +20 βˆ’0 LRActionKit/Source/Target/LRProjectTarget.swift
  62. +26 βˆ’0 LRActionKit/Source/Target/LRTarget.swift
  63. +11 βˆ’0 LRActionKit/Source/Testing/LRTRGlobals.h
  64. +20 βˆ’0 LRActionKit/Source/Testing/LRTRGlobals.m
  65. +25 βˆ’0 LRActionKit/Source/Testing/LRTRProtocolParser.h
  66. +20 βˆ’0 LRActionKit/Source/Testing/LRTRProtocolParser.m
  67. +9 βˆ’0 LRActionKit/Source/Testing/LRTRRun.h
  68. +34 βˆ’0 LRActionKit/Source/Testing/LRTRRun.m
  69. +14 βˆ’0 LRActionKit/Source/Testing/LRTRTest.h
  70. +31 βˆ’0 LRActionKit/Source/Testing/LRTRTest.m
  71. +5 βˆ’0 LRActionKit/Source/Testing/LRTRTestAnythingProtocolParser.h
  72. +127 βˆ’0 LRActionKit/Source/Testing/LRTRTestAnythingProtocolParser.m
  73. +5 βˆ’0 LRActionKit/Source/Utilities/LRPathProcessing.h
  74. +29 βˆ’0 LRActionKit/Source/Utilities/LRPathProcessing.m
  75. +53 βˆ’0 LRActionKit/Source/Utilities/UserScript.h
  76. +213 βˆ’0 LRActionKit/Source/Utilities/UserScript.m
  77. +37 βˆ’0 LRActionKit/Tests/LRActionKitTests.swift
Oops, something went wrong.
@@ -0,0 +1,24 @@
+<?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>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</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>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+</dict>
+</plist>
@@ -0,0 +1,28 @@
+<?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>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>$(CURRENT_PROJECT_VERSION)</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright Β© 2015 Andrey Tarantsov. All rights reserved.</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
@@ -0,0 +1,154 @@
+import Foundation
+import ExpressiveCasting
+import PackageManagerKit
+import ATVersionKit
+import ATPathSpec
+
+public class Action : LRManifestBasedObject {
+
+ public let container: ActionContainer
+
+ public let identifier: String
+ public let name: String
+ public var kind: ActionKind
+
+ public let ruleType: Rule.Type
+ public let rowClassName: String
+
+ private let fakeChangeExtension: String?
+
+ public let combinedIntrinsicInputPathSpec: ATPathSpec
+
+ public private(set) var packageConfigurations: [LRAssetPackageConfiguration]!
+
+ public private(set) var manifestLayers: [LRManifestLayer]!
+
+ public var primaryVersionSpace: LRVersionSpace?
+
+ public let compilableFileTag: Tag?
+ public let taggers: [Tagger]
+ public private(set) var derivers: [Deriver]!
+
+ public init(manifest: [String: AnyObject], container: ActionContainer) {
+ self.container = container
+ identifier = manifest["id"]~~~ ?? ""
+ name = manifest["name"]~~~ ?? identifier
+ // if (_identifier.length == 0)
+ // [self addErrorMessage:@"'id' attribute is required"];
+
+ // if (_kind == ActionKindUnknown)
+ // [self addErrorMessage:[NSString stringWithFormat:@"'kind' attribute is required and must be one of %@", LRValidActionKindStrings()]];
+
+ let type = manifest["type"]~~~ ?? ""
+ switch type {
+ case "filter":
+ kind = .Filter
+ ruleType = FilterRule.self
+ rowClassName = "FilterRuleRow"
+ case "compile-file":
+ kind = .Compiler
+ ruleType = CompileFileRule.self
+ rowClassName = "CompileFileRuleRow"
+ case "compile-folder":
+ kind = .Postproc
+ ruleType = CompileFolderRule.self
+ rowClassName = "FilterRuleRow"
+ case "run-tests":
+ kind = .Postproc
+ ruleType = RunTestsRule.self
+ rowClassName = "FilterRuleRow"
+ case "custom-command":
+ kind = .Postproc
+ ruleType = CustomCommandRule.self
+ rowClassName = "CustomCommandRuleRow"
+ case "user-script":
+ kind = .Postproc
+ ruleType = UserScriptRule.self
+ rowClassName = "UserScriptRuleRow"
+ default:
+ fatalError("Missing or unknown action type")
+ }
+
+ if let inputPathSpecString: String = manifest["input"]~~~ {
+ combinedIntrinsicInputPathSpec = ATPathSpec(string: inputPathSpecString, syntaxOptions:.FlavorExtended)
+ } else {
+ combinedIntrinsicInputPathSpec = ATPathSpec.emptyPathSpec()
+ }
+
+ if let outputSpecString: String = manifest["output"]~~~ {
+ if (outputSpecString == "*.css") {
+ fakeChangeExtension = "css"
+ } else {
+ fakeChangeExtension = nil
+ }
+ } else {
+ fakeChangeExtension = nil
+ }
+
+ var taggers: [Tagger] = []
+ if kind == .Compiler {
+ compilableFileTag = Tag(name: "compilable.\(identifier)")
+ taggers.append(FileSpecTagger(spec: combinedIntrinsicInputPathSpec, tag: compilableFileTag!))
+ } else {
+ compilableFileTag = nil
+ }
+ self.taggers = taggers
+
+ super.init(manifest: manifest, errorSink: container)
+
+ var derivers: [Deriver] = []
+ if kind == .Compiler {
+ derivers.append(CompileFileRuleDeriver(action: self))
+ }
+ self.derivers = derivers
+
+ // Manifests
+ 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)
+ return LRManifestLayer(manifest: info as! [String: AnyObject], requiredPackageReferences: [reference], errorSink: self)
+ }
+
+ let infoDictionaries = ArrayValue(manifest["info"]) { $0 as? [String: AnyObject] } ?? []
+ manifestLayers = infoDictionaries.map { LRManifestLayer(manifest: $0, errorSink: self) } + versionInfoLayers
+
+ let packageConfigurationManifests = ArrayValue(manifest["packages"]) { ArrayValue($0) { StringValue($0) } } ?? []
+ packageConfigurations = packageConfigurationManifests.map { packagesManifest in
+ return LRAssetPackageConfiguration(manifest: ["packages": packagesManifest], errorSink: self)
+ }
+
+ if packageConfigurations.isEmpty {
+ primaryVersionSpace = nil
+ } else {
+ // wow, that's quite a chain
+ primaryVersionSpace = packageConfigurations[0].packageReferences[0].type.versionSpace
+ }
+ }
+
+ public override var description: String {
+ return "\(kind) '\(identifier)'"
+ }
+
+ public func fakeChangeDestinationNameForSourceFile(file: ProjectFile) -> String? {
+ if let fakeChangeExtension = fakeChangeExtension {
+ let relativePath = file.relativePath
+ if relativePath.pathExtension == fakeChangeExtension {
+ return nil
+ } else {
+ return relativePath.stringByDeletingPathExtension.stringByAppendingPathExtension(fakeChangeExtension)
+ }
+ } else {
+ return nil
+ }
+ }
+
+ public func newRule(contextAction contextAction: LRContextAction, memento: NSDictionary?) -> Rule {
+ return ruleType.init(contextAction: contextAction, memento: memento)
+ }
+
+}
@@ -0,0 +1,8 @@
+import Foundation
+
+@objc
+public protocol ActionContainer : NSObjectProtocol, LRManifestErrorSink {
+
+ var substitutionValues: [String: String] { get }
+
+}
@@ -0,0 +1,31 @@
+import Foundation
+import PackageManagerKit
+import ATVersionKit
+
+public class LRActionVersion: NSObject {
+
+ public var action: Action
+ public var manifest: LRActionManifest
+ public var packageSet: LRPackageSet
+
+ public init(action: Action, manifest: LRActionManifest, packageSet: LRPackageSet) {
+ self.action = action
+ self.manifest = manifest
+ self.packageSet = packageSet
+ super.init()
+
+ if packageSet.packages.isEmpty {
+ fatalError("LRActionVersion.init with an empty packageSet")
+ }
+ }
+
+ public var primaryVersion: LRVersion {
+ let packages = packageSet.packages as! [LRPackage]
+ return packages[0].version
+ }
+
+ public override var description: String {
+ return primaryVersion.description
+ }
+
+}
@@ -0,0 +1,22 @@
+import Foundation
+import ExpressiveCasting
+import PackageManagerKit
+
+public class LRAssetPackageConfiguration: LRManifestBasedObject {
+
+ public let packageReferences: [LRPackageReference]
+
+ public override init(manifest: [String: AnyObject], errorSink: LRManifestErrorSink?) {
+ let packageManager = ActionKitSingleton.sharedActionKit().packageManager
+
+ let strings = ArrayValue(manifest["packages"]) { $0 as? String } ?? []
+ packageReferences = strings.mapIf { packageManager.packageReferenceWithString($0) }
+
+ super.init(manifest: manifest, errorSink: errorSink)
+
+ if strings.isEmpty {
+ addErrorMessage("No packages defined in a package configuration")
+ }
+ }
+
+}
@@ -0,0 +1,103 @@
+import Foundation
+import ExpressiveFoundation
+import ExpressiveCollections
+import PackageManagerKit
+import Swift
+
+public class LRContextAction: NSObject {
+
+ public static let didChangeVersionsNotification = "LRContextActionDidChangeVersions"
+
+ public let action: Action
+ public let project: ProjectContext
+ public let resolutionContext: LRPackageResolutionContext
+
+ public private(set) var versions: [LRActionVersion] = []
+ public private(set) var versionSpecs: [LRVersionSpec] = []
+
+ public init(action: Action, project: ProjectContext, resolutionContext: LRPackageResolutionContext) {
+ self.action = action
+ self.project = project
+ self.resolutionContext = resolutionContext
+ super.init()
+
+ updateCoalescence.monitorBlock = { (running) in
+ project.setAnalysisInProgress(running, forTask: self)
+ }
+
+ o.on(LRPackageContainerDidChangePackageListNotification, self, LRContextAction.updateAvailableVersions)
+ updateAvailableVersions()
+ }
+
+ public override var description: String {
+ return "\(action) #ver=\(versions.count) proj=\(project)"
+ }
+
+ public func newInstance(memento memento: [String: AnyObject]) -> Rule {
+ return action.newRule(contextAction: self, memento: memento)
+ }
+
+ private func updateAvailableVersions() {
+ updateCoalescence.perform {
+ self.versions = self._computeAvailableVersions()
+ self.versionSpecs = self._computeAvailableVersionSpecs()
+ self.postNotification(LRContextAction.didChangeVersionsNotification)
+ }
+ }
+
+ private func _computeAvailableVersions() -> [LRActionVersion] {
+ if !action.valid {
+ print("ContextAction(\(action.name)) has invalid manifest, so no versions")
+ return []
+ }
+
+ let packageSets = action.packageConfigurations.map { self.resolutionContext.packageSetsMatchingPackageReferences($0.packageReferences) as! [LRPackageSet] }.flatten()
+
+ let versions = packageSets.mapIf { packageSet -> LRActionVersion? in
+ let layers = self.action.manifestLayers.filter { packageSet.matchesAllPackageReferencesInArray($0.packageReferences) }
+ let manifest = LRActionManifest(layers: layers)
+ if manifest.valid {
+ return LRActionVersion(action: self.action, manifest: manifest, packageSet: packageSet)
+ } else {
+ print("ContextAction(\(self.action.name)) skipping version \(packageSet.primaryPackage) b/c of invalid manifest: \(manifest.errors)")
+ return nil
+ }
+ }
+
+ let sortedVersions = versions.sort { (a: LRActionVersion, b: LRActionVersion) -> Bool in
+ return (a.primaryVersion.compare(b.primaryVersion) == .OrderedAscending)
+ }
+
+ return sortedVersions
+ }
+
+ private func _computeAvailableVersionSpecs() -> [LRVersionSpec] {
+ var specs: [LRVersionSpec] = []
+ var set = Set<LRVersionSpec>()
+
+ for actionVersion in versions {
+ let versionSpecs = [
+ LRVersionSpec.stableVersionSpecWithMajorFromVersion(actionVersion.primaryVersion),
+ LRVersionSpec(matchingMajorMinorFromVersion: actionVersion.primaryVersion),
+ LRVersionSpec(matchingVersion: actionVersion.primaryVersion)
+ ]
+ for spec in versionSpecs {
+ if !set.contains(spec) {
+ spec.changeLogSummary = actionVersion.manifest.changeLogSummary
+ set.insert(spec)
+ specs.append(spec)
+ }
+ }
+ }
+
+ if let primaryVersionSpace = action.primaryVersionSpace {
+ specs.append(LRVersionSpec.stableVersionSpecMatchingAnyVersionInVersionSpace(primaryVersionSpace))
+ }
+
+ return specs
+ }
+
+ private let updateCoalescence = Coalescence()
+ private var o = Observation()
+
+}
Oops, something went wrong.

0 comments on commit 86a0477

Please sign in to comment.