From f723b8b878a3c4a4687b9e337a875500bebb39b1 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 4 Jul 2019 11:18:12 +0100 Subject: feat(third_party/bazel): Check in rules_haskell from Tweag --- .../bazel/rules_haskell/tests/haddock/BUILD.bazel | 73 ++++++++++++++++++++++ .../bazel/rules_haskell/tests/haddock/Deep.hsc | 11 ++++ .../bazel/rules_haskell/tests/haddock/LibA.hs | 19 ++++++ .../bazel/rules_haskell/tests/haddock/LibA/A.hs | 10 +++ .../bazel/rules_haskell/tests/haddock/LibB.hs | 21 +++++++ .../bazel/rules_haskell/tests/haddock/TH.hs | 7 +++ .../bazel/rules_haskell/tests/haddock/header.h | 1 + .../bazel/rules_haskell/tests/haddock/libC.nix | 47 ++++++++++++++ .../bazel/rules_haskell/tests/haddock/unicode.txt | 1 + 9 files changed, 190 insertions(+) create mode 100644 third_party/bazel/rules_haskell/tests/haddock/BUILD.bazel create mode 100644 third_party/bazel/rules_haskell/tests/haddock/Deep.hsc create mode 100644 third_party/bazel/rules_haskell/tests/haddock/LibA.hs create mode 100644 third_party/bazel/rules_haskell/tests/haddock/LibA/A.hs create mode 100644 third_party/bazel/rules_haskell/tests/haddock/LibB.hs create mode 100644 third_party/bazel/rules_haskell/tests/haddock/TH.hs create mode 100644 third_party/bazel/rules_haskell/tests/haddock/header.h create mode 100644 third_party/bazel/rules_haskell/tests/haddock/libC.nix create mode 100644 third_party/bazel/rules_haskell/tests/haddock/unicode.txt (limited to 'third_party/bazel/rules_haskell/tests/haddock') diff --git a/third_party/bazel/rules_haskell/tests/haddock/BUILD.bazel b/third_party/bazel/rules_haskell/tests/haddock/BUILD.bazel new file mode 100644 index 000000000000..6955285c87d2 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/BUILD.bazel @@ -0,0 +1,73 @@ +load( + "@io_tweag_rules_haskell//haskell:haskell.bzl", + "haskell_doc", + "haskell_library", + "haskell_toolchain_library", +) + +package( + default_testonly = 1, + default_visibility = ["//visibility:public"], +) + +haskell_library( + name = "haddock-lib-deep", + srcs = ["Deep.hsc"], + deps = ["//tests/hackage:base"], +) + +haskell_library( + name = "haddock-lib-a", + srcs = [ + "LibA.hs", + "LibA/A.hs", + "header.h", + ], + compiler_flags = ["-I."], + deps = [ + ":haddock-lib-deep", + "//tests/hackage:base", + "//tests/hackage:template-haskell", + ], +) + +haskell_toolchain_library( + name = "haddock-lib-c", + package = "libc", +) + +haskell_library( + name = "haddock-lib-b", + srcs = [ + "LibB.hs", + "TH.hs", + ], + extra_srcs = [ + "unicode.txt", + ], + tags = [ + "requires_hackage", + "requires_zlib", + ], + deps = [ + ":haddock-lib-a", + "//tests/hackage:base", + "//tests/hackage:template-haskell", + "@hackage//:libc", + "@zlib", + ], +) + +haskell_doc( + name = "haddock", + index_transitive_deps = False, + tags = ["requires_hackage"], + deps = [":haddock-lib-b"], +) + +haskell_doc( + name = "haddock-transitive", + index_transitive_deps = True, + tags = ["requires_hackage"], + deps = [":haddock-lib-b"], +) diff --git a/third_party/bazel/rules_haskell/tests/haddock/Deep.hsc b/third_party/bazel/rules_haskell/tests/haddock/Deep.hsc new file mode 100644 index 000000000000..6fb0482a1572 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/Deep.hsc @@ -0,0 +1,11 @@ +-- | "Deep" doc. +module Deep (deep_lib) where + +-- | 'deep_lib' doc. + +#if __GLASGOW_HASKELL__ >= 700 +#ifndef _INTERNAL_HSC_DO_NOT_DEFINE_ME +deep_lib :: Int +deep_lib = 100 +#endif +#endif diff --git a/third_party/bazel/rules_haskell/tests/haddock/LibA.hs b/third_party/bazel/rules_haskell/tests/haddock/LibA.hs new file mode 100644 index 000000000000..252c90ccc6d9 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/LibA.hs @@ -0,0 +1,19 @@ +-- | "LibA" header +{-# LANGUAGE CPP #-} +{-# LANGUAGE TemplateHaskell #-} + +#include "header.h" + +module LibA where + +import LibA.A (a) +import Deep (deep_lib) + +-- | 'A' declaration. +data A = + -- | 'A' constructor. + A + +-- | Doc for 'f' using 'a' and 'deep_lib'. +f :: Int +f = const $a deep_lib + MAGIC_NUMBER diff --git a/third_party/bazel/rules_haskell/tests/haddock/LibA/A.hs b/third_party/bazel/rules_haskell/tests/haddock/LibA/A.hs new file mode 100644 index 000000000000..3be8dd5aadd3 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/LibA/A.hs @@ -0,0 +1,10 @@ +-- | "LibA.A" header +{-# LANGUAGE TemplateHaskell #-} + +module LibA.A where + +import Language.Haskell.TH + +-- | 'a' doc +a :: Q Exp +a = [| 5 |] diff --git a/third_party/bazel/rules_haskell/tests/haddock/LibB.hs b/third_party/bazel/rules_haskell/tests/haddock/LibB.hs new file mode 100644 index 000000000000..b4df1ffcb9a2 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/LibB.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE TemplateHaskell #-} +-- | "LibB" doc. + +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 diff --git a/third_party/bazel/rules_haskell/tests/haddock/TH.hs b/third_party/bazel/rules_haskell/tests/haddock/TH.hs new file mode 100644 index 000000000000..6e791b09154e --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/TH.hs @@ -0,0 +1,7 @@ +module TH (foo) where + +import Language.Haskell.TH +import Language.Haskell.TH.Syntax (lift) + +foo :: Q Exp +foo = runIO (readFile "tests/haddock/unicode.txt") >>= lift diff --git a/third_party/bazel/rules_haskell/tests/haddock/header.h b/third_party/bazel/rules_haskell/tests/haddock/header.h new file mode 100644 index 000000000000..ec5eddd2766e --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/header.h @@ -0,0 +1 @@ +#define MAGIC_NUMBER 100 diff --git a/third_party/bazel/rules_haskell/tests/haddock/libC.nix b/third_party/bazel/rules_haskell/tests/haddock/libC.nix new file mode 100644 index 000000000000..d345178838f1 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/libC.nix @@ -0,0 +1,47 @@ +# A trivial `haskellPackages` library that has haddock generation disabled +self: pkgs: +let + # pkgs = import ../../nixpkgs.nix {}; + + libC = pkgs.writeText "LibC.hs" '' + {-# language NoImplicitPrelude #-} + module LibC where + + data LibCType = LibCType + + -- | myfunction + mytype :: LibCType + mytype = LibCType + ''; + + cabal = pkgs.writeText "libc.cabal" '' + name: libc + version: 0.1.0.0 + build-type: Simple + cabal-version: >=1.10 + + library + default-language: Haskell2010 + exposed-modules: LibC + ''; + + src = pkgs.runCommand "libc-src" {} '' + mkdir $out + cp ${libC} $out/LibC.hs + cp ${cabal} $out/libc.cabal + ''; + +in + # This call means the `.haddock` file is not generated, + # even though the ghc package still references the location + # where it would ordinarily be. + pkgs.haskell.lib.dontHaddock + + (self.callPackage + ({ mkDerivation }: mkDerivation { + pname = "libc"; + version = "0.1.0.0"; + src = src; + license = pkgs.lib.licenses.mit; + isExecutable = false; + }) {}) diff --git a/third_party/bazel/rules_haskell/tests/haddock/unicode.txt b/third_party/bazel/rules_haskell/tests/haddock/unicode.txt new file mode 100644 index 000000000000..74e5f2638d08 --- /dev/null +++ b/third_party/bazel/rules_haskell/tests/haddock/unicode.txt @@ -0,0 +1 @@ +Некоторый текст на русском. -- cgit 1.4.1