Skip to content

Commit 99fe00a

Browse files
authored
Update swift-log/swift-protobuf and support trait-disabled builds (#58)
1 parent a2a6770 commit 99fe00a

13 files changed

Lines changed: 170 additions & 12 deletions

‎Package.resolved‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ let package = Package(
4040
],
4141
dependencies: [
4242
.package(url: "https://github.com/Outdooractive/gis-tools", exact: "3.0.0-beta.1"),
43+
// NOTE: The gis-tools-* format packages below pin gis-tools to exactly 3.0.0-beta.1,
44+
// so gis-tools cannot be bumped until matching format package releases exist.
4345
.package(url: "https://github.com/Outdooractive/gis-tools-csv", exact: "3.0.0-beta.1"),
4446
.package(url: "https://github.com/Outdooractive/gis-tools-geopackage", exact: "3.0.0-beta.1"),
4547
.package(url: "https://github.com/Outdooractive/gis-tools-gpx", exact: "3.0.0-beta.1"),
4648
.package(url: "https://github.com/Outdooractive/gis-tools-fit", exact: "3.0.0-beta.1"),
4749
.package(url: "https://github.com/Outdooractive/gis-tools-shapefile", exact: "3.0.0-beta.1"),
4850
.package(url: "https://github.com/1024jp/GzipSwift.git", from: "7.0.0"),
4951
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.8.2"),
50-
.package(url: "https://github.com/apple/swift-log.git", from: "1.14.0"),
51-
.package(url: "https://github.com/apple/swift-protobuf", from: "1.38.1"),
52+
.package(url: "https://github.com/apple/swift-log.git", from: "1.16.2"),
53+
.package(url: "https://github.com/apple/swift-protobuf", from: "1.39.0"),
5254
],
5355
targets: [
5456
.executableTarget(

‎Sources/MVTCLI/TileFormat.swift‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ extension TileFormat {
101101
logger: logger)
102102

103103
case .mlt(let x, let y, let z):
104+
#if EnableMLT
104105
return try VectorTile(
105106
contentsOfMLT: url,
106107
x: x, y: y, z: z,
107108
layerAllowlist: layerAllowlist,
108109
logger: logger)
110+
#else
111+
throw unavailableError
112+
#endif
109113

110114
case .geoJson(let defaultLayerProperty):
111115
return try VectorTile(
@@ -115,37 +119,57 @@ extension TileFormat {
115119
logger: logger)
116120

117121
case .fit:
122+
#if EnableFIT
118123
return try VectorTile(
119124
contentsOfFIT: url,
120125
layerProperty: layerProperty,
121126
layerAllowlist: layerAllowlist,
122127
logger: logger)
128+
#else
129+
throw unavailableError
130+
#endif
123131

124132
case .gpx:
133+
#if EnableGPX
125134
return try VectorTile(
126135
contentsOfGPX: url,
127136
layerProperty: layerProperty,
128137
layerAllowlist: layerAllowlist,
129138
logger: logger)
139+
#else
140+
throw unavailableError
141+
#endif
130142

131143
case .csv:
144+
#if EnableCSV
132145
return try VectorTile(
133146
contentsOfCSV: url,
134147
readOptions: csvReadOptions,
135148
layerProperty: layerProperty,
136149
layerAllowlist: layerAllowlist,
137150
logger: logger)
151+
#else
152+
throw unavailableError
153+
#endif
138154

139155
case .shapefile:
156+
#if EnableShapefile
140157
return try VectorTile(
141158
shapefile: url,
142159
logger: logger)
160+
#else
161+
throw unavailableError
162+
#endif
143163

144164
case .geopackage:
165+
#if EnableGeoPackage
145166
return try await VectorTile(
146167
geopackage: url,
147168
table: geopackageTable,
148169
logger: logger)
170+
#else
171+
throw unavailableError
172+
#endif
149173
}
150174
}
151175

@@ -193,6 +217,24 @@ extension TileFormat {
193217

194218
}
195219

220+
// MARK: - Build availability
221+
222+
extension TileFormat {
223+
224+
/// The error thrown when the receiver's format is not compiled into this build.
225+
///
226+
/// Optional formats are gated behind package traits (see `Package.swift`).
227+
/// A format may still be recognized on the command line — e.g. via its file
228+
/// extension or `--output-format` — even though its coder was left out of
229+
/// the build; reading or writing it then fails with this error.
230+
var unavailableError: CLIError {
231+
CLIError(
232+
"Format '\(self)' is not available in this build "
233+
+ "(enable the corresponding package trait)")
234+
}
235+
236+
}
237+
196238
// MARK: - CustomStringConvertible
197239

198240
extension TileFormat: CustomStringConvertible {

‎Sources/MVTCLI/WriteTile.swift‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,52 @@ extension CLI {
4242
tile.writeMVT(to: url, options: options)
4343

4444
case .mlt:
45+
#if EnableMLT
4546
tile.writeMLT(to: url, options: options)
47+
#else
48+
throw format.unavailableError
49+
#endif
4650

4751
case .fit:
52+
#if EnableFIT
4853
guard tile.writeFIT(to: url, options: options) else {
4954
throw CLIError("Failed to write FIT")
5055
}
56+
#else
57+
throw format.unavailableError
58+
#endif
5159

5260
case .gpx:
61+
#if EnableGPX
5362
guard tile.writeGPX(to: url, options: options) else {
5463
throw CLIError("Failed to write GPX")
5564
}
65+
#else
66+
throw format.unavailableError
67+
#endif
5668

5769
case .csv:
70+
#if EnableCSV
5871
guard tile.writeCSV(to: url, writeOptions: csvWriteOptions, options: options) else {
5972
throw CLIError("Failed to write CSV")
6073
}
74+
#else
75+
throw format.unavailableError
76+
#endif
6177

6278
case .shapefile:
79+
#if EnableShapefile
6380
try tile.writeShapefile(to: url, options: options)
81+
#else
82+
throw format.unavailableError
83+
#endif
6484

6585
case .geopackage:
86+
#if EnableGeoPackage
6687
try await tile.writeGeoPackage(to: url, options: options)
88+
#else
89+
throw format.unavailableError
90+
#endif
6791
}
6892
}
6993

‎Tests/MVTCLITests/DumpCommandTests.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,50 @@ struct DumpCommandTests {
2121
#expect(output.contains("FeatureCollection"))
2222
}
2323

24+
#if EnableGPX
2425
@Test(.timeLimit(.minutes(1)))
2526
func dumpGpx() throws {
2627
let path = try generateSmallGpx().path
2728
let output = try runCLI(args: ["dump", path])
2829
#expect(output.contains("FeatureCollection"))
2930
}
31+
#endif
3032

33+
#if EnableFIT
3134
@Test(.timeLimit(.minutes(1)))
3235
func dumpFit() throws {
3336
let path = try generateSmallFit().path
3437
let output = try runCLI(args: ["dump", path])
3538
#expect(output.contains("FeatureCollection"))
3639
}
40+
#endif
3741

42+
#if EnableShapefile
3843
@Test(.timeLimit(.minutes(1)))
3944
func dumpShapefile() throws {
4045
let path = try generateSmallShapefile().path
4146
let output = try runCLI(args: ["dump", path])
4247
#expect(output.contains("FeatureCollection"))
4348
}
49+
#endif
4450

51+
#if EnableGeoPackage
4552
@Test(.timeLimit(.minutes(1)))
4653
func dumpGeoPackage() async throws {
4754
let path = try await generateSmallGeoPackage().path
4855
let output = try runCLI(args: ["dump", path])
4956
#expect(output.contains("FeatureCollection"))
5057
}
58+
#endif
5159

60+
#if EnableMLT
5261
@Test(.timeLimit(.minutes(1)))
5362
func dumpMlt() throws {
5463
let path = try generateSmallMlt().path
5564
let output = try runCLI(args: ["dump", "-x", "0", "-y", "0", "-z", "0", path])
5665
#expect(output.contains("FeatureCollection"))
5766
}
67+
#endif
5868

5969
// MARK: Parameters
6070

@@ -102,6 +112,7 @@ struct DumpCommandTests {
102112

103113
// MARK: CSV options
104114

115+
#if EnableCSV
105116
@Test(.timeLimit(.minutes(1)))
106117
func dumpCsvWithTreatAsLineString() throws {
107118
let path = try generateSmallCsv().path
@@ -114,5 +125,6 @@ struct DumpCommandTests {
114125
#expect(plainOutput.contains(#""type" : "Point""#))
115126
#expect(!plainOutput.contains(#""type" : "LineString""#))
116127
}
128+
#endif
117129

118130
}

‎Tests/MVTCLITests/ExportCommandTests.swift‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ExportCommandTests {
2424
#expect(!fc.features.isEmpty)
2525
}
2626

27+
#if EnableGPX
2728
@Test(.timeLimit(.minutes(1)))
2829
func exportGpxToGeoJson() throws {
2930
let path = try generateSmallGpx().path
@@ -33,7 +34,9 @@ struct ExportCommandTests {
3334
let fc = try assertGeoJsonFile(at: outUrl)
3435
#expect(!fc.features.isEmpty)
3536
}
37+
#endif
3638

39+
#if EnableCSV
3740
@Test(.timeLimit(.minutes(1)))
3841
func exportCsvToGeoJson() throws {
3942
let path = try generateSmallCsv().path
@@ -43,7 +46,9 @@ struct ExportCommandTests {
4346
let fc = try assertGeoJsonFile(at: outUrl)
4447
#expect(!fc.features.isEmpty)
4548
}
49+
#endif
4650

51+
#if EnableShapefile
4752
@Test(.timeLimit(.minutes(1)))
4853
func exportShapefileToGeoJson() throws {
4954
let path = try generateSmallShapefile().path
@@ -53,7 +58,9 @@ struct ExportCommandTests {
5358
let fc = try assertGeoJsonFile(at: outUrl)
5459
#expect(!fc.features.isEmpty)
5560
}
61+
#endif
5662

63+
#if EnableGeoPackage
5764
@Test(.timeLimit(.minutes(1)))
5865
func exportGeoPackageToGeoJson() async throws {
5966
let path = try await generateSmallGeoPackage().path
@@ -63,7 +70,9 @@ struct ExportCommandTests {
6370
let fc = try assertGeoJsonFile(at: outUrl)
6471
#expect(!fc.features.isEmpty)
6572
}
73+
#endif
6674

75+
#if EnableMLT
6776
@Test(.timeLimit(.minutes(1)))
6877
func exportMltToGeoJson() throws {
6978
let path = try generateSmallMlt().path
@@ -73,6 +82,7 @@ struct ExportCommandTests {
7382
let fc = try assertGeoJsonFile(at: outUrl)
7483
#expect(!fc.features.isEmpty)
7584
}
85+
#endif
7686

7787
@Test(.timeLimit(.minutes(1)))
7888
func exportWithCompression() throws {

0 commit comments

Comments
 (0)