Skip to content

Commit

Permalink
Switch tests to using stack_install for Hackage dependencies
Browse files Browse the repository at this point in the history
This commit removes all use of the "new" `haskell_import` based
mechanism and the Nixpkgs code to support it. This is effectively
a revert of #442. The new stack_install mechanism is not Nixpkgs
specific and has better performance characteristics.
  • Loading branch information
mboes committed May 22, 2019
1 parent 79c26bc commit 7912560
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 169 deletions.
109 changes: 57 additions & 52 deletions WORKSPACE
Expand Up @@ -33,6 +33,32 @@ load("@os_info//:os_info.bzl", "is_linux", "is_windows")
# bazel dependencies
haskell_repositories()

load("@io_tweag_rules_haskell//haskell:cabal.bzl", "stack_install")

stack_install(
name = "stackage",
packages = [
# Core libraries
"array",
"base",
"directory",
"filepath",
"process",
# For tests
"streaming",
"void",
"hspec",
"hspec-core",
"lens-family-core",
"data-default-class",
"lens-labels",
"proto-lens",
"lens-family",
],
snapshot = "lts-13.15",
deps = ["@zlib.dev//:zlib"],
)

rules_nixpkgs_version = "0.5.2"

rules_nixpkgs_version_is_hash = False
Expand All @@ -52,29 +78,10 @@ load(
"nixpkgs_local_repository",
"nixpkgs_package",
)
load(
"@io_tweag_rules_haskell//haskell:nixpkgs.bzl",
"haskell_nixpkgs_package",
"haskell_nixpkgs_packageset",
)
load(
"@io_tweag_rules_haskell//tests/external-haskell-repository:workspace_dummy.bzl",
"haskell_package_repository_dummy",
)
load(
"@io_tweag_rules_haskell//:constants.bzl",
"test_ghc_version",
)

haskell_nixpkgs_package(
nixpkgs_package(
name = "ghc",
attribute_path = "haskellPackages.ghc",
nix_file = "//tests:ghc.nix",
nix_file_deps = ["//nixpkgs:default.nix"],
# rules_nixpkgs assumes we want to read from `<nixpkgs>` implicitly
# if `repository` is not set, but our nix_file uses `./nixpkgs/`.
# TODO(Profpatsch)
repositories = {"nixpkgs": "//nixpkgs:NOTUSED"},
repository = "@nixpkgs",
)

http_archive(
Expand Down Expand Up @@ -109,18 +116,22 @@ test_repl_ghci_args = [
"-XOverloadedStrings",
]

load(
"@io_tweag_rules_haskell//:constants.bzl",
"test_ghc_version",
)
load(
"@io_tweag_rules_haskell//haskell:nixpkgs.bzl",
"haskell_register_ghc_nixpkgs",
)

haskell_register_ghc_nixpkgs(
attribute_path = "ghc",
compiler_flags = test_compiler_flags,
haddock_flags = test_haddock_flags,
locale_archive = "@glibc_locales//:locale-archive",
nix_file = "//tests:ghc.nix",
nix_file_deps = ["//nixpkgs:default.nix"],
repl_ghci_args = test_repl_ghci_args,
repositories = {"nixpkgs": "@nixpkgs"},
version = test_ghc_version,
)

Expand Down Expand Up @@ -159,12 +170,29 @@ cc_library(
name = "zlib",
linkstatic = 1,
srcs = [":lib"],
testonly = 1,
)
""",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "c2hs",
attribute_path = "haskellPackages.c2hs",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "doctest",
attribute_path = "haskellPackages.doctest",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "proto-lens-protoc",
attribute_path = "haskellPackages.proto-lens-protoc",
repository = "@nixpkgs",
)

nixpkgs_package(
name = "sphinx",
attribute_path = "python36Packages.sphinx",
Expand All @@ -191,14 +219,12 @@ package(default_visibility = ["//visibility:public"])
filegroup (
name = "include",
srcs = glob(["include/*.h"]),
testonly = 1,
)
cc_library(
name = "zlib",
deps = ["@zlib//:zlib"],
hdrs = [":include"],
testonly = 1,
strip_include_prefix = "include",
)
""",
Expand All @@ -219,22 +245,6 @@ filegroup(
repository = "@nixpkgs",
)

haskell_nixpkgs_packageset(
name = "hackage-packages",
base_attribute_path = "haskellPackages",
nix_file = "//tests:ghc.nix",
nix_file_deps = ["//tests/haddock:libC.nix"],
nixopts = [
"-j",
"1",
],
repositories = {"nixpkgs": "@nixpkgs"},
)

load("@hackage-packages//:packages.bzl", "import_packages")

import_packages(name = "hackage")

load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

jvm_maven_import_external(
Expand All @@ -251,6 +261,11 @@ local_repository(
path = "tests/c2hs/repo",
)

load(
"@io_tweag_rules_haskell//tests/external-haskell-repository:workspace_dummy.bzl",
"haskell_package_repository_dummy",
)

# dummy repo for the external haskell repo test (hazel)
haskell_package_repository_dummy(
name = "haskell_package_repository_dummy",
Expand Down Expand Up @@ -363,13 +378,3 @@ buildifier_dependencies()
load("@ai_formation_hazel//:workspace.bzl", "hazel_setup")

hazel_setup()

load("@io_tweag_rules_haskell//haskell:cabal.bzl", "stack_install")

stack_install(
name = "stackage",
testonly = 1,
packages = ["stack"],
snapshot = "lts-13.15",
deps = ["@zlib.dev//:zlib"],
)
2 changes: 1 addition & 1 deletion constants.bzl
@@ -1 +1 @@
test_ghc_version = "8.6.4"
test_ghc_version = "8.6.5"
2 changes: 1 addition & 1 deletion haskell/nixpkgs.bzl
Expand Up @@ -394,7 +394,7 @@ def haskell_register_ghc_nixpkgs(
toolchain_repo_name = "io_tweag_rules_haskell_ghc_nixpkgs_toolchain"

# The package from the system.
haskell_nixpkgs_package(
nixpkgs_package(
name = nixpkgs_ghc_repo_name,
attribute_path = attribute_path,
build_file = build_file,
Expand Down
3 changes: 3 additions & 0 deletions shell.nix
Expand Up @@ -16,6 +16,9 @@ mkShell {
perl
python3
bazel
# For stack_install. TODO Remove ghc when move to Stack 2.
stack
ghc
# Needed for @com_github_golang_protobuf, itself needed by buildifier.
git
# Needed to get correct locale for tests with encoding
Expand Down
20 changes: 10 additions & 10 deletions tests/BUILD.bazel
Expand Up @@ -22,7 +22,7 @@ package(default_testonly = 1)

haskell_doctest_toolchain(
name = "doctest-toolchain",
doctest = "@hackage-doctest//:bin",
doctest = "@doctest//:bin",
tags = ["requires_doctest"],
)

Expand All @@ -34,7 +34,7 @@ haskell_doctest_toolchain(
haskell_proto_toolchain(
name = "protobuf-toolchain",
testonly = 0,
plugin = "@hackage-proto-lens-protoc//:bin/proto-lens-protoc",
plugin = "@proto-lens-protoc//:bin/proto-lens-protoc",
protoc = "@com_google_protobuf//:protoc",
tags = ["requires_hackage"],
deps = [
Expand All @@ -44,17 +44,17 @@ haskell_proto_toolchain(
"//tests/hackage:deepseq",
"//tests/hackage:mtl",
"//tests/hackage:text",
"@hackage//:data-default-class",
"@hackage//:lens-family",
"@hackage//:lens-family-core",
"@hackage//:lens-labels",
"@hackage//:proto-lens",
"@stackage//:data-default-class",
"@stackage//:lens-family",
"@stackage//:lens-family-core",
"@stackage//:lens-labels",
"@stackage//:proto-lens",
],
)

c2hs_toolchain(
name = "c2hs-toolchain",
c2hs = "@hackage-c2hs//:bin",
c2hs = "@c2hs//:bin",
tags = ["requires_c2hs"],
)

Expand Down Expand Up @@ -316,7 +316,7 @@ haskell_binary(
deps = [
"//tests/hackage:base",
"//tests/hackage:process",
"@hackage//:hspec",
"@hackage//:hspec-core",
"@stackage//:hspec",
"@stackage//:hspec-core",
],
)
4 changes: 2 additions & 2 deletions tests/binary-with-prebuilt/BUILD.bazel
Expand Up @@ -13,7 +13,7 @@ haskell_test(
deps = [
"//tests/hackage:base",
"//tests/hackage:template-haskell",
"@hackage//:streaming",
"@hackage//:void",
"@stackage//:streaming",
"@stackage//:void",
],
)
41 changes: 0 additions & 41 deletions tests/ghc.nix

This file was deleted.

1 change: 0 additions & 1 deletion tests/haddock/BUILD.bazel
Expand Up @@ -48,7 +48,6 @@ haskell_library(
":haddock-lib-a",
"//tests/hackage:base",
"//tests/hackage:template-haskell",
"@hackage//:libc",
"@zlib",
],
)
Expand Down
5 changes: 0 additions & 5 deletions tests/haddock/LibB.hs
Expand Up @@ -5,17 +5,12 @@ module LibB where

import LibA.A (a)
import LibA (f)
import LibC (mytype, LibCType)
import TH (foo)

-- | Doc for 'x' using 'f' and 'a' and 'Int'.
x :: Int
x = const f a

-- | This uses a type from an undocumented package
y :: LibCType
y = mytype

-- | A thing generated with TH.
z :: String
z = $foo
47 changes: 0 additions & 47 deletions tests/haddock/libC.nix

This file was deleted.

2 changes: 1 addition & 1 deletion tests/repl-targets/BUILD.bazel
Expand Up @@ -59,7 +59,7 @@ haskell_library(
deps = [
"//tests/data:ourclibrary",
"//tests/hackage:base",
"@hackage//:array",
"@stackage//:array",
"@zlib",
],
)
Expand Down

0 comments on commit 7912560

Please sign in to comment.