Skip to content

Commit

Permalink
created cabal file offers building the test program (executable)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalh committed Nov 19, 2016
1 parent 0a28b27 commit 457808d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
45 changes: 31 additions & 14 deletions source/src/BNFC/Backend/Haskell/CFtoCabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,49 @@ buildPackageDescription opt = emptyPackageDescription
PackageIdentifier
{ pkgName = PackageName (lang opt)
, pkgVersion = Version [0,1] []}
, library =
Just mempty
{ exposedModules = exposedMods opt
, libExposed = True
, libBuildInfo = emptyBuildInfo
{ buildable = True
, hsSourceDirs = ["."]
, targetBuildDepends = dependencies opt
}
}
, library = Just (createLibrary opt)
, executables = [createExecutable opt]
, extraSrcFiles = [ happyFile opt, alexFile opt ]
, buildType = Just Simple
, license = AllRightsReserved
, specVersionRaw = Right (orLaterVersion $ Version [1,22] [])
}

dependencies :: SharedOptions -> [Dependency]
dependencies opt =
[ Dependency (PackageName "base") (laterVersion $ Version [4] [])
[ Dependency (PackageName "base") (orLaterVersion $ Version [4] [])
, Dependency (PackageName "array") anyVersion
] ++
[ Dependency (PackageName "mtl") anyVersion | TargetHaskellGadt == target opt ]

createLibrary :: SharedOptions -> Library
createLibrary opt = mempty
{ exposedModules = exposedLibMods opt
, libExposed = True
, libBuildInfo = emptyBuildInfo
{ buildable = True
, hsSourceDirs = ["."]
, targetBuildDepends = dependencies opt
}
}

createExecutable :: SharedOptions -> Executable
createExecutable opt = Executable name mainIs buildInfo where
name :: String
name = "Test" ++ lang opt

mainIs :: FilePath
mainIs = tFile opt

buildInfo :: BuildInfo
buildInfo = mempty
{ targetBuildDepends = dependencies opt
, otherModules = exposedLibMods opt
}

-- |returns a list of all exposed modules
exposedMods :: SharedOptions -> [ModuleName]
exposedMods opt = map fromString $
-- |returns a list of all modules the library exposes
exposedLibMods :: SharedOptions -> [ModuleName]
exposedLibMods opt = map fromString $
[absFileM opt
,errFileM opt
,printerFileM opt
Expand Down
3 changes: 2 additions & 1 deletion testing/src/HaskellCabalTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ mkTest target desc bnfcParams =
makeShellyTest description $ withTmpDir $ \tmp -> do
cd tmp
writefile "Test.cf" $ unlines
[ "Start. S ::= S \"a\" ;"
[ "Start. S ::= S \"parseMe\" ;"
, "End. S ::= ;" ]
run_ "bnfc" args
assertFileExists "Test.cabal"
cmd "cabal" "configure"
cmd "cabal" "build"
cmd "echo" "parseMe" -|- cmd "cabal" "run"
where
args :: [Text]
args = target:"--cabal":bnfcParams ++ ["Test.cf"]
Expand Down

0 comments on commit 457808d

Please sign in to comment.