Skip to content

Commit

Permalink
🚚 Break up targets to fix unnecessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Nov 27, 2022
1 parent 87c2c87 commit 19164e5
Show file tree
Hide file tree
Showing 35 changed files with 247 additions and 109 deletions.
52 changes: 52 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/swift-geo-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WGS84Geometry"
BuildableName = "WGS84Geometry"
BlueprintName = "WGS84Geometry"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "WGS84Turf"
BuildableName = "WGS84Turf"
BlueprintName = "WGS84Turf"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TurfCore"
BuildableName = "TurfCore"
BlueprintName = "TurfCore"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down Expand Up @@ -205,6 +247,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "TurfCoreTests"
BuildableName = "TurfCoreTests"
BlueprintName = "TurfCoreTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
47 changes: 33 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import PackageDescription

#warning("TODO: Remove Turf dependency from WGS84")
let package = Package(
name: "swift-geo",
platforms: [
.macOS(.v10_15)
.macOS(.v10_15),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
// Products define the executables and libraries a package produces,
// and make them visible to other packages.
.library(name: "Geodesy", targets: ["Geodesy"]),
.library(name: "WGS84", targets: ["WGS84"]),
.library(name: "GeodeticGeometry", targets: ["GeodeticGeometry"]),
Expand All @@ -29,18 +29,29 @@ let package = Package(
),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
// Targets are the basic building blocks of a package.
// A target can define a module or a test suite.
// Targets can depend on other targets in this package,
// and on products in packages this package depends on.

// 🧰 A toolbox with a few shared protocols, shared by most targets
.target(name: "SwiftGeoToolbox"),

// 📏 Values with units (angles, lengths…)
.target(name: "ValueWithUnit", dependencies: ["SwiftGeoToolbox"]),

// 🌍 Definition of types representing geodesy concepts
.target(name: "Geodesy", dependencies: [
"ValueWithUnit",
"SwiftGeoToolbox",
]),
.target(name: "WGS84Core", dependencies: ["Geodesy"]),
.testTarget(name: "GeodesyTests", dependencies: ["Geodesy", "WGS84Core"]),

// 📽️ Representing values in different ways
.target(name: "GeodeticDisplay", dependencies: ["Geodesy"]),
.testTarget(name: "GeodeticDisplayTests", dependencies: ["GeodeticDisplay", "WGS84"]),
.testTarget(name: "GeodeticDisplayTests", dependencies: ["GeodeticDisplay", "WGS84Core"]),

// 📐 Geometric systems on geodetic types
.target(
name: "GeodeticGeometry",
dependencies: [
Expand All @@ -65,11 +76,12 @@ let package = Package(
// ]),
]
),
.testTarget(name: "GeodeticGeometryTests", dependencies: ["GeodeticGeometry", "WGS84"]),
.target(name: "WGS84", dependencies: ["GeodeticGeometry", "Turf", "WGS84Core"]),
.testTarget(name: "WGS84Tests", dependencies: ["WGS84"]),
.testTarget(name: "GeodeticGeometryTests", dependencies: ["GeodeticGeometry", "WGS84Geometry"]),

// 📐 Geometry on geodetic types
.target(name: "Turf", dependencies: ["TurfCore", "TurfMapKit"]),
.target(
name: "Turf",
name: "TurfCore",
dependencies: [
.target(name: "GeodeticGeometry"),
.product(name: "Algorithms", package: "swift-algorithms"),
Expand All @@ -90,14 +102,21 @@ let package = Package(
]
),
.testTarget(
name: "TurfTests",
name: "TurfCoreTests",
dependencies: [
"Turf",
"WGS84",
"WGS84Turf", // Unfortunately, this depends on `Turf`
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
resources: [.copy("__Snapshots__")]
),
.target(name: "TurfMapKit", dependencies: ["Turf", "WGS84"]),
.target(name: "TurfMapKit", dependencies: ["TurfCore", "WGS84Geometry"]),

// 🗺️ World Geodetic System standard
.target(name: "WGS84", dependencies: ["WGS84Core", "WGS84Geometry", "WGS84Turf"]),
.testTarget(name: "WGS84Tests", dependencies: ["WGS84"]),
.target(name: "WGS84Core", dependencies: ["Geodesy", "GeodeticDisplay"]),
.target(name: "WGS84Geometry", dependencies: ["WGS84Core", "GeodeticGeometry"]),
.target(name: "WGS84Turf", dependencies: ["WGS84Geometry", "Turf"]),
]
)
10 changes: 10 additions & 0 deletions Sources/Turf/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Exports.swift
// SwiftGeo
//
// Created by Rémi Bardon on 22/11/2022.
// Copyright © 2022 Rémi Bardon. All rights reserved.
//

@_exported import TurfCore
@_exported import TurfMapKit
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions Sources/TurfMapKit/Turf+MapKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#if canImport(MapKit)
import MapKit
import Turf
import WGS84
import TurfCore
import WGS84Geometry

//public func mkBBox(for points: [WGS842D.Point]) -> MKMapRect {
// return WGS842D.bbox(forCollection: points)?.mkMapRect ?? .world
Expand All @@ -18,12 +18,12 @@ import WGS84
//public func mkBBox(for coords: [CLLocationCoordinate2D]) -> MKMapRect {
// return mkBBox(for: coords.map(Point2D.init))
//}

public func clCenter(for points: [WGS842D.Point]) -> CLLocationCoordinate2D? {
return WGS842D.center(forCollection: points)?.clLocationCoordinate2D
}

public func clCenter(for coords: [CLLocationCoordinate2D]) -> CLLocationCoordinate2D? {
return clCenter(for: coords.map(WGS842D.Point.init))
}
//
//public func clCenter(for points: [WGS842D.Point]) -> CLLocationCoordinate2D? {
// return WGS842D.center(forCollection: points)?.clLocationCoordinate2D
//}
//
//public func clCenter(for coords: [CLLocationCoordinate2D]) -> CLLocationCoordinate2D? {
// return clCenter(for: coords.map(WGS842D.Point.init))
//}
#endif
2 changes: 2 additions & 0 deletions Sources/WGS84/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
//

@_exported import WGS84Core
@_exported import WGS84Geometry
@_exported import WGS84Turf
54 changes: 0 additions & 54 deletions Sources/WGS84/Interoperability/WGS84+CoreLocation.swift

This file was deleted.

40 changes: 40 additions & 0 deletions Sources/WGS84Core/Interoperability/WSG84Core+CoreLocation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// WSG84Core+CoreLocation.swift
// SwiftGeo
//
// Created by Rémi Bardon on 02/02/2022.
// Copyright © 2022 Rémi Bardon. All rights reserved.
//

#if canImport(CoreLocation)
import CoreLocation

extension Coordinate2D {

public var clLocation: CLLocation {
CLLocation(
latitude: self.latitude.decimalDegrees,
longitude: self.longitude.decimalDegrees
)
}

public var clLocationCoordinate2D: CLLocationCoordinate2D {
CLLocationCoordinate2D(
latitude: self.latitude.decimalDegrees,
longitude: self.longitude.decimalDegrees
)
}

public init(_ location: CLLocation) {
self.init(location.coordinate)
}

public init(_ coordinate: CLLocationCoordinate2D) {
self.init(
latitude: .init(decimalDegrees: coordinate.latitude),
longitude: .init(decimalDegrees: coordinate.longitude)
)
}

}
#endif
20 changes: 20 additions & 0 deletions Sources/WGS84Core/Interoperability/WSG84Core+MapKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// WSG84Core+MapKit.swift
// SwiftGeo
//
// Created by Rémi Bardon on 02/02/2022.
// Copyright © 2022 Rémi Bardon. All rights reserved.
//

// `MapKit` depends on `CoreLocation`, no need to check
#if canImport(MapKit)
import MapKit

public extension Coordinate2D {

var mkMapPoint: MKMapPoint {
MKMapPoint(self.clLocationCoordinate2D)
}

}
#endif
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//
// Display.swift
// WGS84+Display.swift
// SwiftGeo
//
// Created by Rémi Bardon on 24/08/2021.
// Copyright © 2021 Rémi Bardon. All rights reserved.
//

#if canImport(GeodeticDisplay)
import GeodeticDisplay

extension Coordinate2D: GeographicNotation {
Expand Down Expand Up @@ -55,4 +54,3 @@ extension Coordinate3D: GeographicNotation {
}

}
#endif
9 changes: 9 additions & 0 deletions Sources/WGS84Geometry/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Exports.swift
// SwiftGeo
//
// Created by Rémi Bardon on 27/11/2022.
// Copyright © 2022 Rémi Bardon. All rights reserved.
//

@_exported import WGS84Core
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// WGS84Geometry+CoreLocation.swift
// SwiftGeo
//
// Created by Rémi Bardon on 02/02/2022.
// Copyright © 2022 Rémi Bardon. All rights reserved.
//

#if canImport(CoreLocation)
import CoreLocation

public extension Point2D {

var clLocation: CLLocation {
self.coordinates.clLocation
}

var clLocationCoordinate2D: CLLocationCoordinate2D {
self.coordinates.clLocationCoordinate2D
}

init(_ location: CLLocation) {
self.init(coordinates: .init(location))
}

init(_ coordinate: CLLocationCoordinate2D) {
self.init(coordinates: .init(coordinate))
}

}
#endif
Loading

0 comments on commit 19164e5

Please sign in to comment.