diff --git a/Package.swift b/Package.swift index 2d56544..b2e8b59 100644 --- a/Package.swift +++ b/Package.swift @@ -2,6 +2,18 @@ import PackageDescription +extension Year { + static var year2015: Year { Year("2015") } + static var year2016: Year { Year("2016") } + static var year2018: Year { Year("2018") } + static var year2019: Year { Year("2019") } + static var year2020: Year { Year("2020") } + static var year2021: Year { Year("2021") } + static var year2022: Year { Year("2022") } + static var year2023: Year { Year("2023") } + static var year2024: Year { Year("2024") } +} + let package = Package( name: "Advent of Code", platforms: [ @@ -10,15 +22,15 @@ let package = Package( ], products: [ .library(name: "Advent", targets: ["Advent"]), - .library(name: "Year2015", targets: ["Year2015"]), - .library(name: "Year2016", targets: ["Year2016"]), - .library(name: "Year2018", targets: ["Year2018"]), - .library(name: "Year2019", targets: ["Year2019"]), - .library(name: "Year2020", targets: ["Year2020"]), - .library(name: "Year2021", targets: ["Year2021"]), - .library(name: "Year2022", targets: ["Year2022"]), - .library(name: "Year2023", targets: ["Year2023"]), - .library(name: "Year2024", targets: ["Year2024"]), + .library(.year2015), + .library(.year2016), + .library(.year2018), + .library(.year2019), + .library(.year2020), + .library(.year2021), + .library(.year2022), + .library(.year2023), + .library(.year2024), .executable(name: "aoc", targets: ["AdventTool"]), .executable(name: "intcode", targets: ["IntcodeComputer tool"]), ], @@ -71,79 +83,23 @@ let package = Package( // MARK: - Year2015 - .target( - name: "Year2015", - dependencies: ["Advent"], - path: "Year2015/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2015Tests", - dependencies: ["Advent", "Year2015"], - path: "Year2015/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2015), + .testTarget(.year2015), // MARK: - Year2016 - .target( - name: "Year2016", - dependencies: ["Advent"], - path: "Year2016/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2016Tests", - dependencies: ["Advent", "Year2016"], - path: "Year2016/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2016), + .testTarget(.year2016), // MARK: - Year2018 - .target( - name: "Year2018", - dependencies: ["Advent"], - path: "Year2018/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2018Tests", - dependencies: ["Advent", "Year2018"], - path: "Year2018/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2018), + .testTarget(.year2018), // MARK: - Year2019 - .target( - name: "Year2019", - dependencies: ["Advent"], - path: "Year2019/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2019Tests", - dependencies: ["Advent", "Year2019"], - path: "Year2019/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2019), + .testTarget(.year2019), .executableTarget( name: "IntcodeComputer tool", @@ -159,99 +115,79 @@ let package = Package( // MARK: - Year2020 - .target( - name: "Year2020", - dependencies: ["Advent"], - path: "Year2020/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2020Tests", - dependencies: ["Advent", "Year2020"], - path: "Year2020/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2020), + .testTarget(.year2020), // MARK: - Year2021 - .target( - name: "Year2021", - dependencies: ["Advent"], - path: "Year2021/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2021Tests", - dependencies: ["Advent", "Year2019", "Year2021"], - path: "Year2021/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2021), + .testTarget(.year2021, dependencies: ["Year2019"]), // MARK: - Year2022 - .target( - name: "Year2022", - dependencies: ["Advent"], - path: "Year2022/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2022Tests", - dependencies: ["Advent", "Year2022"], - path: "Year2022/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2022), + .testTarget(.year2022), // MARK: - Year2023 - .target( - name: "Year2023", - dependencies: ["Advent"], - path: "Year2023/Sources", - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - .testTarget( - name: "Year2023Tests", - dependencies: ["Advent", "Year2023"], - path: "Year2023/Tests", - resources: [.copy("Inputs")], - swiftSettings: [ - .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + .target(.year2023), + .testTarget(.year2023), // MARK: - Year2024 - .target( - name: "Year2024", - dependencies: ["Advent"], - path: "Year2024/Sources", + .target(.year2024), + .testTarget(.year2024), + ], + swiftLanguageVersions: [.v5] +) + +struct Year { + let name: String + init(_ year: String) { + name = "Year\(year)" + } +} + +extension Product { + static func library(_ year: Year) -> Product { + library(name: year.name, targets: [year.name]) + } +} + +extension Target { + static func target(_ year: Year) -> Target { + target( + name: year.name, + dependencies: [ + "Advent", + .product(name: "Algorithms", package: "swift-algorithms"), + .product(name: "Crypto", package: "swift-crypto"), + ], + path: "\(year.name)/Sources", swiftSettings: [ .unsafeFlags(["-enable-bare-slash-regex"]), - ]), + ] + ) + } - .testTarget( - name: "Year2024Tests", - dependencies: ["Advent", "Year2024"], - path: "Year2024/Tests", - resources: [.copy("Inputs")], + static func testTarget( + _ year: Year, + dependencies: [Target.Dependency] = [] + ) -> Target { + testTarget( + name: "\(year.name)Tests", + dependencies: [ + "Advent", + .byName(name: year.name), + .product(name: "Algorithms", package: "swift-algorithms"), + .product(name: "Crypto", package: "swift-crypto"), + ] + dependencies, + path: "\(year.name)/Tests", + resources: [ + .copy("Inputs"), + ], swiftSettings: [ .unsafeFlags(["-enable-bare-slash-regex"]), - ]), - - ], - swiftLanguageVersions: [.v5] -) + ]) + } +}