Skip to content

Commit b593ae3

Browse files
author
Jaro Reinders
committed
Simplify Setup.hs
1 parent e993213 commit b593ae3

3 files changed

Lines changed: 22 additions & 39 deletions

File tree

uuagc/trunk/Setup.hs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
1-
-- Note: to bootstrap uuagc with a commandline uuagc,
2-
-- pass the -DEXTERNAL_UUAGC to GHC
3-
-- when building setup.hs. This can be accomplished using
4-
-- cabal install with --ghc-options="-DEXTERNAL_UUAGC".
5-
--
6-
-- When this option is used, a cabal flag will be set so
7-
-- that the Haskell sources will be regenerated from
8-
-- the attribute grammar sources
9-
--
10-
-- Note: it would be nicer if this behavior could be enabled
11-
-- with a configure flag. However, a compiled Setup.hs is
12-
-- required in order to perform 'configure', so configure
13-
-- flags are regarded too late in the process.
14-
-- Also note that this Setup.hs has conditional package
15-
-- requirements depending on what code is used.
16-
171
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
18-
{-# LANGUAGE CPP #-}
192
module Main where
203

21-
#ifdef EXTERNAL_UUAGC
224
import System.Environment (getArgs)
23-
import Distribution.Simple (defaultMainWithHooksArgs)
5+
import Distribution.Simple (defaultMainWithHooksArgs, UserHooks (..), simpleUserHooks)
6+
import Distribution.Simple.LocalBuildInfo (flagAssignment)
247
import Distribution.Simple.UUAGC (uuagcUserHook)
8+
import Distribution.Types.Flag (lookupFlagAssignment, mkFlagName)
9+
import Debug.Trace
2510

2611
main :: IO ()
27-
main = args >>= defaultMainWithHooksArgs uuagcUserHook
28-
29-
args :: IO [String]
30-
args = do
31-
as <- getArgs
32-
let addFlags | "configure" `elem` as = ("--flags=bootstrap_external" :)
33-
| otherwise = id
34-
return (addFlags as)
35-
#else
36-
import Distribution.Simple (defaultMain, defaultMainWithHooksArgs)
37-
38-
main :: IO ()
39-
main = defaultMain
40-
#endif
12+
main = do
13+
args <- getArgs
14+
defaultMainWithHooksArgs hooks args
15+
where
16+
hooks = uuagcUserHook { buildHook = myBuildHook }
17+
myBuildHook pd lbi uh bf
18+
| lookupFlagAssignment (mkFlagName "bootstrap_external") (flagAssignment lbi) == Just True
19+
= buildHook uuagcUserHook pd lbi uh bf
20+
| otherwise
21+
= buildHook simpleUserHooks pd lbi uh bf

uuagc/trunk/update-src-generated.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rm -rf dist-newstyle
2-
cabal v2-configure --ghc-options="-DEXTERNAL_UUAGC" -fwith-loag
3-
cabal v2-build --ghc-options="-DEXTERNAL_UUAGC"
2+
set -e
3+
cabal v2-build -fbootstrap_external -fwith-loag
44
cp dist-newstyle/build/x86_64-linux/ghc-*/uuagc-*/build/*.hs src-generated/
55
cp dist-newstyle/build/x86_64-linux/ghc-*/uuagc-*/build/LOAG/*.hs src-generated/LOAG/
66
# Patch the line pragma's a bit

uuagc/trunk/uuagc.cabal

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ extra-source-files: src-ag/*.ag
2020
extra-source-files: src-ag/*.lag
2121
extra-source-files: src-ag/LOAG/*.ag
2222

23-
-- This flag will be set by Setup.hs, use
24-
-- cabal configure --ghc-options="-DEXTERNAL_UUAGC"
2523
flag bootstrap_external
2624
description: Use an external uuagc executable for bootstrapping
2725
default: False
@@ -55,8 +53,12 @@ library
5553
build-depends: haskell-src-exts >= 1.11.1
5654
build-depends: filepath >= 1.1.0.4
5755
build-depends: aeson >= 1.4.7.1, bytestring >= 0.9.2.1
58-
hs-source-dirs: src, src-version, src-ag, src-options
59-
if !flag(bootstrap_external)
56+
hs-source-dirs: src, src-version, src-options
57+
if flag(bootstrap_external)
58+
-- we need to avoid any *.ag files if we're not bootstrapping,
59+
-- because we now always use the ag preprocessor.
60+
hs-source-dirs: src-ag
61+
else
6062
hs-source-dirs: src-generated
6163
exposed-modules: UU.UUAGC, UU.UUAGC.Version
6264
default-extensions: TypeSynonymInstances, MultiParamTypeClasses

0 commit comments

Comments
 (0)