Skip to content

Commit

Permalink
Merge pull request #198 from symbiont-io/bazel-ldfi2-version
Browse files Browse the repository at this point in the history
bazel ldfi2 version
  • Loading branch information
symbiont-stevan-andjelkovic authored Apr 7, 2021
2 parents bcd1b5a + dd432d1 commit c19e6d6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 52 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ graal_bindist_repository(
name = "graal",
java_version = "11",
version = "21.0.0",
)
)
3 changes: 2 additions & 1 deletion doc/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ Then follow the relevant language support section of the `nixpkgs`

* Nix [Pills](https://nixos.org/guides/nix-pills/);
* `nixpkgs` [manual](https://nixos.org/manual/nixpkgs/unstable/);
* `nix` [manual](https://nixos.org/manual/nix/unstable/).
* `nix` [manual](https://nixos.org/manual/nix/unstable/);
* [How to Learn Nix](https://ianthehenry.com/posts/how-to-learn-nix/).
25 changes: 21 additions & 4 deletions src/ldfi2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ load(
"@rules_haskell//haskell:defs.bzl",
"haskell_binary",
"haskell_library",
"haskell_toolchain",
)

genrule(
name = "ldfi_version",
srcs = [],
outs = ["src/Ldfi/GitHash.hs"],
cmd = ";".join([
"( echo 'module Ldfi.GitHash (gitHash) where'",
"echo 'gitHash :: String'",
"echo -n 'gitHash = \"'",
"awk '/STABLE_GIT_COMMIT/ { printf $$2 }' bazel-out/stable-status.txt",
"echo '\"'",
") > \"$@\"",
]),
stamp = True,
message = "Generating version file",
visibility = ['//visibility:public'],
)

haskell_library(
name = "ldfi-lib",
name = "ldfi_lib",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs']),
srcs = glob(['src/**/*.hs']) + [":ldfi_version"],
deps = [
"@stackage//:aeson",
"@stackage//:base",
Expand All @@ -29,10 +45,11 @@ haskell_library(
haskell_binary(
name = "ldfi2",
srcs = ["app/Main.hs"],
compiler_flags = ["-D__BAZEL_BUILD__"],
deps = [
"@stackage//:base",
"@stackage//:optparse-generic",
"@stackage//:text",
":ldfi-lib"
":ldfi_lib",
],
)
22 changes: 19 additions & 3 deletions src/ldfi2/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
Expand All @@ -7,14 +8,29 @@ module Main where

import qualified Data.Text.IO as T
import qualified Ldfi
import Ldfi.FailureSpec (FailureSpec (FailureSpec))
import qualified Ldfi.GitHash as Git
import Ldfi.FailureSpec (FailureSpec(FailureSpec))
import Ldfi.Sat (z3Solver)
import Ldfi.Storage
import Options.Generic

------------------------------------------------------------------------

-- When building with Bazel we generate a module containing the git commit hash
-- at compile-time.
#ifdef __BAZEL_BUILD__
import Ldfi.GitHash
-- When building with cabal we expect the git commit hash to be passed in via
-- CPP flags, i.e. `--ghc-option=-D__GIT_HASH__=\"X\"`.
#elif defined __GIT_HASH__
gitHash :: String
gitHash = __GIT_HASH__
#else
gitHash :: String
gitHash = "unknown"
#endif

------------------------------------------------------------------------

type FailedRunHelpText = "Mark a RunId as having already failed in the test, the failures used in that run will not be generated again. This option can be repeated to mark several runs"

data Config = Config
Expand All @@ -37,7 +53,7 @@ main = do

go :: Config -> IO () -> IO ()
go cfg help
| unHelpful $ version cfg = putStrLn Git.version
| unHelpful $ version cfg = putStrLn gitHash
| otherwise =
let mFailSpec = makeFailureSpec (unHelpful $ endOfFiniteFailures cfg) (unHelpful $ maxCrashes cfg) (unHelpful $ endOfTime cfg) (unHelpful $ limitNumberOfFaults cfg)
in case (unHelpful $ testId cfg, mFailSpec) of
Expand Down
5 changes: 2 additions & 3 deletions src/ldfi2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ in
pkg.overrideAttrs (attrs: {
pname = "detsys-ldfi2";
src = gitignoreSource ./.;
preBuild = ''
export DETSYS_LDFI_VERSION="${nixpkgs.lib.commitIdFromGitRepo ./../../.git}"
'';
configureFlags =
[ "--ghc-option=-D__GIT_HASH__=\"${nixpkgs.lib.commitIdFromGitRepo ./../../.git}\"" ];
# this should probably check that attrs.checkInputs doesn't exist
checkInputs = [ nixpkgs.pkgs.haskell.packages.${compiler}.tasty-discover ];
})
3 changes: 0 additions & 3 deletions src/ldfi2/ldfi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ library
Ldfi
Ldfi.Estimate
Ldfi.FailureSpec
Ldfi.GitHash
Ldfi.Marshal.Faults
Ldfi.Prop
Ldfi.Sat
Ldfi.Solver
Ldfi.Storage
Ldfi.Traces

other-modules: Ldfi.GitHashImpl

-- GHC boot library dependencies:
-- (https://gitlab.haskell.org/ghc/ghc/-/blob/master/packages)
build-depends:
Expand Down
10 changes: 0 additions & 10 deletions src/ldfi2/src/Ldfi/GitHash.hs

This file was deleted.

27 changes: 0 additions & 27 deletions src/ldfi2/src/Ldfi/GitHashImpl.hs

This file was deleted.

0 comments on commit c19e6d6

Please sign in to comment.