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

Add build-tool flag to omit tool and FV deps+modules from build #882

Merged
merged 8 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions executables/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module Main where

#if !defined(ghcjs_HOST_OS)
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
import qualified Pact.Bench as Bench
#endif


main :: IO ()
main =
#if defined(ghcjs_HOST_OS)
error "Error: command line REPL does not exist in GHCJS mode"
#else
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
Bench.main
#else
error "Error: command line REPL does not exist in GHCJS mode"
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved
#endif
8 changes: 4 additions & 4 deletions executables/GasModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module Main where

#if !defined(ghcjs_HOST_OS)
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
import qualified Pact.GasModel.GasModel as GasModel
#endif


main :: IO ()
main =
#if defined(ghcjs_HOST_OS)
error "Error: gas model benchmarking does not exist in GHCJS mode"
#else
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
GasModel.main
#else
error "Error: gas model benchmarking does not exist in GHCJS mode"
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved
#endif
8 changes: 4 additions & 4 deletions executables/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

module Main where

#if !defined(ghcjs_HOST_OS)
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
import qualified Pact.Main as Repl
#endif

main :: IO ()
main =
#if defined(ghcjs_HOST_OS)
error "Error: command line REPL does not exist in GHCJS mode"
#else
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
Repl.main
#else
error "Error: command line REPL does not exist in GHCJS mode"
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved
#endif
80 changes: 52 additions & 28 deletions pact.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ flag ghc-flags
default: False
manual: True

flag build-tool
description: Include modules and deps for tests + executable
default: True
manual: False
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved

library
exposed-modules: Crypto.Hash.Blake2Native
, Pact.Analyze.Remote.Types
Expand Down Expand Up @@ -101,9 +106,10 @@ library
exposed-modules:
Pact.Analyze.Remote.Client

if !impl(ghcjs)
hs-source-dirs: src-ghc
if !impl(ghcjs) && flag(build-tool)
hs-source-dirs: src-tool
exposed-modules:
Pact.Docgen
Pact.Analyze
Pact.Analyze.Alloc
Pact.Analyze.Eval
Expand Down Expand Up @@ -139,37 +145,56 @@ library
Pact.Analyze.Types.Types
Pact.Analyze.Util
Pact.Analyze.Remote.Server
Pact.ApiReq
Pact.Bench
Pact.Coverage
Pact.Coverage.Report
Pact.Docgen
Pact.Interpreter
Pact.Main
Pact.MockDb
Pact.Persist.MockPersist
Pact.Persist.SQLite
Pact.PersistPactDb.Regression
Pact.ReplTools
Pact.Server.ApiServer
Pact.Server.History.Persistence
Pact.Server.History.Service
Pact.Server.History.Types
Pact.Server.PactService
Pact.Server.Server
Pact.Server.Test
Pact.Types.Crypto
Pact.Types.ECDSA
Pact.Types.Server
Pact.Types.SQLite
Pact.GasModel.GasModel
Pact.GasModel.Types
Pact.GasModel.Utils
Pact.GasModel.GasTests

build-depends:
algebraic-graphs >= 0.2 && < 0.6
, cassava >= 0.5
, constraints
, fast-logger
, haskeline >= 0.7.3 && < 0.8
, mmorph >= 1.1 && < 1.2
, neat-interpolation >= 0.4
, optparse-applicative >= 0.12.1.0 && < 0.16
, sbv >= 8.8
, wai-cors
, warp


cpp-options: -DBUILD_TOOL
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved


if !impl(ghcjs)
hs-source-dirs: src-ghc
exposed-modules:
Pact.ApiReq
Pact.Coverage
Pact.Coverage.Report
Pact.Interpreter
Pact.MockDb
Pact.Persist.MockPersist
Pact.Persist.SQLite
Pact.PersistPactDb.Regression
Pact.Server.PactService
Pact.Types.Crypto
Pact.Types.ECDSA
Pact.Types.Server
Pact.Types.SQLite

build-depends: Decimal >= 0.4.2 && < 0.6
, aeson >= 0.11.3.0 && < 1.5
, algebraic-graphs >= 0.2 && < 0.6
, prettyprinter >= 1.2 && < 1.6.1
, prettyprinter-ansi-terminal >= 1.1 && < 1.2
, attoparsec >= 0.13.0.2 && < 0.14
Expand All @@ -180,7 +205,6 @@ library
, base64-bytestring >= 1.0.0.1 && < 1.2.0.0
, bound >= 2 && < 2.1
, bytestring >=0.10.8.1 && < 0.11
, cassava >= 0.5
, cereal >=0.5.4.0 && < 0.6
, containers >= 0.5.7 && < 0.7
, data-default >= 0.7.1.1 && < 0.8
Expand All @@ -196,6 +220,7 @@ library
, megaparsec >= 9
, mtl >= 2.2.1 && < 2.3
, optparse-applicative >= 0.12.1.0 && < 0.16
, pact-time >= 0.2
, parsers >= 0.12.4 && < 0.13
, QuickCheck >= 2.12.6.1
, quickcheck-instances >= 0.3
Expand All @@ -211,10 +236,7 @@ library
, vector >= 0.11.0.0 && < 0.13
, vector-algorithms >= 0.7
, vector-space >= 0.10.4 && < 0.17
, mmorph >= 1.1 && < 1.2
, constraints
, servant
, pact-time >= 0.2

if impl(ghcjs)
build-depends:
Expand All @@ -227,21 +249,23 @@ library
, criterion >= 1.1.4 && < 1.6
, cryptonite
, direct-sqlite
, fast-logger
, haskeline >= 0.7.3 && < 0.8
, http-client
, memory
, neat-interpolation >= 0.4
, safe-exceptions >= 0.1.5.0 && < 0.2
, sbv >= 8.8
, servant-client
, servant-client-core
, servant-server
, statistics >= 0.13.3 && < 0.16
, wai-cors
, warp
, yaml


if impl(ghcjs)
build-depends:
ghcjs-base,
larskuhtz marked this conversation as resolved.
Show resolved Hide resolved
ghcjs-prim


if !impl(ghcjs) && !os(windows)
build-depends: unix

Expand Down Expand Up @@ -292,7 +316,7 @@ executable gasmodel
default-language: Haskell2010

test-suite hspec
if !impl(ghcjs)
if !impl(ghcjs) && flag(build-tool)
main-is: hspec.hs
type: exitcode-stdio-1.0
else
Copy link
Contributor

@larskuhtz larskuhtz Jun 23, 2021

Choose a reason for hiding this comment

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

The else branch will be selected for !impl(ghcjs) && !flag(build-tool), which probably is not intended. I think, the following would be correct:

  elif impl(ghcjs) && flag(build-tool)
    main-is:          hspec-ghcjs.hs
    type:             exitcode-stdio-1.0
  else
    buildable: False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's intended this way to at least run some tests on ghc && !build-tool. What is really needed is a subset of tests for this case but that can wait.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, cool. I though the build-tool would be incompatible with the test suite. Much better this way. We should also reenable tests in the ci build for -build-tool.

Expand Down Expand Up @@ -334,7 +358,7 @@ test-suite hspec
Blake2Spec
KeysetSpec
TypesSpec
if !impl(ghcjs)
if !impl(ghcjs) && flag(build-tool)
build-depends:
neat-interpolation
, sbv
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 11 additions & 7 deletions src/Pact/Repl/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import qualified Data.Map.Strict as M
import Data.Semigroup (Endo(..))
import qualified Data.Set as S
import Data.Text (Text, unpack)
import qualified Data.Text as Text
import Data.Text.Encoding
import Pact.Time
import qualified Data.Vector as V
Expand All @@ -52,7 +51,9 @@ import Criterion.Types

import Statistics.Types (Estimate(..))

# ifdef BUILD_TOOL
import qualified Pact.Analyze.Check as Check
# endif
import qualified Pact.Types.Crypto as Crypto
#endif

Expand Down Expand Up @@ -209,9 +210,11 @@ replDefs = ("Repl",
["(env-exec-config ['DisableHistoryInTransactionalMode]) (env-exec-config)"]
("Queries, or with arguments, sets execution config flags. Valid flags: " <>
tShow (M.keys flagReps))
#ifdef BUILD_TOOL
,defZRNative "verify" verify (funType tTyString [("module",tTyString)])
[]
"Verify MODULE, checking that all properties hold."
#endif

,defZRNative "sig-keyset" sigKeyset (funType tTyKeySet [])
[]
Expand Down Expand Up @@ -608,32 +611,33 @@ tc i as = case as of
setop $ TcErrors $ map (\(TC.Failure ti s) -> renderInfo (TC._tiInfo ti) ++ ":Warning: " ++ s) fails
return $ tStr $ "Typecheck " <> modname <> ": Unable to resolve all types"

#ifdef BUILD_TOOL
verify :: RNativeFun LibState
verify i as = case as of
[TLitString modName] -> do
md <- getModule i (ModuleName modName Nothing)
-- reading all modules from db here, but should be fine in repl
modules <- getAllModules i
let failureMessage = tStr $ "Verification of " <> modName <> " failed"
#if defined(ghcjs_HOST_OS)
# if defined(ghcjs_HOST_OS)
uri <- fromMaybe "localhost" <$> viewLibState (view rlsVerifyUri)
renderedLines <- liftIO $
RemoteClient.verifyModule modules md uri
setop $ TcErrors $ Text.unpack <$> renderedLines
setop $ TcErrors $ unpack <$> renderedLines
return failureMessage
#else
# else
modResult <- liftIO $ Check.verifyModule modules md
let renderedLines = Check.renderVerifiedModule modResult
case modResult of
Right modResult'
| not (Check.hasVerificationError modResult')
-> return $ tStr $ mconcat renderedLines
_ -> do
setop $ TcErrors $ Text.unpack <$> renderedLines
setop $ TcErrors $ unpack <$> renderedLines
return failureMessage
#endif

# endif
_ -> argsError i as
#endif

sigKeyset :: RNativeFun LibState
sigKeyset _ _ = view eeMsgSigs >>= \ss ->
Expand Down
24 changes: 21 additions & 3 deletions src/Pact/Server/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ module Pact.Server.API
, ApiPoll
, ApiListen
, ApiLocal
#ifdef BUILD_TOOL
, ApiVerify
#endif
, ApiVersion
#if !defined(ghcjs_HOST_OS)
-- | client
, sendClient
, pollClient
, listenClient
, localClient
, verifyClient
, versionClient
# ifdef BUILD_TOOL
, verifyClient
# endif
#endif
) where

Expand All @@ -43,7 +47,9 @@ import Servant.Client
import Servant.Client.Core
#endif

#ifdef BUILD_TOOL
import qualified Pact.Analyze.Remote.Types as Analyze
#endif
import Pact.Types.API
import Pact.Types.Command
import Pact.Types.Hash
Expand All @@ -70,15 +76,21 @@ type ApiLocal = "local"
:> ReqBody '[JSON] (Command Text)
:> Post '[JSON] (CommandResult Hash)

#ifdef BUILD_TOOL
type ApiVerify = "verify"
:> ReqBody '[JSON] Analyze.Request
:> Post '[JSON] Analyze.Response
#endif

type ApiVersion = "version"
:> Get '[PlainText] Text

-- | "pact -s" REST API.
#ifdef BUILD_TOOL
type PactServerAPI = ApiV1API :<|> ApiVerify :<|> ApiVersion
#else
type PactServerAPI = ApiV1API :<|> ApiVersion
#endif

pactServerAPI :: Proxy PactServerAPI
pactServerAPI = Proxy
Expand All @@ -105,15 +117,21 @@ listenClient = v1Listen apiV1Client
localClient :: Command Text -> ClientM (CommandResult Hash)
localClient = v1Local apiV1Client

# ifdef BUILD_TOOL
verifyClient :: Analyze.Request -> ClientM Analyze.Response
verifyClient = client (Proxy @ApiVerify)
# endif

versionClient :: ClientM Text
versionClient = client (Proxy @ApiVersion)

apiV1Client :: forall m. RunClient m => ApiV1Client m
apiV1Client = ApiV1Client send poll listen local
where
(send :<|> poll :<|> listen :<|> local) :<|> _verify :<|> _version =
clientIn pactServerAPI (Proxy :: Proxy m)
(send :<|> poll :<|> listen :<|> local)
# ifdef BUILD_TOOL
:<|> _verify
# endif
:<|> _version =
clientIn pactServerAPI (Proxy :: Proxy m)
#endif
4 changes: 2 additions & 2 deletions src/Pact/Types/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Data.String
import Data.Default
import GHC.Generics (Generic)
import Control.DeepSeq
#if !defined(ghcjs_HOST_OS)
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
import Data.SBV (Mergeable (symbolicMerge))
#endif
import qualified Data.Vector as V
Expand Down Expand Up @@ -109,7 +109,7 @@ mkInfo t = Info $ Just (Code t,Parsed delt len)
where len = T.length t
delt = Directed (encodeUtf8 t) 0 0 (fromIntegral len) (fromIntegral len)

#if !defined(ghcjs_HOST_OS)
#if !defined(ghcjs_HOST_OS) && defined(BUILD_TOOL)
instance Mergeable Info where
-- Because Info values have no effect on execution we just take the max
-- (which could possibly have more info)
Expand Down