@@ -1,20 +1,4 @@
1−-- | Entry point for the code-generating executable `protoc` plugin. See the
2−-- | package README for instructions on how to run the code generator.
3−-- |
4−-- | The funny thing about writing a `protoc` compiler plugin codec is that it
5−-- | bootstraps itself. We just have to write enough of the compiler plugin codec
6−-- | that it can handle the `plugin.proto` and `descriptor.proto` files, and
7−-- | then we call the compiler plugin on these `.proto` files and the compiler
8−-- | plugin codec generates the rest of itself.
9−-- |
10−-- | Then we can delete the hand-written code and generate code to replace it
11−-- | with this command.
12−-- |
13−-- | protoc --purescript_out=./src/ProtocPlugin google/protobuf/compiler/plugin.proto
14−-- |
15−-- | See
16−-- | * https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin.pb
17−-- | * https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor.pb
1+-- | Entry point for the conformance test runner.
182module Conformance.Main (main) where
193
204import Prelude
@@ -25,15 +9,13 @@ import Control.Monad.Writer (tell)
259import Data.ArrayBuffer.Builder (execPut, subBuilder, putInt32le)
2610import Data.ArrayBuffer.Builder as Builder
2711import Data.ArrayBuffer.DataView as DV
28−import Data.ArrayBuffer.Types (ArrayBuffer)
2912import Data.Either (Either(..))
30−import Data.Generic.Rep.Show (genericShow)
3113import Data.Maybe (Maybe(..))
3214import Effect (Effect)
3315import Node.Buffer (toArrayBuffer, fromArrayBuffer)
3416import Node.Encoding (Encoding(..))
3517import Node.Process (stdin, stdout, stderr, exit)
36−import Node.Stream (onFinish, onReadable, read, write, writeString)
18+import Node.Stream (onReadable, read, write, writeString)
3719import ProtobufTestMessages.Proto3.TestMessagesProto3 as T3
3820import Text.Parsing.Parser (runParserT)
3921import Text.Parsing.Parser.DataView (anyInt32le)
@@ -42,7 +24,6 @@ bailOutMaybe :: forall a. String -> Effect (Maybe a) -> Effect a
4224bailOutMaybe err thing =
4325 thing >>= case _ of
4426 Nothing -> do
45− -- writeString stderr UTF8 err (void $ exit 1)
4627 void $ writeString stderr UTF8 err (pure unit)
4728 exit 1
4829 Just x -> pure x
@@ -58,28 +39,11 @@ bailOutEither thing = thing >>= case _ of
5839-- https://github.com/protocolbuffers/protobuf/blob/master/conformance/conformance_test_runner.cc
5940main :: Effect Unit
6041main = do
61− -- void $ writeString stderr UTF8 "Beginning Conformance Check" (pure unit)
6242 onReadable stdin $ do
63− -- void $ writeString stderr UTF8 "stdin readable" (pure unit)
64− -- msglenbuf <- bailOutMaybe "No message length" $ read stdin (Just 4)
65− -- msglendv <- DV.whole <$> toArrayBuffer msglenbuf
6643 msglendv <- map DV.whole $ toArrayBuffer =<< (bailOutMaybe "No message length" $ read stdin (Just 4))
6744 msglen <- bailOutEither $ runParserT msglendv $ anyInt32le
68− -- void $ writeString stderr UTF8 (show msglen) (pure unit)
69−
7045 stdinview <- map DV.whole $ toArrayBuffer =<< (bailOutMaybe "No stdin" $ read stdin (Just msglen))
71− -- stdinbufMay <- read stdin Nothing
72− -- case stdinbufMay of
73− -- Nothing -> pure unit
74− -- Just stdinbuf -> do
7546 request <- bailOutEither $ runParserT stdinview $ parseConformanceRequest $ DV.byteLength stdinview
76−
77− -- case requestParsed of
78− -- Left err -> void $ writeString stderr UTF8 (show err) (pure unit)
79− -- Right request -> do
80− -- Uncomment this line to write the parsed declarations to stderr.
81− -- void $ writeString stderr UTF8 (show request) (pure unit)
82−
8347 response <- reply request
8448
8549 case response of
@@ -97,7 +61,7 @@ main = do
9761reply :: ConformanceRequest -> Effect ConformanceResponse
9862reply (ConformanceRequest
9963 { requested_output_format: Just C.WireFormat_PROTOBUF
100− , message_type: Just "protobuf_test_messages.proto3.TestAllTypesProto3" -- :: Maybe.Maybe String
64+ , message_type: Just "protobuf_test_messages.proto3.TestAllTypesProto3"
10165 , test_category: _ -- :: Maybe.Maybe TestCategory
10266 , jspb_encoding_options: _ -- :: Maybe.Maybe JspbEncodingConfig
10367 , print_unknown_fields: _ -- :: Maybe.Maybe Boolean
@@ -117,13 +81,12 @@ reply (ConformanceRequest
11781 }
11882reply (ConformanceRequest
11983 { requested_output_format: _ -- :: Maybe.Maybe WireFormat
120− , message_type: Just "protobuf_test_messages.proto2.TestAllTypesProto2" -- :: Maybe.Maybe String
84+ , message_type: Just "protobuf_test_messages.proto2.TestAllTypesProto2"
12185 , test_category: _ -- :: Maybe.Maybe TestCategory
12286 , jspb_encoding_options: _ -- :: Maybe.Maybe JspbEncodingConfig
12387 , print_unknown_fields: _ -- :: Maybe.Maybe Boolean
12488 , payload: _ -- Just (C.ConformanceRequest_Payload_Protobuf_payload arraybuffer)
12589 }) = pure $ ConformanceResponse
126− -- { result: Just $ ConformanceResponse_Result_Runtime_error $ "runtime " <> message_type
12790 { result: Just $ ConformanceResponse_Result_Skipped "Skipped proto2"
12891 }
12992