forked from google/proto-lens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.hs
executable file
·67 lines (58 loc) · 2.53 KB
/
bootstrap.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- Copyright 2016 Google Inc. All Rights Reserved.
--
-- Use of this source code is governed by a BSD-style
-- license that can be found in the LICENSE file or at
-- https://developers.google.com/open-source/licenses/bsd
-- To regenerate the bootstrapping proto bindings:
-- $ runghc bootstrap.hs
-- Note: if this doesn't work, you may need to edit the "location" field in
-- stack-boostrap.yaml.
import Control.Applicative ((<$>))
import System.FilePath ((</>))
import System.Process (callProcess, readProcess)
protoRoot :: String
protoRoot = "google/protobuf/src"
protoc :: String
protoc = "protoc"
bootstrapModuleRoot :: String
bootstrapModuleRoot = "proto-lens-protoc/app"
bootstrappingYaml :: FilePath
bootstrappingYaml = "stack-bootstrap.yaml"
useBootstrappingYaml :: String
useBootstrappingYaml = "--stack-yaml=" ++ bootstrappingYaml
-- Change this to build with an older version of stack.
-- TODO: remove this after we can use stack v2 (#332).
stack :: String
stack = "stack"
-- This should match (or at least be API-compatible with) the value of bootstrapCommit
-- in stack-bootstrap.yaml.
bootstrapCommit :: String
bootstrapCommit = "master"
main :: IO ()
main = do
-- 1. Temporarily replace the bootstrap proto bindings in proto-lens-protoc
-- with an older version that's compatible with the bootstrap version of
-- proto-lens.
-- 2. Build proto-lens-protoc against the older proto-lens.
-- 3. Use it to generate new versions of the bootstrap proto bindings,
-- overwriting the previous versions.
callProcess "git" ["checkout", bootstrapCommit, "--",
bootstrapModuleRoot </> "Proto"]
[sha] <- lines <$> readProcess "git" ["rev-parse", bootstrapCommit] ""
-- Append the bootstrapping commit hash to the yaml file.
appendFile bootstrappingYaml (" commit: " ++ sha ++ "\n")
[installRoot] <- lines <$> readProcess stack
[useBootstrappingYaml, "path", "--local-install-root"] ""
let protocGenHaskell = installRoot </> "bin/proto-lens-protoc"
callProcess stack [useBootstrappingYaml, "build", "proto-lens-protoc"]
callProcess protoc $
[ "--plugin=protoc-gen-haskell=" ++ protocGenHaskell
, "--haskell_out=no-runtime:" ++ bootstrapModuleRoot
, "--proto_path=" ++ protoRoot
]
++ map (protoRoot </>)
[ "google/protobuf/descriptor.proto"
, "google/protobuf/compiler/plugin.proto"
]
-- Verify that the generated code compiles successfully.
callProcess stack ["build", "proto-lens-protoc"]