Skip to content

Commit

Permalink
Revert #331 and remove methodOptions.
Browse files Browse the repository at this point in the history
We're not using it currently.  Also, the existing approach
doesn't work well with our internal Blaze rules.  If we still
want this long-term, we can revisit it after fixing #334.
  • Loading branch information
judah committed Oct 15, 2019
1 parent ffa97af commit d1def49
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 67 deletions.
1 change: 0 additions & 1 deletion proto-lens-protoc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
### Breaking Changes
- Reexport transitive definitions from modules generated for `.proto` files
with `import public` statements (#329).
- Add `methodOptions` to `HasMethodImpl` to provide custom method options.
- Bump lower bounds to base-4.10 (ghc-8.2).
- Use `ghc-source-gen` instead of `haskell-src-exts`. Removes
`Data.ProtoLens.Compiler.Combinators` and adds
Expand Down
4 changes: 2 additions & 2 deletions proto-lens-protoc/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ extra-source-files:
- Changelog.md

dependencies:
- base >= 4.10 && < 4.14
- bytestring == 0.10.*
- base >= 4.9 && < 4.14
- containers >= 0.5 && < 0.7
- lens-family >= 1.2 && < 2.1
- proto-lens == 0.5.*
Expand All @@ -44,4 +43,5 @@ executables:
source-dirs: app
dependencies:
- ghc-paths == 0.1.*
- bytestring == 0.10.*
- proto-lens-protoc
3 changes: 0 additions & 3 deletions proto-lens-protoc/src/Data/ProtoLens/Compiler/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import Proto.Google.Protobuf.Descriptor
, FieldDescriptorProto'Type(..)
, FileDescriptorProto
, MethodDescriptorProto
, MethodOptions
, ServiceDescriptorProto
)
import GHC.SourceGen
Expand Down Expand Up @@ -137,7 +136,6 @@ data MethodInfo = MethodInfo
, methodOutput :: Text
, methodClientStreaming :: Bool
, methodServerStreaming :: Bool
, methodOptions :: MethodOptions
}

-- | Information about a single field of a proto message,
Expand Down Expand Up @@ -330,7 +328,6 @@ collectServices fd = fmap (toServiceInfo $ fd ^. #package) $ fd ^. #service
, methodOutput = fromString . T.unpack $ md ^. #outputType
, methodClientStreaming = md ^. #clientStreaming
, methodServerStreaming = md ^. #serverStreaming
, methodOptions = md ^. #options
}

messageAndEnumDefs ::
Expand Down
8 changes: 0 additions & 8 deletions proto-lens-protoc/src/Data/ProtoLens/Compiler/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Data.ProtoLens.Compiler.Generate(


import Control.Arrow (second)
import qualified Data.ByteString.Char8 as B
import qualified Data.Foldable as F
import qualified Data.List as List
import qualified Data.Map as Map
Expand All @@ -27,7 +26,6 @@ import Data.Maybe (isJust)
import Data.Semigroup ((<>))
#endif
import Data.Ord (comparing)
import Data.ProtoLens (encodeMessage)
import qualified Data.Set as Set
import Data.String (fromString)
import Data.Text (unpack)
Expand Down Expand Up @@ -247,12 +245,6 @@ generateServiceDecls env si =
(True, False) -> "Data.ProtoLens.Service.Types.ClientStreaming"
(False, True) -> "Data.ProtoLens.Service.Types.ServerStreaming"
(True, True) -> "Data.ProtoLens.Service.Types.BiDiStreaming"
-- methodOptions _ _ = decodeMessageOrDie (pack "...")
-- (where "..." is the encoded version of the proto message).
, funBind "methodOptions" $ match [wildP, wildP]
$ var "Data.ProtoLens.decodeMessageOrDie"
@@ (var "Data.ByteString.Char8.pack"
@@ string (B.unpack $ encodeMessage $ methodOptions m))
]
| m <- serviceMethods si
, let instanceHead = stringTy (T.unpack $ methodIdent m)
Expand Down
4 changes: 0 additions & 4 deletions proto-lens-tests/tests/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ service TestService {
rpc ClientStreaming (stream Foo) returns (Bar);
rpc ServerStreaming (Foo) returns (stream Bar);
rpc BiDiStreaming (stream Foo) returns (stream Bar);
// Test that we pass method options through the API:
rpc Deprecated (Foo) returns (Bar) {
option deprecated = true;
}
}

58 changes: 16 additions & 42 deletions proto-lens-tests/tests/service_test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,112 +6,86 @@

module Main (main) where

import Control.Exception (evaluate)
import Control.Monad (void)
import Data.ProtoLens (defMessage)
import Data.Proxy (Proxy (..))
import Lens.Family2 (set)
import Test.Tasty (testGroup, TestTree)
import Test.Tasty.HUnit (testCase)
import Test.HUnit ((@=?))
import Proto.Service
import Data.ProtoLens.Service.Types
import Data.ProtoLens.TestUtil (testMain)
import Proto.Google.Protobuf.Descriptor_Fields (deprecated)


-- This module will fail to compile due to @-fwarn-overlapping-patterns@ and
-- @-Werror@ if any of the constraints on the definitions below is incorrect.
main :: IO ()
main = testMain
[ testCase "module compiles" $ do
-- Use these variables in a monomorphic context to verify that
-- their contexts are all correct.
void $ evaluate serviceMetadataTest
void $ evaluate normalMethodMetadataTest
void $ evaluate clientStreamingMethodMetadataTest
void $ evaluate serverStreamingMethodMetadataTest
void $ evaluate bidiStreamingMethodMetadataTest
void $ evaluate revMessagesMetadataTest
, testMethodOption
[ testCase "module compiles" $ return ()
]


serviceMetadataTest
_serviceMetadataTest
:: ( s ~ TestService
, Service s
, ServicePackage s ~ "test.service"
-- proto-lens generates this list in alphabetical order.
, ServiceMethods s ~ '[ "biDiStreaming"
, "clientStreaming"
, "deprecated"
, "normal"
, "revMessages"
, "serverStreaming"
]
) => Proxy m
serviceMetadataTest = Proxy
_serviceMetadataTest = Proxy


normalMethodMetadataTest
_normalMethodMetadataTest
:: ( s ~ TestService
, m ~ "normal"
, HasMethod s m
, MethodInput s m ~ Foo
, MethodOutput s m ~ Bar
, MethodStreamingType s m ~ 'NonStreaming
) => Proxy m
normalMethodMetadataTest = Proxy
_normalMethodMetadataTest = Proxy


clientStreamingMethodMetadataTest
_clientStreamingMethodMetadataTest
:: ( s ~ TestService
, m ~ "clientStreaming"
, HasMethod s m
, MethodInput s m ~ Foo
, MethodOutput s m ~ Bar
, MethodStreamingType s m ~ 'ClientStreaming
) => Proxy m
clientStreamingMethodMetadataTest = Proxy
_clientStreamingMethodMetadataTest = Proxy


serverStreamingMethodMetadataTest
_serverStreamingMethodMetadataTest
:: ( s ~ TestService
, m ~ "serverStreaming"
, HasMethod s m
, MethodInput s m ~ Foo
, MethodOutput s m ~ Bar
, MethodStreamingType s m ~ 'ServerStreaming
) => Proxy m
serverStreamingMethodMetadataTest = Proxy
_serverStreamingMethodMetadataTest = Proxy


bidiStreamingMethodMetadataTest
_bidiStreamingMethodMetadataTest
:: ( s ~ TestService
, m ~ "biDiStreaming"
, m ~ "bidiStreaming"
, HasMethod s m
, MethodInput s m ~ Foo
, MethodOutput s m ~ Bar
, MethodStreamingType s m ~ 'BiDiStreaming
) => Proxy m
bidiStreamingMethodMetadataTest = Proxy
_bidiStreamingMethodMetadataTest = Proxy


revMessagesMetadataTest
_revMessagesMetadataTest
:: ( s ~ TestService
, m ~ "revMessages"
, HasMethod s m
, MethodInput s m ~ Bar
, MethodOutput s m ~ Foo
, MethodStreamingType s m ~ 'NonStreaming
) => Proxy m
revMessagesMetadataTest = Proxy

testMethodOption :: TestTree
testMethodOption = testGroup "methodOption"
[ testCase "default" $
defMessage
@=? methodOptions TestService (Proxy :: Proxy "normal")
, testCase "deprecated" $
set deprecated True defMessage
@=? methodOptions TestService (Proxy :: Proxy "deprecated")
]

_revMessagesMetadataTest = Proxy
1 change: 0 additions & 1 deletion proto-lens/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Pending

### Breaking Changes
- Add `methodOptions` to `HasMethodImpl` to provide custom method options.
- Bump lower bounds to base-4.10 (ghc-8.2).

### Backwards-Compatible Changes
Expand Down
3 changes: 0 additions & 3 deletions proto-lens/src/Data/ProtoLens/Service/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ module Data.ProtoLens.Service.Types

import Data.Kind (Constraint)
import Data.ProtoLens.Message (Message)
import {-# SOURCE #-} Proto.Google.Protobuf.Descriptor (MethodOptions)
import GHC.TypeLits
import Data.Proxy (Proxy)


-- | Reifies the fact that there is a 'HasMethod' instance for every symbol
Expand Down Expand Up @@ -87,7 +85,6 @@ class ( KnownSymbol m
type MethodInput s m :: *
type MethodOutput s m :: *
type MethodStreamingType s m :: StreamingType
methodOptions :: s -> Proxy m -> MethodOptions


-- | Helper constraint that expands to a user-friendly error message when 'm'
Expand Down
3 changes: 0 additions & 3 deletions proto-lens/src/Proto/Google/Protobuf/Descriptor.hs-boot

This file was deleted.

0 comments on commit d1def49

Please sign in to comment.