Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use configurations to allow to build with old ghc, but requires new c…

…abal

Also update Setup.lhs, again requires new cabal, but much simplified.
  • Loading branch information...
commit 532e9188427f7ba548ff463a9762d34046aee40c 1 parent c0f9659
@dcoutts dcoutts authored
Showing with 70 additions and 109 deletions.
  1. +37 −87 Setup.lhs
  2. +33 −22 alex.cabal
View
124 Setup.lhs
@@ -3,63 +3,55 @@
\begin{code}
module Main where
-import Control.Exception ( finally )
-import Distribution.Simple.Setup ( CopyDest(..), CopyFlags(..) )
+import Distribution.PackageDescription (PackageDescription(..))
+import Distribution.Simple.Setup ( BuildFlags(..) )
import Distribution.Simple ( defaultMainWithHooks, defaultUserHooks, UserHooks(..) )
-import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..), mkDataDir )
-import System.Directory ( findExecutable, removeFile, copyFile, createDirectoryIfMissing, getCurrentDirectory, setCurrentDirectory )
-import System.Exit ( ExitCode(..) )
-import System.IO ( openFile, IOMode(..) )
+import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..) )
+import Distribution.Simple.Program
+
+import System.FilePath ((</>))
import System.IO.Error ( try )
-import System.Process ( runProcess, waitForProcess )
+import System.Directory (removeFile)
main :: IO ()
-main = defaultMainWithHooks defaultUserHooks{ postBuild = myPostBuild,
+main = defaultMainWithHooks defaultUserHooks{ hookedPrograms = [perlProgram],
+ postBuild = myPostBuild,
postClean = myPostClean,
- postCopy = myPostCopy,
- postInst = myPostInstall }
+ copyHook = myCopy,
+ instHook = myInstall }
+
+perlProgram = simpleProgram "perl"
-myPostBuild _ _ _ lbi =
- excursion "templates" $ do
- let cpp_template src dst opts = do
- let dst_pp = dst ++ ".hspp"
- ghc = "ghc" -- totally wrong, but I've lost the last bit of energy to find out how to do this correctly with Cabal
- ghc_args = ["-o", dst_pp, "-E", "-cpp", src] ++ opts
- -- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into
- -- '{-# LINE 27 "GenericTemplate.hs" #-}'.
- perl_args = ["-pe", "s/^#\\s+(\\d+)\\s+(\"[^\"]*\")/{-# LINE \\1 \\2 #-}/g;s/\\$(Id:.*)\\$/\\1/g", dst_pp]
- mb_perl <- findExecutable "perl"
- perl <- case mb_perl of
- Nothing -> ioError (userError "You need \"perl\" installed and on your PATH to complete the build")
- Just path -> return path
- do_cmd ghc ghc_args `cmd_seq` do_cmd_out perl perl_args dst
+-- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into
+-- '{-# LINE 27 "GenericTemplate.hs" #-}'.
+crazy_perl_regexp =
+ "s/^#\\s+(\\d+)\\s+(\"[^\"]*\")/{-# LINE \\1 \\2 #-}/g;s/\\$(Id:.*)\\$/\\1/g"
- cmd_seqs ([ cpp_template "GenericTemplate.hs" dst opts | (dst,opts) <- templates ] ++
- [ cpp_template "wrappers.hs" dst opts | (dst,opts) <- wrappers ])
- return ()
+myPostBuild _ flags _ lbi = do
+ let runProgram p = rawSystemProgramConf (buildVerbose flags) p (withPrograms lbi)
+ cpp_template src dst opts = do
+ runProgram ghcProgram (["-o", dst, "-E", "-cpp", "templates" </> src] ++ opts)
+ runProgram perlProgram ["-i", "-pe", crazy_perl_regexp, dst]
-myPostClean _ _ _ _ =
- excursion "templates" $ do
- sequence_ [ try (removeFile f) >> try (removeFile (f ++ ".hspp"))
- | (f,_) <- all_templates]
- return done
+ sequence_ ([ cpp_template "GenericTemplate.hs" dst opts | (dst,opts) <- templates ] ++
+ [ cpp_template "wrappers.hs" dst opts | (dst,opts) <- wrappers ])
-myPostInstall _ _ pkg_descr lbi = do
- install pkg_descr lbi NoCopyDest
+myPostClean _ _ _ _ = mapM_ (try . removeFile) all_template_files
-myPostCopy _ copy_flags pkg_descr lbi = do
- install pkg_descr lbi (copyDest copy_flags)
+myInstall pkg_descr lbi hooks flags =
+ instHook defaultUserHooks pkg_descr' lbi hooks flags
+ where pkg_descr' = pkg_descr {
+ dataFiles = dataFiles pkg_descr ++ all_template_files
+ }
-install pkg_descr lbi copy_dest =
- excursion "templates" $ do
- let dataDir = mkDataDir pkg_descr lbi copy_dest
- createDirectoryIfMissing True dataDir
- sequence [ copyFile f (dataDir ++ '/':f) | (f,_) <- all_templates ]
- -- XXX: joinFileName
- return done
+myCopy pkg_descr lbi hooks copy_flags =
+ copyHook defaultUserHooks pkg_descr' lbi hooks copy_flags
+ where pkg_descr' = pkg_descr {
+ dataFiles = dataFiles pkg_descr ++ all_template_files
+ }
-all_templates :: [(FilePath,[String])]
-all_templates = templates ++ wrappers
+all_template_files :: [FilePath]
+all_template_files = map fst (templates ++ wrappers)
templates :: [(FilePath,[String])]
templates = [
@@ -80,46 +72,4 @@ wrappers = [
("AlexWrapper-gscan", ["-DALEX_GSCAN"])
]
--- -----------------------------------------------------------------------------
--- Utils
-
-do_cmd :: FilePath -> [String] -> IO ExitCode
-do_cmd cmd args = do
- putStrLn (unwords (cmd:args))
- ph <- runProcess cmd args Nothing Nothing Nothing Nothing Nothing
- waitForProcess ph
-
-do_cmd_out :: FilePath -> [String] -> FilePath -> IO ExitCode
-do_cmd_out cmd args outfile = do
- putStrLn (unwords (cmd:args))
- outh <- openFile outfile WriteMode
- ph <- runProcess cmd args Nothing Nothing Nothing (Just outh) Nothing
- waitForProcess ph
-
-cmd_seq :: IO ExitCode -> IO ExitCode -> IO ExitCode
-cmd_seq c1 c2 = do
- e <- c1
- case e of
- ExitSuccess -> c2
- _ -> return e
-
-cmd_seqs = foldr cmd_seq (return done)
-
-excursion :: FilePath -> IO a -> IO a
-excursion d io = do
- cwd <- getCurrentDirectory
- (do setCurrentDirectory d; io) `finally` setCurrentDirectory cwd
-
--- -----------------------------------------------------------------------------
--- Cope with Cabal's API changes
-
-class Done a where
- done :: a
-
-instance Done () where
- done = ()
-
-instance Done ExitCode where
- done = ExitSuccess
-
\end{code}
View
55 alex.cabal
@@ -9,7 +9,7 @@ stability: stable
homepage: http://www.haskell.org/alex/
synopsis: Alex is a tool for generating lexical analysers in Haskell
category: Development
-build-depends: base>=1.0, haskell98>=1.0, array, containers, directory
+cabal-version: >= 1.2
extra-source-files:
ANNOUNCE
README
@@ -49,24 +49,35 @@ extra-source-files:
tests/tokens_gscan.x
tests/tokens_posn.x
-executable: alex
-hs-source-dirs: src
-main-is: Main.hs
-extensions: CPP
-other-modules:
- AbsSyn
- CharSet
- DFA
- DFS
- Info
- Main
- Map
- NFA
- Output
- Parser
- ParseMonad
- Scan
- Set
- Sort
- Util
-ghc-options: -O
+flag small_base
+ description: Choose the new smaller, split-up base package.
+
+executable alex
+ executable: alex
+ hs-source-dirs: src
+ main-is: Main.hs
+
+ if flag(small_base)
+ build-depends: base >= 2.1, array, containers, directory
+ else
+ build-depends: base >= 1.0
+
+ build-depends: haskell98 >= 1.0
+
+ extensions: CPP
+ other-modules:
+ AbsSyn
+ CharSet
+ DFA
+ DFS
+ Info
+ Main
+ Map
+ NFA
+ Output
+ Parser
+ ParseMonad
+ Scan
+ Set
+ Sort
+ Util
Please sign in to comment.
Something went wrong with that request. Please try again.