Skip to content

Commit

Permalink
working through PR
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 3, 2025
1 parent ee40609 commit bb134fb
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 38 deletions.
1 change: 1 addition & 0 deletions .github/workflows/PackageDSLKit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches-ignore:
- '*WIP'
pull-request:
env:
PACKAGE_NAME: PackageDSLKit
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ identifier_name:
excluded:
- DerivedData
- .build
- Compression.playground
- .temp
indentation_width:
indentation_width: 2
file_name:
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

internal struct Component: Sendable {
internal struct Component: Sendable, Hashable, Codable {
internal let name: String
internal let inheritedTypes: [String]
internal let properties: [String: Property]
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/ComponentWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import SwiftSyntax

internal struct ComponentWriter: Sendable {
internal struct ComponentWriter: Sendable, Hashable, Codable {
private let propertyWriter = PropertyWriter()
internal func node(from component: Component) -> StructDeclSyntax {
let memberBlockList = MemberBlockItemListSyntax(
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/Dependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//

public struct Dependency: TypeSource {
public struct DependencyType: OptionSet, Sendable {
public struct DependencyType: OptionSet, Sendable, Hashable, Codable {
public typealias RawValue = Int

public static let package = DependencyType(rawValue: 1)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/FileManagerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum FileManagerType: String, CaseIterable {
public enum FileManagerType: String, CaseIterable, Sendable, Hashable, Codable {
case fileManager
}
14 changes: 7 additions & 7 deletions Sources/PackageDSLKit/Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import SwiftSyntax

public struct Index {
public struct Index: Sendable, Hashable, Codable {
public let entries: [EntryRef]
public let dependencies: [DependencyRef]
public let testTargets: [TestTargetRef]
Expand All @@ -52,23 +52,23 @@ public struct Index {

extension Index {
internal init(
items: [(PackageIndexStrategy.ExpressionKind, String)],
items: [PackageIndexStrategy.Child],
modifiers: [ModifierType: [String]]
) {
var entries: [EntryRef] = []
var dependencies: [DependencyRef] = []
var testTargets: [TestTargetRef] = []
var swiftSettings: [SwiftSettingRef] = []
for item in items {
switch item.0 {
switch item.kind {
case .entries:
entries.append(.init(name: item.1))
entries.append(.init(name: item.name))
case .dependencies:
dependencies.append(.init(name: item.1))
dependencies.append(.init(name: item.name))
case .testTargets:
testTargets.append(.init(name: item.1))
testTargets.append(.init(name: item.name))
case .swiftSettings:
swiftSettings.append(.init(name: item.1))
swiftSettings.append(.init(name: item.name))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/MissingSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct MissingSource: Sendable {
public struct MissingSource: Sendable, Hashable, Codable {
public let source: Source
public let sourceType: SourceType
public let name: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/Modifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct Modifier: Sendable {
public struct Modifier: Sendable, Hashable, Codable {
public let type: ModifierType
public let code: [String]
}
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/ModifierType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum ModifierType: String, Sendable {
public enum ModifierType: String, Sendable, Hashable, Codable {
case supportedPlatforms
case defaultLocalization
}
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageDSLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum PackageDSLError: Error {
public enum PackageDSLError: Error, Sendable {
case custom(String, (any Sendable)?)
case other(any Error)
case validationFailure([MissingSource])
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageDirectoryConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct PackageDirectoryConfiguration {
public struct PackageDirectoryConfiguration: Sendable, Hashable, Codable {
public let index: Index
public let products: [Product]
public let dependencies: [Dependency]
Expand Down
12 changes: 8 additions & 4 deletions Sources/PackageDSLKit/PackageIndexStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ import SwiftSyntax
#endif

internal class PackageIndexStrategy: ParsingStrategy {
internal enum ExpressionKind: String {
internal struct Child: Sendable, Hashable, Codable {
let kind: ExpressionKind
let name: String
}
internal enum ExpressionKind: String, Sendable, Hashable, Codable {
case entries
case dependencies
case testTargets
case swiftSettings
}

private enum VisitorState: Equatable {
private enum VisitorState: Sendable, Hashable, Codable {
case root
case variable
case functionCall
Expand All @@ -52,7 +56,7 @@ internal class PackageIndexStrategy: ParsingStrategy {
case modifier(ModifierType)
}

private var items = [(ExpressionKind, String)]()
private var items = [Child]()
private var modifiers = [ModifierType: [String]]()
private var currentState: VisitorState = .root
#if canImport(os)
Expand Down Expand Up @@ -131,7 +135,7 @@ internal class PackageIndexStrategy: ParsingStrategy {
case (.functionCall, "Package"):
return .visitChildren
case (.codeBlockFor(let expressionKind), .some(let name)):
items.append((expressionKind, name))
items.append(.init(kind: expressionKind, name: name))
currentState = .labeledExpr(expressionKind)
return .visitChildren
case (_, .some(let name)):
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageIndexWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import SwiftSyntax

public struct PackageIndexWriter: Sendable {
public struct PackageIndexWriter: Sendable, Hashable, Codable {
private func labeledExpression(for name: String, items: [String]) -> LabeledExprSyntax? {
if items.isEmpty {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import Foundation
import SwiftParser

public struct PackageParser {
public struct PackageParser: Sendable, Hashable, Codable {
public init() {
}
private func parseResults(at directoryURL: URL, with fileManager: FileManager)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageSpecifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct PackageSpecifications: Sendable {
public struct PackageSpecifications: Sendable, Hashable, Codable {
public let products: [Product]
public let dependencies: [Dependency]
public let targets: [Target]
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PackageType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum PackageType: String {
public enum PackageType: String, Sendable, Hashable, Codable {
case empty
case library
case executable
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageDSLKit/ParsingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

internal enum ParsingResult {
case packageIndex([(PackageIndexStrategy.ExpressionKind, String)], [ModifierType: [String]])
internal enum ParsingResult: Sendable, Hashable, Codable {
case packageIndex([PackageIndexStrategy.Child], [ModifierType: [String]])
case structure(Component) // Add appropriate structure data
}
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/ParsingStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import SwiftSyntax
// Protocol for different parsing strategies
internal protocol ParsingStrategy {
// Return true if this strategy should handle the current context
func shouldActivate(_ node: some SyntaxProtocol, currentStrategy: ParsingStrategy?) -> Bool
func shouldActivate(_ node: some SyntaxProtocol, currentStrategy: (any ParsingStrategy)?) -> Bool

// Called when switching from this strategy to another
func finalize() -> ParsingResult?
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/ProductType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum ProductType: String, Sendable {
public enum ProductType: String, Sendable, Hashable, Codable {
case library
case executable
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct Property: Sendable {
public struct Property: Sendable, Hashable, Codable {
public let name: String
public let type: String
public let code: [String]
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/PropertyWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import SwiftSyntax

internal struct PropertyWriter: Sendable {
internal struct PropertyWriter: Sendable, Hashable, Codable {
internal func node(from property: Property) -> VariableDeclSyntax {
let codeBlocks = property.code.map(CodeBlockItemSyntax.init)
let codeBlockList = CodeBlockItemListSyntax(codeBlocks)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum Source: Sendable {
public enum Source: Sendable, Hashable, Codable {
case index
case product(String)
case target(String)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/SourceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public enum SourceType: CaseIterable, Sendable {
public enum SourceType: CaseIterable, Sendable, Hashable, Codable {
case product
case dependency
case testTarget
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/SupportedPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public struct SupportedPlatform: Sendable, Hashable {
public struct SupportedPlatform: Sendable, Hashable, Codable {
public let osName: String
public let version: Int

Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/SwiftVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import Foundation

public struct SwiftVersion: Sendable, Equatable, ExpressibleByStringLiteral, CustomStringConvertible
public struct SwiftVersion: Sendable, Hashable, ExpressibleByStringLiteral, CustomStringConvertible
{
public let major: Int
public let minor: Int
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageDSLKit/TypeReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public typealias DependencyRef = BasicTypeReference
public typealias TestTargetRef = BasicTypeReference
public typealias SwiftSettingRef = BasicTypeReference

public protocol TypeReference: Sendable {
public protocol TypeReference: Sendable, Hashable, Codable {
var name: String { get }
}

Expand All @@ -50,7 +50,7 @@ extension TypeReference {
}

extension BasicTypeReference {
public init(source: TypeSource) {
public init(source: any TypeSource) {
self.init(name: source.typeName)
}
}
2 changes: 1 addition & 1 deletion Sources/PackageDSLKit/TypeSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
// OTHER DEALINGS IN THE SOFTWARE.
//

public protocol TypeSource: Sendable {
public protocol TypeSource: Sendable, Hashable, Codable {
var typeName: String { get }
}

0 comments on commit bb134fb

Please sign in to comment.