From 5952642cf8b3bdfef01d0c22832d91669e88206e Mon Sep 17 00:00:00 2001 From: John Carey Date: Thu, 7 Jul 2022 15:56:49 -0700 Subject: [PATCH 1/5] Support proto3-suite 0.5.0 and later. Starting with proto3-suite 0.5.0, the initial character of a service method names is no longer forced to uppercase. --- src/Network/GRPC/MQTT/TH/Proto.hs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Network/GRPC/MQTT/TH/Proto.hs b/src/Network/GRPC/MQTT/TH/Proto.hs index c0f44c5..6357add 100644 --- a/src/Network/GRPC/MQTT/TH/Proto.hs +++ b/src/Network/GRPC/MQTT/TH/Proto.hs @@ -1,6 +1,7 @@ --- Copyright (c) 2021 Arista Networks, Inc. +-- Copyright (c) 2021-2022 Arista Networks, Inc. -- Use of this source code is governed by the Apache License 2.0 -- that can be found in the COPYING file. +{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TemplateHaskell #-} @@ -44,12 +45,17 @@ import Proto3.Suite.DotProto.Internal dpIdentUnqualName, importProto, invalidMethodNameError, - prefixedFieldName, protoPackageName, typeLikeName, ) import Turtle (FilePath, directory, filename) +#if MIN_VERSION_proto3_suite(0,5,0) +import Proto3.Suite.DotProto.Internal (prefixedMethodName) +#else +import Proto3.Suite.DotProto.Internal (prefixedFieldName) +#endif + ------------------------------------------------------------------------------- -- | Proto option to enable/disable batching in streams @@ -103,7 +109,13 @@ forEachService protoFilepath defBatchedStream action = showErrors . runExceptT $ (NonStreaming, NonStreaming) -> [e|wrapUnaryClientHandler|] (Streaming, NonStreaming) -> [e|wrapClientStreamingClientHandler|] (Streaming, Streaming) -> [e|wrapBiDiStreamingClientHandler useBatchedStream|] - clientFun <- prefixedFieldName serviceName nm + clientFun <- +#if MIN_VERSION_proto3_suite(0,5,0) + prefixedMethodName +#else + prefixedFieldName +#endif + serviceName nm return [(endpointPrefix <> nm, useBatchedStream, streamingWrapper, mkName clientFun)] _ -> invalidMethodNameError rpcMethodName serviceMethodName _ = pure [] From c346d5762b1cf8a3463a012eb77fcd1c98289b6a Mon Sep 17 00:00:00 2001 From: John Carey Date: Fri, 8 Jul 2022 09:23:29 -0700 Subject: [PATCH 2/5] Replace the other uses of prefixedFieldName. --- grpc-mqtt.cabal | 1 + src/Network/GRPC/MQTT/TH/Client.hs | 4 ++-- src/Network/GRPC/MQTT/TH/Proto.hs | 16 ++------------ src/Network/GRPC/MQTT/TH/RemoteClient.hs | 6 ++--- src/Proto3/Suite/DotProto/Internal/Compat.hs | 23 ++++++++++++++++++++ 5 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 src/Proto3/Suite/DotProto/Internal/Compat.hs diff --git a/grpc-mqtt.cabal b/grpc-mqtt.cabal index 01504c3..decb663 100644 --- a/grpc-mqtt.cabal +++ b/grpc-mqtt.cabal @@ -95,6 +95,7 @@ library Network.GRPC.MQTT.Message.Packet.Core Network.GRPC.MQTT.Message.Request.Core Proto.Mqtt + Proto3.Suite.DotProto.Internal.Compat Proto3.Wire.Decode.Extra Proto3.Wire.Encode.Extra Proto3.Wire.Types.Extra diff --git a/src/Network/GRPC/MQTT/TH/Client.hs b/src/Network/GRPC/MQTT/TH/Client.hs index ec41c73..89036b7 100644 --- a/src/Network/GRPC/MQTT/TH/Client.hs +++ b/src/Network/GRPC/MQTT/TH/Client.hs @@ -40,7 +40,7 @@ import Network.GRPC.MQTT.Types MQTTResult, ) import Network.MQTT.Topic (Topic) -import Proto3.Suite.DotProto.Internal (prefixedFieldName) +import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName) import Turtle (FilePath) -------------------------------------------------------------------------------- @@ -48,7 +48,7 @@ import Turtle (FilePath) mqttClientFuncs :: Turtle.FilePath -> Batched -> Q [Dec] mqttClientFuncs fp defaultBatchedStream = fmap concat $ forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do - clientFuncName <- mkName <$> prefixedFieldName serviceName "mqttClient" + clientFuncName <- mkName <$> prefixedMethodName serviceName "mqttClient" lift $ clientService clientFuncName (mkName serviceName) [(a, batched) | (a, batched, _, _) <- serviceMethods] clientService :: Name -> Name -> [(String, Batched)] -> DecsQ diff --git a/src/Network/GRPC/MQTT/TH/Proto.hs b/src/Network/GRPC/MQTT/TH/Proto.hs index 6357add..0ee147a 100644 --- a/src/Network/GRPC/MQTT/TH/Proto.hs +++ b/src/Network/GRPC/MQTT/TH/Proto.hs @@ -1,7 +1,6 @@ -- Copyright (c) 2021-2022 Arista Networks, Inc. -- Use of this source code is governed by the Apache License 2.0 -- that can be found in the COPYING file. -{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TemplateHaskell #-} @@ -48,14 +47,9 @@ import Proto3.Suite.DotProto.Internal protoPackageName, typeLikeName, ) +import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName) import Turtle (FilePath, directory, filename) -#if MIN_VERSION_proto3_suite(0,5,0) -import Proto3.Suite.DotProto.Internal (prefixedMethodName) -#else -import Proto3.Suite.DotProto.Internal (prefixedFieldName) -#endif - ------------------------------------------------------------------------------- -- | Proto option to enable/disable batching in streams @@ -109,13 +103,7 @@ forEachService protoFilepath defBatchedStream action = showErrors . runExceptT $ (NonStreaming, NonStreaming) -> [e|wrapUnaryClientHandler|] (Streaming, NonStreaming) -> [e|wrapClientStreamingClientHandler|] (Streaming, Streaming) -> [e|wrapBiDiStreamingClientHandler useBatchedStream|] - clientFun <- -#if MIN_VERSION_proto3_suite(0,5,0) - prefixedMethodName -#else - prefixedFieldName -#endif - serviceName nm + clientFun <- prefixedMethodName serviceName nm return [(endpointPrefix <> nm, useBatchedStream, streamingWrapper, mkName clientFun)] _ -> invalidMethodNameError rpcMethodName serviceMethodName _ = pure [] diff --git a/src/Network/GRPC/MQTT/TH/RemoteClient.hs b/src/Network/GRPC/MQTT/TH/RemoteClient.hs index 49a9b4c..a6acee4 100644 --- a/src/Network/GRPC/MQTT/TH/RemoteClient.hs +++ b/src/Network/GRPC/MQTT/TH/RemoteClient.hs @@ -35,7 +35,7 @@ import Language.Haskell.TH import Network.GRPC.HighLevel.Client (Client) import Network.GRPC.MQTT.Types (Batched (Batched, Unbatched), MethodMap) import Network.GRPC.MQTT.Wrapping (wrapServerStreamingClientHandler, wrapUnaryClientHandler) -import Proto3.Suite.DotProto.Internal (prefixedFieldName) +import Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName) import Turtle (FilePath) -------------------------------------------------------------------------------- @@ -43,8 +43,8 @@ import Turtle (FilePath) mqttRemoteClientMethodMap :: Turtle.FilePath -> Batched -> Q [Dec] mqttRemoteClientMethodMap fp defaultBatchedStream = fmap concat $ forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do - clientFuncName <- mkName <$> prefixedFieldName serviceName "remoteClientMethodMap" - grpcClientName <- mkName <$> prefixedFieldName serviceName "client" + clientFuncName <- mkName <$> prefixedMethodName serviceName "remoteClientMethodMap" + grpcClientName <- mkName <$> prefixedMethodName serviceName "client" lift $ rcMethodMap clientFuncName grpcClientName serviceMethods rcMethodMap :: Name -> Name -> [(String, Batched, ExpQ, Name)] -> DecsQ diff --git a/src/Proto3/Suite/DotProto/Internal/Compat.hs b/src/Proto3/Suite/DotProto/Internal/Compat.hs new file mode 100644 index 0000000..a458d79 --- /dev/null +++ b/src/Proto3/Suite/DotProto/Internal/Compat.hs @@ -0,0 +1,23 @@ +-- Copyright (c) 2022 Arista Networks, Inc. +-- Use of this source code is governed by the Apache License 2.0 +-- that can be found in the COPYING file. +{-# LANGUAGE CPP #-} + +-- | For versions of @proto3-suite@ starting with 0.5.0, merely +-- reexports `Proto3.Suite.DotProto.Internal.prefixedMethodName)`, +-- but for earlier versions emulates that function by defining it as +-- an alias of `Proto3.Suite.DotProto.Internal.prefixedFieldName`. +module Proto3.Suite.DotProto.Internal.Compat (prefixedMethodName) where + +#if MIN_VERSION_proto3_suite(0,5,0) + +import Proto3.Suite.DotProto.Internal (prefixedMethodName) + +#else + +import Proto3.Suite.DotProto.Internal (prefixedFieldName) + +prefixedMethodName :: MonadError CompileError m => String -> String -> m String +prefixedMethodName = prefixedFieldName + +#endif From 1bf8c6aff8fa23be6c2a60ffbf2ab57f7366d7bd Mon Sep 17 00:00:00 2001 From: John Carey Date: Fri, 8 Jul 2022 09:27:30 -0700 Subject: [PATCH 3/5] Update copyright date ranges. --- grpc-mqtt.cabal | 2 +- src/Network/GRPC/MQTT/TH/Client.hs | 2 +- src/Network/GRPC/MQTT/TH/RemoteClient.hs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grpc-mqtt.cabal b/grpc-mqtt.cabal index decb663..67e5ce9 100644 --- a/grpc-mqtt.cabal +++ b/grpc-mqtt.cabal @@ -7,7 +7,7 @@ synopsis: Run gRPC services over an MQTT connection license: Apache-2.0 author: Arista Networks maintainer: opensource@awakesecurity.com -copyright: 2021 Arista Networks +copyright: 2021-2022 Arista Networks category: Network build-type: Simple diff --git a/src/Network/GRPC/MQTT/TH/Client.hs b/src/Network/GRPC/MQTT/TH/Client.hs index 89036b7..8839ab4 100644 --- a/src/Network/GRPC/MQTT/TH/Client.hs +++ b/src/Network/GRPC/MQTT/TH/Client.hs @@ -1,4 +1,4 @@ --- Copyright (c) 2021 Arista Networks, Inc. +-- Copyright (c) 2021-2022 Arista Networks, Inc. -- Use of this source code is governed by the Apache License 2.0 -- that can be found in the COPYING file. {-# LANGUAGE TemplateHaskell #-} diff --git a/src/Network/GRPC/MQTT/TH/RemoteClient.hs b/src/Network/GRPC/MQTT/TH/RemoteClient.hs index a6acee4..46c27cb 100644 --- a/src/Network/GRPC/MQTT/TH/RemoteClient.hs +++ b/src/Network/GRPC/MQTT/TH/RemoteClient.hs @@ -1,4 +1,4 @@ --- Copyright (c) 2021 Arista Networks, Inc. +-- Copyright (c) 2021-2022 Arista Networks, Inc. -- Use of this source code is governed by the Apache License 2.0 -- that can be found in the COPYING file. {-# LANGUAGE TemplateHaskell #-} From e6d40f36a611b80122df0d1f869b44e6c3fae072 Mon Sep 17 00:00:00 2001 From: j6carey Date: Fri, 8 Jul 2022 11:48:47 -0700 Subject: [PATCH 4/5] Update src/Proto3/Suite/DotProto/Internal/Compat.hs Co-authored-by: Matt Friede --- src/Proto3/Suite/DotProto/Internal/Compat.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Proto3/Suite/DotProto/Internal/Compat.hs b/src/Proto3/Suite/DotProto/Internal/Compat.hs index a458d79..76cbe81 100644 --- a/src/Proto3/Suite/DotProto/Internal/Compat.hs +++ b/src/Proto3/Suite/DotProto/Internal/Compat.hs @@ -15,7 +15,9 @@ import Proto3.Suite.DotProto.Internal (prefixedMethodName) #else -import Proto3.Suite.DotProto.Internal (prefixedFieldName) +import Control.Monad.Except (MonadError) +import Proto3.Suite.DotProto.Internal (CompileError, prefixedFieldName) +import Relude (String) prefixedMethodName :: MonadError CompileError m => String -> String -> m String prefixedMethodName = prefixedFieldName From ab569abb53db78f2a4c724bed6b29ba1eeacaef3 Mon Sep 17 00:00:00 2001 From: John Carey Date: Fri, 8 Jul 2022 13:33:21 -0700 Subject: [PATCH 5/5] Capitalize "MqttClient", "RemoteClientMethodMap", and "Client" so that when they are incorporated Haskell names they retain the same capitalization whe built with proto3-suite-0.5.0 as they did with earlier bersions of proto3-suite. --- src/Network/GRPC/MQTT/TH/Client.hs | 2 +- src/Network/GRPC/MQTT/TH/RemoteClient.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Network/GRPC/MQTT/TH/Client.hs b/src/Network/GRPC/MQTT/TH/Client.hs index 8839ab4..2cb1b7e 100644 --- a/src/Network/GRPC/MQTT/TH/Client.hs +++ b/src/Network/GRPC/MQTT/TH/Client.hs @@ -48,7 +48,7 @@ import Turtle (FilePath) mqttClientFuncs :: Turtle.FilePath -> Batched -> Q [Dec] mqttClientFuncs fp defaultBatchedStream = fmap concat $ forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do - clientFuncName <- mkName <$> prefixedMethodName serviceName "mqttClient" + clientFuncName <- mkName <$> prefixedMethodName serviceName "MqttClient" lift $ clientService clientFuncName (mkName serviceName) [(a, batched) | (a, batched, _, _) <- serviceMethods] clientService :: Name -> Name -> [(String, Batched)] -> DecsQ diff --git a/src/Network/GRPC/MQTT/TH/RemoteClient.hs b/src/Network/GRPC/MQTT/TH/RemoteClient.hs index 46c27cb..222615e 100644 --- a/src/Network/GRPC/MQTT/TH/RemoteClient.hs +++ b/src/Network/GRPC/MQTT/TH/RemoteClient.hs @@ -43,8 +43,8 @@ import Turtle (FilePath) mqttRemoteClientMethodMap :: Turtle.FilePath -> Batched -> Q [Dec] mqttRemoteClientMethodMap fp defaultBatchedStream = fmap concat $ forEachService fp defaultBatchedStream $ \serviceName serviceMethods -> do - clientFuncName <- mkName <$> prefixedMethodName serviceName "remoteClientMethodMap" - grpcClientName <- mkName <$> prefixedMethodName serviceName "client" + clientFuncName <- mkName <$> prefixedMethodName serviceName "RemoteClientMethodMap" + grpcClientName <- mkName <$> prefixedMethodName serviceName "Client" lift $ rcMethodMap clientFuncName grpcClientName serviceMethods rcMethodMap :: Name -> Name -> [(String, Batched, ExpQ, Name)] -> DecsQ