Prechádzať zdrojové kódy

Default `UseAccessLevelOnImports` to `false` (#2047)

## Motivation

After the discussion on
https://github.com/grpc/grpc-swift/pull/2042#discussion_r1746796122, I
played a bit more with `InternalImportsByDefault` and the different
generator options, got to the following conclusions:

- If you add `import Foo` to some file, where `Foo` is also being
imported with an explicit `internal` access-level modifier _in the
generated code_, it will work as long as `InternalImportsByDefault` is
enabled.
- If you disable `InternalImportsByDefault` for the corresponding target
in `Package.swift`, you get an `"Ambiguous implicit access level for
import of 'Foo'; it is imported as 'internal' elsewhere"` **error** (not
a warning). This means that if the code generator plugin(s) begin adding
the access level modifiers by default based on how they're built, they
could cause source-breakages for users unintentionally.
- _This isn't any different between language mode 5 or 6_ - I tried
changing the target's language mode and the behaviour is the same as
described above in either case.

Given all this, defaulting `UseAccessLevelOnImports` to `false`
**always** for now may be the easiest (and least surprising, from a
users' perspective) thing to do, until `InternalImportsByDefault` are
enabled by default in a future Swift >6.0 version (as the proposal
states), where we can default to `true` again:
```
#if compiler(>=6.x) // where x is the version where internal imports by default is enabled
// default to true
#else
// default to false
#endif
```

The rationale behind this is that adding access levels to imports on
your code is currently totally optional. If you choose to start adding
them explicitly, then it's okay to also have to tell your
tooling/generators that they should also add them explicitly. If you
don't, they'll keep generating things the exact same way they've been
doing it, which is what users of the generator would expect.

## Modifications
- Default `UseAccessLevelOnImports` to `false` always.
- Regenerate protos
- Remove `InternalImportsByDefault` from test and executable targets,
since it doesn't make a lot of sense to have access level modifiers on
imports here anyways as these targets cannot be imported.
Gus Cairo 1 rok pred
rodič
commit
2cc5aae7a0

+ 1 - 1
Tests/GRPCHTTP2TransportTests/ControlService.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-internal import GRPCCore
+import GRPCCore
 
 import struct Foundation.Data
 

+ 2 - 2
Tests/GRPCHTTP2TransportTests/Generated/control.grpc.swift

@@ -22,8 +22,8 @@
 // For information on using the generated types, please see the documentation:
 //   https://github.com/grpc/grpc-swift
 
-internal import GRPCCore
-internal import GRPCProtobuf
+import GRPCCore
+import GRPCProtobuf
 
 internal enum Control {
     internal static let descriptor = GRPCCore.ServiceDescriptor.Control

+ 5 - 5
Tests/GRPCHTTP2TransportTests/HTTP2TransportNIOPosixTests.swift

@@ -14,13 +14,13 @@
  * limitations under the License.
  */
 
-private import GRPCCore
-private import GRPCHTTP2Core
-private import GRPCHTTP2TransportNIOPosix
-internal import XCTest
+import GRPCCore
+import GRPCHTTP2Core
+import GRPCHTTP2TransportNIOPosix
+import XCTest
 
 #if canImport(NIOSSL)
-private import NIOSSL
+import NIOSSL
 #endif
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)

+ 4 - 4
Tests/GRPCHTTP2TransportTests/HTTP2TransportNIOTransportServicesTests.swift

@@ -15,10 +15,10 @@
  */
 
 #if canImport(Network)
-private import GRPCCore
-private import GRPCHTTP2Core
-internal import GRPCHTTP2TransportNIOTransportServices
-internal import XCTest
+import GRPCCore
+import GRPCHTTP2Core
+import GRPCHTTP2TransportNIOTransportServices
+import XCTest
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 final class HTTP2TransportNIOTransportServicesTests: XCTestCase {

+ 6 - 6
Tests/GRPCHTTP2TransportTests/HTTP2TransportTests.swift

@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-internal import GRPCCore
-private import GRPCHTTP2Core
-private import GRPCHTTP2TransportNIOPosix
-private import GRPCHTTP2TransportNIOTransportServices
-private import GRPCProtobuf
-internal import XCTest
+import GRPCCore
+import GRPCHTTP2Core
+import GRPCHTTP2TransportNIOPosix
+import GRPCHTTP2TransportNIOTransportServices
+import GRPCProtobuf
+import XCTest
 
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 final class HTTP2TransportTests: XCTestCase {

+ 5 - 5
Tests/GRPCHTTP2TransportTests/Test Utilities/HTTP2StatusCodeServer.swift

@@ -14,11 +14,11 @@
  * limitations under the License.
  */
 
-internal import GRPCHTTP2Core
-private import NIOCore
-private import NIOHPACK
-private import NIOHTTP2
-private import NIOPosix
+import GRPCHTTP2Core
+import NIOCore
+import NIOHPACK
+import NIOHTTP2
+import NIOPosix
 
 /// An HTTP/2 test server which only responds to request headers by sending response headers and
 /// then closing. Each stream will be closed with the ":status" set to the value of the

+ 1 - 1
Tests/GRPCHTTP2TransportTests/Test Utilities/XCTest+Utilities.swift

@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-private import XCTest
+import XCTest
 
 func XCTAssertThrowsError<T, E: Error>(
   ofType: E.Type,

+ 2 - 2
Tests/GRPCHTTP2TransportTests/XCTestCase+Vsock.swift

@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-private import NIOPosix
-internal import XCTest
+import NIOPosix
+import XCTest
 
 extension XCTestCase {
   func vsockAvailable() -> Bool {