Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to proto-lens #296

Merged
merged 17 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tmp/
*.hp
*.prof
*.pyc
/hie.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been looking forward to merging just for this 😉


/test.*
/*.html
Expand Down
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Put protoc and twirp tooling in its own image
FROM golang:1.12-stretch AS protoc
FROM haskell:8.6 as haskell
RUN cabal new-update hackage.haskell.org,HEAD
RUN cabal new-install proto-lens-protoc
RUN which proto-lens-protoc

FROM golang:1.13-stretch AS protoc
RUN apt-get update && apt-get install -y unzip
ENV PROTOBUF_VERSION=3.7.1
RUN wget "https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protoc-$PROTOBUF_VERSION-linux-x86_64.zip" && \
unzip "protoc-$PROTOBUF_VERSION-linux-x86_64.zip" -d "/protobuf"

RUN go get github.com/golang/protobuf/proto && \
go get github.com/twitchtv/protogen/typemap && \
go get github.com/tclem/twirp-haskell/pkg/gen/haskell && \
go get github.com/tclem/twirp-haskell/protoc-gen-haskell
GO111MODULE=on go get github.com/tclem/proto-lens-jsonpb/protoc-gen-jsonpb_haskell@e4d10b77f57ee25beb759a33e63e2061420d3dc2

COPY --from=haskell /root/.cabal/bin/proto-lens-protoc /usr/local/bin/proto-lens-protoc

ENTRYPOINT ["/protobuf/bin/protoc", "-I/protobuf", "-I=/go/src/github.com/tclem/twirp-haskell"]
ENTRYPOINT ["/protobuf/bin/protoc", "-I/protobuf", "--plugin=protoc-gen-haskell=/usr/local/bin/proto-lens-protoc"]

# Build semantic
FROM haskell:8.6 as build
Expand Down
9 changes: 2 additions & 7 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@ jobs: $ncpus

source-repository-package
type: git
location: https://github.com/joshvera/proto3-suite.git
tag: 83f3352f0c7c94ea091e6087f60692eda9991fae

source-repository-package
type: git
location: https://github.com/joshvera/proto3-wire.git
tag: 84664e22f01beb67870368f1f88ada5d0ad01f56
location: https://github.com/tclem/proto-lens-jsonpb
tag: e4d10b77f57ee25beb759a33e63e2061420d3dc2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something we can/should push to hackage at some point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely can, I'm not sure we should just yet. Let's see if this approach works for us.

3 changes: 0 additions & 3 deletions proto/semantic.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
syntax = "proto3";

import "pkg/gen/haskell/haskell.proto";

package github.semantic;

option (haskell.haskell_package) = "Semantic.Proto";
option ruby_package = "Semantic::Proto";

message PingRequest {
Expand Down
5 changes: 3 additions & 2 deletions script/protoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export PROJECT="github.com/github/semantic"

# Generate Haskell for semantic's protobuf types
docker run --rm --user $(id -u):$(id -g) -v $(pwd):/go/src/$PROJECT -w /go/src/$PROJECT \
semantic-protoc \
--proto_path=proto --haskell_out=src/Semantic/Proto \
semantic-protoc --proto_path=proto \
--haskell_out=./src \
--jsonpb_haskell_out=./src \
semantic.proto
9 changes: 6 additions & 3 deletions semantic.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ common dependencies
, text ^>= 1.2.3.1
, these >= 0.7 && <1
, unix ^>= 2.7.2.2
, proto3-suite
, proto3-wire
, lingo >= 0.2.0.0

common executable-flags
Expand Down Expand Up @@ -241,14 +239,16 @@ library
-- High-level flow & operational functionality (logging, stats, etc.)
, Semantic.Analysis
-- API
, Proto.Semantic
, Proto.Semantic_Fields
, Proto.Semantic_JSON
, Semantic.Api
, Semantic.Api.Bridge
, Semantic.Api.Diffs
, Semantic.Api.LegacyTypes
, Semantic.Api.Symbols
, Semantic.Api.Terms
, Semantic.Api.TOCSummaries
, Semantic.Proto.SemanticPB
, Semantic.AST
, Semantic.CLI
, Semantic.Config
Expand Down Expand Up @@ -304,6 +304,9 @@ library
, prettyprinter ^>= 1.2.1
, pretty-show ^>= 1.9.5
, profunctors ^>= 5.3
, proto-lens ^>= 0.5.1.0
, proto-lens-jsonpb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Do we need a version bound on this?
  2. Should these version bounds be using ^>= to express “up to the next major version”?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon reflection we probably don’t need a version bound on proto-lens-jsonpb because we’re bringing it in with source-repository-package, but I think ^>= for proto-lens is a good idea either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We’ll eventually want to push proto-lens-jsonpb to Hackage so we can fix #16, so a version bound on both these is good to me.

, proto-lens-runtime ^>= 0.5.0.0
, reducers ^>= 3.12.3
, semantic-tags ^>= 0
, semigroupoids ^>= 5.3.2
Expand Down
8 changes: 5 additions & 3 deletions src/Data/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import Algebra.Graph.Class (connect, overlay, vertex)
import qualified Algebra.Graph.Class as Class
import qualified Algebra.Graph.ToGraph as Class
import Control.Effect.State
import Control.Lens (view)
import Data.Aeson
import qualified Data.Set as Set
import Semantic.Proto.SemanticPB
import Proto.Semantic as P
import Proto.Semantic_Fields as P

-- | An algebraic graph with 'Ord', 'Semigroup', and 'Monoid' instances.
newtype Graph vertex = Graph { unGraph :: G.Graph vertex }
Expand Down Expand Up @@ -100,8 +102,8 @@ instance Ord vertex => Ord (Graph vertex) where
class VertexTag vertex where
uniqueTag :: vertex -> Int

instance VertexTag DiffTreeVertex where uniqueTag = fromIntegral . diffVertexId
instance VertexTag TermVertex where uniqueTag = fromIntegral . vertexId
instance VertexTag DiffTreeVertex where uniqueTag = fromIntegral . view diffVertexId
instance VertexTag TermVertex where uniqueTag = fromIntegral . view vertexId

instance (Ord vertex, ToJSON vertex, VertexTag vertex) => ToJSON (Graph vertex) where
toJSON (Graph graph) = object ["vertices" .= G.vertexList graph, "edges" .= (Edge <$> G.edgeList graph)]
Expand Down
Loading