diff options
author | Yann Herklotz <git@yannherklotz.com> | 2019-07-23 01:38:23 +0200 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2019-07-23 01:38:23 +0200 |
commit | 89821f1837d34f3f8e66370a4e5638629015306c (patch) | |
tree | 1721197e06ee0ba2999927fee456bfee1108cd4b | |
parent | 58c0c75859a63bc60064a265eb3ea0ae669b4137 (diff) | |
download | verismith-89821f1837d34f3f8e66370a4e5638629015306c.tar.gz verismith-89821f1837d34f3f8e66370a4e5638629015306c.zip |
Remove stack and format fuzz
-rw-r--r-- | .envrc | 83 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/VeriFuzz/Fuzz.hs | 60 | ||||
-rw-r--r-- | stack-8.4.2.yaml | 10 | ||||
-rw-r--r-- | stack.yaml | 9 |
5 files changed, 111 insertions, 52 deletions
@@ -1 +1,84 @@ +#################################### +# Environment setup for Nix shells # +#################################### + +# From https://github.com/direnv/direnv/wiki/Nix#persistent-cached-shell +# +# Usage: use_nix [...] +# +# Load environment variables from `nix-shell`. +# If you have a `default.nix` or `shell.nix` one of these will be used and +# the derived environment will be stored at ./.direnv/env-<hash> +# and symlink to it will be created at ./.direnv/default. +# Dependencies are added to the GC roots, such that the environment remains persistent. +# +# Packages can also be specified directly via e.g `use nix -p ocaml`, +# however those will not be added to the GC roots. +# +# The resulting environment is cached for better performance. +# +# To trigger switch to a different environment: +# `rm -f .direnv/default` +# +# To derive a new environment: +# `rm -rf .direnv/env-$(md5sum {shell,default}.nix 2> /dev/null | cut -c -32)` +# +# To remove cache: +# `rm -f .direnv/dump-*` +# +# To remove all environments: +# `rm -rf .direnv/env-*` +# +# To remove only old environments: +# `find .direnv -name 'env-*' -and -not -name `readlink .direnv/default` -exec rm -rf {} +` +# +use_nix() { + set -e + + local shell="shell.nix" + if [[ ! -f "${shell}" ]]; then + shell="default.nix" + fi + + if [[ ! -f "${shell}" ]]; then + fail "use nix: shell.nix or default.nix not found in the folder" + fi + + local dir="${PWD}"/.direnv + local default="${dir}/default" + if [[ ! -L "${default}" ]] || [[ ! -d `readlink "${default}"` ]]; then + local wd="${dir}/env-`md5sum "${shell}" | cut -c -32`" # TODO: Hash also the nixpkgs version? + mkdir -p "${wd}" + + local drv="${wd}/env.drv" + if [[ ! -f "${drv}" ]]; then + log_status "use nix: deriving new environment" + IN_NIX_SHELL=1 nix-instantiate --add-root "${drv}" --indirect "${shell}" > /dev/null + nix-store -r `nix-store --query --references "${drv}"` --add-root "${wd}/dep" --indirect > /dev/null + fi + + rm -f "${default}" + ln -s `basename "${wd}"` "${default}" + fi + + local drv=`readlink -f "${default}/env.drv"` + local dump="${dir}/dump-`md5sum ".envrc" | cut -c -32`-`md5sum ${drv} | cut -c -32`" + + if [[ ! -f "${dump}" ]] || [[ "${XDG_CONFIG_DIR}/direnv/direnvrc" -nt "${dump}" ]]; then + log_status "use nix: updating cache" + + old=`find ${dir} -name 'dump-*'` + nix-shell "${drv}" --show-trace "$@" --run 'direnv dump' > "${dump}" + rm -f ${old} + fi + + direnv_load cat "${dump}" + + watch_file "${default}" + watch_file shell.nix + if [[ ${shell} == "default.nix" ]]; then + watch_file default.nix + fi +} + use nix @@ -12,3 +12,4 @@ failed output* .ghc* dist* +.direnv
\ No newline at end of file diff --git a/src/VeriFuzz/Fuzz.hs b/src/VeriFuzz/Fuzz.hs index dd7fe7b..0eb7f2d 100644 --- a/src/VeriFuzz/Fuzz.hs +++ b/src/VeriFuzz/Fuzz.hs @@ -27,40 +27,33 @@ module VeriFuzz.Fuzz ) where -import Control.DeepSeq ( force ) -import Control.Exception.Lifted ( finally ) -import Control.Lens hiding ( (<.>) ) -import Control.Monad ( forM - , replicateM - ) +import Control.DeepSeq (force) +import Control.Exception.Lifted (finally) +import Control.Lens hiding ((<.>)) +import Control.Monad (forM, replicateM) import Control.Monad.IO.Class -import Control.Monad.Trans.Class ( lift ) -import Control.Monad.Trans.Control ( MonadBaseControl ) -import Control.Monad.Trans.Maybe ( runMaybeT ) -import Control.Monad.Trans.Reader - hiding ( local ) +import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Control (MonadBaseControl) +import Control.Monad.Trans.Maybe (runMaybeT) +import Control.Monad.Trans.Reader hiding (local) import Control.Monad.Trans.State.Strict -import qualified Crypto.Random.DRBG as C -import Data.ByteString ( ByteString ) -import Data.List ( nubBy - , sort - ) -import Data.Maybe ( isNothing ) -import Data.Text ( Text ) -import qualified Data.Text as T +import qualified Crypto.Random.DRBG as C +import Data.ByteString (ByteString) +import Data.List (nubBy, sort) +import Data.Maybe (isNothing) +import Data.Text (Text) +import qualified Data.Text as T import Data.Time -import Data.Tuple ( swap ) -import Hedgehog ( Gen ) -import qualified Hedgehog.Internal.Gen as Hog -import Hedgehog.Internal.Seed ( Seed ) -import qualified Hedgehog.Internal.Seed as Hog -import qualified Hedgehog.Internal.Tree as Hog -import Prelude hiding ( FilePath ) -import Shelly hiding ( get ) -import Shelly.Lifted ( MonadSh - , liftSh - ) -import System.FilePath.Posix ( takeBaseName ) +import Data.Tuple (swap) +import Hedgehog (Gen) +import qualified Hedgehog.Internal.Gen as Hog +import Hedgehog.Internal.Seed (Seed) +import qualified Hedgehog.Internal.Seed as Hog +import qualified Hedgehog.Internal.Tree as Hog +import Prelude hiding (FilePath) +import Shelly hiding (get) +import Shelly.Lifted (MonadSh, liftSh) +import System.FilePath.Posix (takeBaseName) import VeriFuzz.Config import VeriFuzz.Internal import VeriFuzz.Reduce @@ -151,7 +144,7 @@ failedSynthesis :: MonadSh m => Fuzz m [SynthTool] failedSynthesis = fmap toSynth . filter failed . _fuzzSynthStatus <$> get where failed (SynthStatus _ (Fail SynthFail) _) = True - failed _ = False + failed _ = False toSynth (SynthStatus s _ _) = s make :: MonadSh m => FilePath -> m () @@ -261,7 +254,7 @@ failEquivWithIdentity = filter withIdentity . _fuzzSynthResults <$> get where withIdentity (SynthResult (IdentitySynth _) _ (Fail EquivFail) _) = True withIdentity (SynthResult _ (IdentitySynth _) (Fail EquivFail) _) = True - withIdentity _ = False + withIdentity _ = False passEquiv :: (MonadSh m) => Fuzz m [SynthResult] passEquiv = filter withIdentity . _fuzzSynthResults <$> get @@ -470,3 +463,4 @@ sampleSeed s gen = Nothing -> loop (n - 1) Just x -> return (seed, Hog.nodeValue x) in loop (100 :: Int) + diff --git a/stack-8.4.2.yaml b/stack-8.4.2.yaml deleted file mode 100644 index 4c9cdda..0000000 --- a/stack-8.4.2.yaml +++ /dev/null @@ -1,10 +0,0 @@ -flags: {} -packages: - - . -extra-deps: - - fgl-visualize-0.1.0.1@sha256:e682066053a6e75478a08fd6822dd0143a3b8ea23244bdb01dd389a266447c5e - - tomland-1.0.0@sha256:a6eb99963469c3c047f7f6a54ccbadc87c2ec046eec82c6f22e535f7edfbc292 - - dotgen-0.4.2@sha256:309b7cc8a3593a8e48bee7b53020d5f72db156d58edf78a0214f58fbb84b292b - - megaparsec-7.0.5@sha256:45e1f1348fab2783646fdb4d9e6097568981a740951c7356d36d794e2baba305 - - hedgehog-fn-0.5 -resolver: nightly-2018-05-30 diff --git a/stack.yaml b/stack.yaml deleted file mode 100644 index 8283ae6..0000000 --- a/stack.yaml +++ /dev/null @@ -1,9 +0,0 @@ -flags: {} -packages: - - . -extra-deps: - - DRBG-0.5.5@sha256:3b8040bed356e2b63927a27fb6d5adbd19d70c9e1d1bb66111bbeb33e56900eb - - fgl-visualize-0.1.0.1@sha256:e682066053a6e75478a08fd6822dd0143a3b8ea23244bdb01dd389a266447c5e - - tomland-1.0.1.0@sha256:d8a8d2c6a4a09966070fff3bdc64dd4700e35c061f21a0ba56fdad55035d9600 - -resolver: lts-13.28 |