Skip to content

Commit cc8e0ad

Browse files
authored
Emit a descriptive error when running the generator on iOS, tvOS, or watchOS (#87)
Emit a descriptive error when running the generator on iOS, tvOS, or watchOS ### Motivation Resolves #86, which some adopters are hitting by accident. ### Modifications Makes the generator itself build successfully on iOS, tvOS, watchOS, but not really, as I just added an explicit, clear error on those platforms pointing out that the adopter probably did this by accident, and how to fix it. ### Result A clear, descriptive error is now emitted when the adopter links the `_OpenAPIGeneratorCore` target from e.g. an iOS app (most likely by accident): ``` .../swift-openapi-generator/Sources/_OpenAPIGeneratorCore/PlatformChecks.swift:4:8 Running the generator tool itself is not supported on iOS, tvOS, and watchOS. Check that your app is not linking the generator directly. For details, check out: #86 ``` ### Test Plan Tested locally by creating an iOS app with a lower deployment target and linked the generator directly. The error goes away when the linkages is removed, as expected. Reviewed by: simonjbeaumont Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #87
1 parent 6d64332 commit cc8e0ad

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Package.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import PackageDescription
1717
let package = Package(
1818
name: "swift-openapi-generator",
1919
platforms: [
20-
.macOS(.v10_15)
20+
.macOS(.v10_15),
21+
22+
// The platforms below are not currently supported for running
23+
// the generator itself. We include them here to allow the generator
24+
// to emit a more descriptive compiler error.
25+
.iOS("99"), .tvOS("99"), .watchOS("99"),
2126
],
2227
products: [
2328
.executable(name: "swift-openapi-generator", targets: ["swift-openapi-generator"]),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftOpenAPIGenerator open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
// Emit a compiler error if this library is linked with a target in an adopter
16+
// project.
17+
#if !(os(macOS) || os(Linux))
18+
#error("_OpenAPIGeneratorCore is only to be used by swift-openapi-generator itself—your target should not link this library or the command line tool directly.")
19+
#endif

0 commit comments

Comments
 (0)