ソースを参照

Move the PackageManager-based echo example to Sources/ and add it as a target to the main Package.swift.

Daniel Alm 7 年 前
コミット
128571a155

+ 3 - 3
.gitignore

@@ -10,8 +10,8 @@ Plugin/Sources/protoc-gen-swiftgrpc/templates.swift
 Plugin/protoc-*
 Plugin/protoc-*
 Plugin/swiftgrpc.log
 Plugin/swiftgrpc.log
 Plugin/echo.*.swift
 Plugin/echo.*.swift
-Examples/Echo/PackageManager/Echo
-Examples/Echo/PackageManager/test.out
-Examples/Echo/PackageManager/echo.pid
+Echo
+test.out
+echo.pid
 SwiftGRPC.xcodeproj
 SwiftGRPC.xcodeproj
 Package.resolved
 Package.resolved

+ 0 - 35
Examples/Echo/PackageManager/Package.swift

@@ -1,35 +0,0 @@
-// swift-tools-version:4.0
-
-/*
- * Copyright 2017, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import PackageDescription
-
-let package = Package(
-  name: "Echo",
-  dependencies: [
-    .package(url: "../../..", .branch("HEAD")),
-    .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.2"),
-    .package(url: "https://github.com/kylef/Commander.git", from: "0.8.0")
-  ],
-  targets: [
-    .target(name: "Echo",
-            dependencies: [
-              "SwiftGRPC",
-              "SwiftProtobuf",
-              "Commander"
-            ],
-	    path: "Sources")
-  ])

+ 0 - 1
Examples/Echo/PackageManager/Sources/EchoProvider.swift

@@ -1 +0,0 @@
-../../EchoProvider.swift

+ 0 - 1
Examples/Echo/PackageManager/Sources/echo.grpc.swift

@@ -1 +0,0 @@
-../../Generated/echo.grpc.swift

+ 0 - 1
Examples/Echo/PackageManager/Sources/echo.pb.swift

@@ -1 +0,0 @@
-../../Generated/echo.pb.swift

+ 0 - 0
Examples/Echo/Xcode/Echo.xcodeproj/project.pbxproj → Examples/EchoXcode/Echo.xcodeproj/project.pbxproj


+ 0 - 0
Examples/Echo/Xcode/Echo/AppDelegate.swift → Examples/EchoXcode/Echo/AppDelegate.swift


+ 0 - 0
Examples/Echo/Xcode/Echo/Assets.xcassets/AppIcon.appiconset/Contents.json → Examples/EchoXcode/Echo/Assets.xcassets/AppIcon.appiconset/Contents.json


+ 0 - 0
Examples/Echo/Xcode/Echo/Base.lproj/MainMenu.xib → Examples/EchoXcode/Echo/Base.lproj/MainMenu.xib


+ 0 - 0
Examples/Echo/Xcode/Echo/EchoViewController.swift → Examples/EchoXcode/Echo/EchoViewController.swift


+ 0 - 0
Examples/Echo/Xcode/Echo/Info.plist → Examples/EchoXcode/Echo/Info.plist


+ 0 - 0
Examples/Echo/Xcode/Echo/ssl.crt → Examples/EchoXcode/Echo/ssl.crt


+ 0 - 0
Examples/Echo/Xcode/Echo/ssl.key → Examples/EchoXcode/Echo/ssl.key


+ 1 - 1
Examples/Echo/Xcode/README.md → Examples/EchoXcode/README.md

@@ -1,6 +1,6 @@
 # Echo gRPC Sample App
 # Echo gRPC Sample App
 
 
-The Echo Xcode project contains a Mac app that can be used to 
+The Echo Xcode project contains a Mac app that can be used to
 instantiate and run local gRPC clients and servers. It depends
 instantiate and run local gRPC clients and servers. It depends
 on the gRPC Xcode project, which requires a local build of the
 on the gRPC Xcode project, which requires a local build of the
 gRPC Core C library. To build that, please run "make" in the
 gRPC Core C library. To build that, please run "make" in the

+ 10 - 0
Makefile

@@ -12,6 +12,16 @@ project:
 test:	all
 test:	all
 	swift test -v $(CFLAGS)
 	swift test -v $(CFLAGS)
 
 
+test-echo:	all
+	cp .build/debug/Echo .
+	./Echo serve & /bin/echo $$! > echo.pid
+	./Echo get | tee test.out
+	./Echo expand | tee -a test.out
+	./Echo collect | tee -a test.out
+	./Echo update | tee -a test.out
+	kill -9 `cat echo.pid`
+	diff -u test.out Sources/EchoExample/test.gold
+
 test-examples:
 test-examples:
 	cd Examples/Echo/PackageManager; make test
 	cd Examples/Echo/PackageManager; make test
 	cd Examples/Simple/PackageManager; make
 	cd Examples/Simple/PackageManager; make

+ 9 - 1
Package.swift

@@ -24,7 +24,8 @@ let package = Package(
   ],
   ],
   dependencies: [
   dependencies: [
     .package(url: "https://github.com/Zewo/zlib.git", from: "0.4.0"),
     .package(url: "https://github.com/Zewo/zlib.git", from: "0.4.0"),
-    .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.2")
+    .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.2"),
+    .package(url: "https://github.com/kylef/Commander.git", from: "0.8.0")
   ],
   ],
   targets: [
   targets: [
     .target(name: "SwiftGRPC",
     .target(name: "SwiftGRPC",
@@ -38,5 +39,12 @@ let package = Package(
               "SwiftProtobufPluginLibrary",
               "SwiftProtobufPluginLibrary",
               "protoc-gen-swift"]),
               "protoc-gen-swift"]),
     .target(name: "BoringSSL"),
     .target(name: "BoringSSL"),
+    .target(name: "Echo",
+            dependencies: [
+              "SwiftGRPC",
+              "SwiftProtobuf",
+              "Commander"
+            ],
+            path: "Sources/EchoExample"),
     .testTarget(name: "SwiftGRPCTests", dependencies: ["SwiftGRPC"])
     .testTarget(name: "SwiftGRPCTests", dependencies: ["SwiftGRPC"])
   ])
   ])

+ 0 - 0
Examples/Echo/EchoProvider.swift → Sources/EchoExample/EchoProvider.swift


+ 0 - 1
Examples/Echo/Generated/echo.grpc.swift → Sources/EchoExample/Generated/echo.grpc.swift

@@ -289,4 +289,3 @@ internal final class Echo_EchoServer: ServiceServer {
     }
     }
   }
   }
 }
 }
-

+ 0 - 0
Examples/Echo/Generated/echo.pb.swift → Sources/EchoExample/Generated/echo.pb.swift


+ 1 - 1
Examples/Echo/PackageManager/Makefile → Sources/EchoExample/Makefile

@@ -11,7 +11,7 @@ test:	all
 	./Echo update | tee -a test.out
 	./Echo update | tee -a test.out
 	kill -9 `cat echo.pid`
 	kill -9 `cat echo.pid`
 	diff -u test.out test.gold
 	diff -u test.out test.gold
-	
+
 project:
 project:
 	swift package generate-xcodeproj
 	swift package generate-xcodeproj
 
 

+ 2 - 2
Examples/Echo/README.md → Sources/EchoExample/README.md

@@ -1,10 +1,10 @@
 # Echo, a gRPC Sample App
 # Echo, a gRPC Sample App
 
 
 This directory contains a simple echo server and client
 This directory contains a simple echo server and client
-that demonstrates all four gRPC API styles (Unary, Server 
+that demonstrates all four gRPC API styles (Unary, Server
 Streaming, Client Streaming, and Bidirectional Streaming).
 Streaming, Client Streaming, and Bidirectional Streaming).
 
 
-The [Xcode](Xcode) directory contains a Mac app and 
+The [Xcode](Xcode) directory contains a Mac app and
 [PackageManager](PackageManager) contains a command-line tool
 [PackageManager](PackageManager) contains a command-line tool
 that can be built with the Swift Package Manager. Both contain
 that can be built with the Swift Package Manager. Both contain
 a Swift client and server.
 a Swift client and server.

+ 0 - 0
Examples/Echo/RUNME → Sources/EchoExample/RUNME


+ 4 - 4
Examples/Echo/echo.proto → Sources/EchoExample/echo.proto

@@ -19,13 +19,13 @@ package echo;
 service Echo {
 service Echo {
   // Immediately returns an echo of a request.
   // Immediately returns an echo of a request.
   rpc Get(EchoRequest) returns (EchoResponse) {}
   rpc Get(EchoRequest) returns (EchoResponse) {}
-  
+
   // Splits a request into words and returns each word in a stream of messages.
   // Splits a request into words and returns each word in a stream of messages.
-  rpc Expand(EchoRequest) returns (stream EchoResponse) {}  
-  
+  rpc Expand(EchoRequest) returns (stream EchoResponse) {}
+
   // Collects a stream of messages and returns them concatenated when the caller closes.
   // Collects a stream of messages and returns them concatenated when the caller closes.
   rpc Collect(stream EchoRequest) returns (EchoResponse) {}
   rpc Collect(stream EchoRequest) returns (EchoResponse) {}
-  
+
   // Streams back messages as they are received in an input stream.
   // Streams back messages as they are received in an input stream.
   rpc Update(stream EchoRequest) returns (stream EchoResponse) {}
   rpc Update(stream EchoRequest) returns (stream EchoResponse) {}
 }
 }

+ 4 - 4
Examples/Echo/PackageManager/Sources/main.swift → Sources/EchoExample/main.swift

@@ -141,7 +141,7 @@ Group {
       requestMessage.text = part
       requestMessage.text = part
       print("collect sending: " + part)
       print("collect sending: " + part)
       try collectCall.send(requestMessage) { error in
       try collectCall.send(requestMessage) { error in
-        if let error = error {	
+        if let error = error {
           print("collect send error \(error)")
           print("collect send error \(error)")
         }
         }
       }
       }
@@ -172,15 +172,15 @@ Group {
       requestMessage.text = part
       requestMessage.text = part
       print("update sending: " + requestMessage.text)
       print("update sending: " + requestMessage.text)
       try updateCall.send(requestMessage) { error in
       try updateCall.send(requestMessage) { error in
-        if let error = error {	
+        if let error = error {
           print("update send error \(error)")
           print("update send error \(error)")
         }
         }
       }
       }
     }
     }
     updateCall.waitForSendOperationsToFinish()
     updateCall.waitForSendOperationsToFinish()
-    
+
     try updateCall.closeSend()
     try updateCall.closeSend()
-    
+
     while true {
     while true {
       do {
       do {
         let responseMessage = try updateCall.receive()
         let responseMessage = try updateCall.receive()

+ 0 - 0
Examples/Echo/PackageManager/ssl.crt → Sources/EchoExample/ssl.crt


+ 0 - 0
Examples/Echo/PackageManager/ssl.key → Sources/EchoExample/ssl.key


+ 0 - 0
Examples/Echo/PackageManager/test.gold → Sources/EchoExample/test.gold


+ 1 - 1
Tests/SwiftGRPCTests/EchoProvider.swift

@@ -1 +1 @@
-../../Examples/Echo/EchoProvider.swift
+../../Sources/EchoExample/EchoProvider.swift

+ 1 - 1
Tests/SwiftGRPCTests/echo.grpc.swift

@@ -1 +1 @@
-../../Examples/Echo/Generated/echo.grpc.swift
+../../Sources/EchoExample/Generated/echo.grpc.swift

+ 1 - 1
Tests/SwiftGRPCTests/echo.pb.swift

@@ -1 +1 @@
-../../Examples/Echo/Generated/echo.pb.swift
+../../Sources/EchoExample/Generated/echo.pb.swift