Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 7b44a6a

Browse files
committed
Repeatable code gen from proto
1 parent 40a8e6d commit 7b44a6a

File tree

13 files changed

+48
-125
lines changed

13 files changed

+48
-125
lines changed

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Put protoc and twirp tooling in it's own image
2+
FROM golang:1.12-stretch AS protoc
3+
RUN apt-get update && apt-get install -y unzip
4+
ENV PROTOBUF_VERSION=3.7.1
5+
RUN wget "https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protoc-$PROTOBUF_VERSION-linux-x86_64.zip" && \
6+
unzip "protoc-$PROTOBUF_VERSION-linux-x86_64.zip" -d "/protobuf"
7+
8+
RUN go get github.com/golang/protobuf/proto && \
9+
go get github.com/twitchtv/protogen/typemap && \
10+
go get github.com/tclem/twirp-haskell/pkg/gen/haskell && \
11+
go get github.com/tclem/twirp-haskell/protoc-gen-haskell
12+
13+
ENTRYPOINT ["/protobuf/bin/protoc", "-I/protobuf", "-I=/go/src/github.com/tclem/twirp-haskell"]
14+
15+
# Build semantic
116
FROM haskell:8.6 as build
217
WORKDIR /build
318

proto/semantic/api/v1/code_analysis.proto renamed to proto/semantic.proto

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
11
syntax = "proto3";
22

3-
package semantic.api.v1;
3+
import "pkg/gen/haskell/haskell.proto";
44

5-
option java_package = "com.github.semantic.api.v1";
5+
package github.semantic;
66

7-
// Semantic's CodeAnalysis service provides endpoints for parsing, analyzing,
8-
// and comparing source code.
9-
service CodeAnalysis {
10-
// Check health & status of the service.
11-
rpc Ping (PingRequest) returns (PingResponse);
12-
// Calculate c-tags like symbols for blobs.
13-
rpc ParseTreeSymbols (ParseTreeRequest) returns (ParseTreeSymbolResponse);
14-
// Parse trees in adjacency graph representation.
15-
rpc ParseTreeGraph (ParseTreeRequest) returns (ParseTreeGraphResponse);
16-
// Calculate table of contents style diff summaries.
17-
rpc DiffTreeTOC (DiffTreeRequest) returns (DiffTreeTOCResponse);
18-
// Tree diffs in adjacency graph representation.
19-
rpc DiffTreeGraph (DiffTreeRequest) returns (DiffTreeGraphResponse);
20-
}
21-
22-
message PingRequest {
23-
string service = 1;
24-
}
25-
26-
message PingResponse {
27-
string status = 1;
28-
string hostname = 2;
29-
string timestamp = 3;
30-
string sha = 4;
31-
}
7+
option (haskell.haskell_package) = "Semantic.Proto";
8+
option ruby_package = "Semantic::Proto";
329

3310
message ParseTreeRequest {
3411
repeated Blob blobs = 1;

script/protoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: script/protoc
3+
#/
4+
#/ Generate code from .proto files
5+
6+
set -ex
7+
cd "$(dirname "$0")/.."
8+
9+
docker build -t semantic-protoc --target protoc .
10+
11+
PARENT_DIR=$(dirname $(pwd))
12+
13+
export PROJECT="github.com/github/semantic"
14+
15+
# Generate Haskell for semantic's protobuf types
16+
docker run --rm --user $(id -u):$(id -g) -v $(pwd):/go/src/$PROJECT -w /go/src/$PROJECT \
17+
semantic-protoc \
18+
--proto_path=proto --haskell_out=src/Semantic/Proto \
19+
semantic.proto

semantic.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ library
249249
, Semantic.Api.Symbols
250250
, Semantic.Api.Terms
251251
, Semantic.Api.TOCSummaries
252-
, Semantic.Api.V1.CodeAnalysisPB
252+
, Semantic.Proto.SemanticPB
253253
, Semantic.AST
254254
, Semantic.CLI
255255
, Semantic.Config

src/Data/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Control.Effect
2424
import Control.Effect.State
2525
import Data.Aeson
2626
import qualified Data.Set as Set
27-
import Semantic.Api.V1.CodeAnalysisPB
27+
import Semantic.Proto.SemanticPB
2828

2929
-- | An algebraic graph with 'Ord', 'Semigroup', and 'Monoid' instances.
3030
newtype Graph vertex = Graph { unGraph :: G.Graph vertex }

src/Rendering/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Data.String (IsString (..))
2020
import Data.Term
2121
import Prologue
2222
import Semantic.Api.Bridge
23-
import Semantic.Api.V1.CodeAnalysisPB
23+
import Semantic.Proto.SemanticPB
2424

2525
import qualified Data.Text as T
2626

src/Semantic/Api.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import Semantic.Api.Diffs as DiffsAPI
1111
import Semantic.Api.Symbols as SymbolsAPI
1212
import Semantic.Api.Terms as TermsAPI
1313
import Semantic.Api.TOCSummaries as TOCSummariesAPI
14-
import Semantic.Api.V1.CodeAnalysisPB as Types
14+
import Semantic.Proto.SemanticPB as Types

src/Semantic/Api/Bridge.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Data.Source (fromText, toText)
1212
import qualified Data.Span as Data
1313
import qualified Data.Text as T
1414
import qualified Semantic.Api.LegacyTypes as Legacy
15-
import qualified Semantic.Api.V1.CodeAnalysisPB as API
15+
import qualified Semantic.Proto.SemanticPB as API
1616

1717
-- | An @APIBridge x y@ instance describes an isomorphism between @x@ and @y@.
1818
-- This is suitable for types such as 'Pos' which are representationally equivalent

src/Semantic/Api/Diffs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Rendering.Graph
3535
import Rendering.JSON hiding (JSON)
3636
import qualified Rendering.JSON
3737
import Semantic.Api.Bridge
38-
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, BlobPair)
38+
import Semantic.Proto.SemanticPB hiding (Blob, BlobPair)
3939
import Semantic.Task as Task
4040
import Semantic.Telemetry as Stat
4141
import Serializing.Format hiding (JSON)

src/Semantic/Api/Symbols.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Prologue
2424
import Semantic.Api.Bridge
2525
import qualified Semantic.Api.LegacyTypes as Legacy
2626
import Semantic.Api.Terms (ParseEffects, doParse)
27-
import Semantic.Api.V1.CodeAnalysisPB hiding (Blob)
27+
import Semantic.Proto.SemanticPB hiding (Blob)
2828
import Semantic.Task
2929
import Serializing.Format
3030
import Tags.Taggable

0 commit comments

Comments
 (0)