From 690fe66fc1c48e0d2de9c342cb950bf1c2c7f539 Mon Sep 17 00:00:00 2001 From: Jakub Skotnicki <1700160+Skoti@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:15:49 +0200 Subject: [PATCH] add PluginExample for UseAccessLevelOnImports option --- PluginExamples/Package.swift | 15 ++++++++++++++- .../AccessLevelOnImport/AccessLevelOnImport.proto | 7 +++++++ .../Dependency/Dependency.proto | 5 +++++ .../Sources/AccessLevelOnImport/empty.swift | 3 +++ .../swift-protobuf-config.json | 12 ++++++++++++ .../Sources/ExampleTests/ExampleTests.swift | 10 ++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto create mode 100644 PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto create mode 100644 PluginExamples/Sources/AccessLevelOnImport/empty.swift create mode 100644 PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json diff --git a/PluginExamples/Package.swift b/PluginExamples/Package.swift index bdae15376..e14208b98 100644 --- a/PluginExamples/Package.swift +++ b/PluginExamples/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.6 +// swift-tools-version: 5.8 import PackageDescription @@ -14,6 +14,7 @@ let package = Package( .target(name: "Simple"), .target(name: "Nested"), .target(name: "Import"), + .target(name: "AccessLevelOnImport"), ] ), .target( @@ -43,5 +44,17 @@ let package = Package( .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") ] ), + .target( + name: "AccessLevelOnImport", + dependencies: [ + .product(name: "SwiftProtobuf", package: "swift-protobuf"), + ], + swiftSettings: [ + .enableExperimentalFeature("AccessLevelOnImport"), + ], + plugins: [ + .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf") + ] + ) ] ) diff --git a/PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto b/PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto new file mode 100644 index 000000000..bc91e9cd2 --- /dev/null +++ b/PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +import "Dependency/Dependency.proto"; + +message AccessLevelOnImport { + Dependency dependency = 1; +} diff --git a/PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto b/PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto new file mode 100644 index 000000000..ce47bbf1d --- /dev/null +++ b/PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message Dependency { + string name = 1; +} diff --git a/PluginExamples/Sources/AccessLevelOnImport/empty.swift b/PluginExamples/Sources/AccessLevelOnImport/empty.swift new file mode 100644 index 000000000..d4445d2a5 --- /dev/null +++ b/PluginExamples/Sources/AccessLevelOnImport/empty.swift @@ -0,0 +1,3 @@ +/// DO NOT DELETE. +/// +/// We need to keep this file otherwise the plugin is not running. diff --git a/PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json b/PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json new file mode 100644 index 000000000..11bb943cb --- /dev/null +++ b/PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json @@ -0,0 +1,12 @@ +{ + "invocations": [ + { + "protoFiles": [ + "AccessLevelOnImport/AccessLevelOnImport.proto", + "Dependency/Dependency.proto", + ], + "visibility": "public", + "useAccessLevelOnImports": true + } + ] +} diff --git a/PluginExamples/Sources/ExampleTests/ExampleTests.swift b/PluginExamples/Sources/ExampleTests/ExampleTests.swift index ef334a389..8bd8a91ae 100644 --- a/PluginExamples/Sources/ExampleTests/ExampleTests.swift +++ b/PluginExamples/Sources/ExampleTests/ExampleTests.swift @@ -1,6 +1,7 @@ import Simple import Nested import Import +import AccessLevelOnImport import XCTest @@ -19,4 +20,13 @@ final class ExampleTests: XCTestCase { let foo = Foo.with { $0.bar = .with { $0.name = "Bar" } } XCTAssertEqual(foo.bar.name, "Bar") } + +#if compiler(>=5.9) + #if hasFeature(AccessLevelOnImport) + func testAccessLevelOnImport() { + let foo = Foo.with { $0.bar = .with { $0.name = "Bar" } } + XCTAssertEqual(foo.bar.name, "Bar") + } + #endif +#endif }