nix
This commit is contained in:
parent
ecbd55dcf1
commit
18d2688e73
9 changed files with 59 additions and 109 deletions
2
Setup.hs
Normal file
2
Setup.hs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import Distribution.Simple
|
||||||
|
main = defaultMain
|
44
Setup.lhs
44
Setup.lhs
|
@ -1,44 +0,0 @@
|
||||||
#!/usr/bin/env runhaskell
|
|
||||||
\begin{code}
|
|
||||||
{-# OPTIONS_GHC -Wall #-}
|
|
||||||
module Main (main) where
|
|
||||||
|
|
||||||
import Data.List ( nub )
|
|
||||||
import Data.Version ( showVersion )
|
|
||||||
import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
|
|
||||||
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
|
|
||||||
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
|
|
||||||
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
|
|
||||||
import Distribution.Simple.BuildPaths ( autogenModulesDir )
|
|
||||||
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
|
|
||||||
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
|
|
||||||
import Distribution.Verbosity ( Verbosity )
|
|
||||||
import System.FilePath ( (</>) )
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = defaultMainWithHooks simpleUserHooks
|
|
||||||
{ buildHook = \pkg lbi hooks flags -> do
|
|
||||||
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
|
|
||||||
buildHook simpleUserHooks pkg lbi hooks flags
|
|
||||||
}
|
|
||||||
|
|
||||||
generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
|
|
||||||
generateBuildModule verbosity pkg lbi = do
|
|
||||||
let dir = autogenModulesDir lbi
|
|
||||||
createDirectoryIfMissingVerbose verbosity True dir
|
|
||||||
withLibLBI pkg lbi $ \_ libcfg -> do
|
|
||||||
withTestLBI pkg lbi $ \suite suitecfg -> do
|
|
||||||
rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
|
|
||||||
[ "module Build_" ++ testName suite ++ " where"
|
|
||||||
, "deps :: [String]"
|
|
||||||
, "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
|
|
||||||
]
|
|
||||||
where
|
|
||||||
formatdeps = map (formatone . snd)
|
|
||||||
formatone p = case packageName p of
|
|
||||||
PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
|
|
||||||
|
|
||||||
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
|
|
||||||
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
|
|
||||||
|
|
||||||
\end{code}
|
|
26
default.nix
Normal file
26
default.nix
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:
|
||||||
|
let
|
||||||
|
inherit (nixpkgs) pkgs;
|
||||||
|
haskellPackages = if compiler == "default"
|
||||||
|
then pkgs.haskellPackages
|
||||||
|
else pkgs.haskell.packages.${compiler};
|
||||||
|
|
||||||
|
tasty-hedgehog-github = pkgs.callPackage (pkgs.fetchFromGitHub {
|
||||||
|
owner = "qfpl";
|
||||||
|
repo = "tasty-hedgehog";
|
||||||
|
rev = "5da389f5534943b430300a213c5ffb5d0e13459e";
|
||||||
|
sha256 = "04pmr9q70gakd327sywpxr7qp8jnl3b0y2sqxxxcj6zj2q45q38m";
|
||||||
|
}) {};
|
||||||
|
|
||||||
|
modifiedHaskellPackages = haskellPackages.override {
|
||||||
|
overrides = self: super: {
|
||||||
|
tasty-hedgehog =
|
||||||
|
if super ? tasty-hedgehog
|
||||||
|
then super.tasty-hedgehog
|
||||||
|
else tasty-hedgehog-github;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
lets-lens = modifiedHaskellPackages.callPackage ./lets-lens.nix {};
|
||||||
|
in
|
||||||
|
lets-lens
|
|
@ -4,14 +4,15 @@ license: BSD3
|
||||||
license-file: LICENCE
|
license-file: LICENCE
|
||||||
author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
|
author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
|
||||||
maintainer: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
|
maintainer: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
|
||||||
copyright: Copyright (C) 2015 National ICT Australia Limited
|
copyright: Copyright (C) 2015-2016 National ICT Australia Limited
|
||||||
|
copyright: Copyright (c) 2018, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.
|
||||||
synopsis: Source code for exercises on the lens concept
|
synopsis: Source code for exercises on the lens concept
|
||||||
category: Education
|
category: Education
|
||||||
description: Source code for exercises on the lens concept
|
description: Source code for exercises on the lens concept
|
||||||
homepage: https://github.com/data61/lets-lens
|
homepage: https://github.com/data61/lets-lens
|
||||||
bug-reports: https://github.com/data61/lets-lens/issues
|
bug-reports: https://github.com/data61/lets-lens/issues
|
||||||
cabal-version: >= 1.10
|
cabal-version: >= 1.10
|
||||||
build-type: Custom
|
build-type: Simple
|
||||||
extra-source-files: changelog
|
extra-source-files: changelog
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
|
@ -24,11 +25,8 @@ flag small_base
|
||||||
library
|
library
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
build-depends: base < 5 && >= 4
|
build-depends: base >= 4.8 && < 5
|
||||||
, QuickCheck >= 2.0
|
|
||||||
, doctest >= 0.9.7
|
|
||||||
, containers >= 0.4.0.0
|
, containers >= 0.4.0.0
|
||||||
, array >= 0.4
|
|
||||||
|
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
-fno-warn-unused-binds
|
-fno-warn-unused-binds
|
||||||
|
|
15
lets-lens.nix
Normal file
15
lets-lens.nix
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{ mkDerivation, base, containers, directory, doctest, filepath
|
||||||
|
, QuickCheck, stdenv, template-haskell
|
||||||
|
}:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "lets-lens";
|
||||||
|
version = "0.0.1";
|
||||||
|
src = ./.;
|
||||||
|
libraryHaskellDepends = [ base containers ];
|
||||||
|
testHaskellDepends = [
|
||||||
|
base directory doctest filepath QuickCheck template-haskell
|
||||||
|
];
|
||||||
|
homepage = "https://github.com/data61/lets-lens";
|
||||||
|
description = "Source code for exercises on the lens concept";
|
||||||
|
license = stdenv.lib.licenses.bsd3;
|
||||||
|
}
|
7
shell.nix
Normal file
7
shell.nix
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:
|
||||||
|
let
|
||||||
|
inherit (nixpkgs) pkgs;
|
||||||
|
drv = import ./default.nix { inherit nixpkgs compiler; };
|
||||||
|
drvWithTools = pkgs.haskell.lib.addBuildDepends drv [ pkgs.cabal-install ];
|
||||||
|
in
|
||||||
|
if pkgs.lib.inNixShell then drvWithTools.env else drvWithTools
|
8
test/.gitignore
vendored
8
test/.gitignore
vendored
|
@ -1,8 +0,0 @@
|
||||||
# cabal
|
|
||||||
/dist
|
|
||||||
|
|
||||||
# cabal-dev
|
|
||||||
/cabal-dev
|
|
||||||
|
|
||||||
# Haskell Program Coverage
|
|
||||||
/.hpc
|
|
4
test/Tests.hs
Normal file
4
test/Tests.hs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = pure ()
|
|
@ -1,50 +0,0 @@
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
|
|
||||||
module Main where
|
|
||||||
|
|
||||||
import Build_doctests (deps)
|
|
||||||
#if (__GLASGOW_HASKELL__ < 710)
|
|
||||||
import Control.Applicative
|
|
||||||
#endif
|
|
||||||
import Control.Monad
|
|
||||||
import Data.List
|
|
||||||
import System.Directory
|
|
||||||
import System.FilePath
|
|
||||||
import Test.DocTest
|
|
||||||
|
|
||||||
main ::
|
|
||||||
IO ()
|
|
||||||
main =
|
|
||||||
getSources >>= \sources -> doctest $
|
|
||||||
"-isrc"
|
|
||||||
: "-idist/build/autogen"
|
|
||||||
: "-optP-include"
|
|
||||||
: "-optPdist/build/autogen/cabal_macros.h"
|
|
||||||
: "-hide-all-packages"
|
|
||||||
: map ("-package="++) deps ++ sources
|
|
||||||
|
|
||||||
sourceDirectories ::
|
|
||||||
[FilePath]
|
|
||||||
sourceDirectories =
|
|
||||||
[
|
|
||||||
"src"
|
|
||||||
]
|
|
||||||
|
|
||||||
isSourceFile ::
|
|
||||||
FilePath
|
|
||||||
-> Bool
|
|
||||||
isSourceFile p =
|
|
||||||
and [takeFileName p /= "Setup.hs", isSuffixOf ".hs" p]
|
|
||||||
|
|
||||||
getSources :: IO [FilePath]
|
|
||||||
getSources =
|
|
||||||
liftM (filter isSourceFile . concat) (mapM go sourceDirectories)
|
|
||||||
where
|
|
||||||
go dir = do
|
|
||||||
(dirs, files) <- getFilesAndDirectories dir
|
|
||||||
(files ++) . concat <$> mapM go dirs
|
|
||||||
|
|
||||||
getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])
|
|
||||||
getFilesAndDirectories dir = do
|
|
||||||
c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir
|
|
||||||
(,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c
|
|
Loading…
Reference in a new issue