1
1
{-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE DataKinds #-}
2
3
{-# LANGUAGE FlexibleContexts #-}
3
4
{-# LANGUAGE LambdaCase #-}
4
5
{-# LANGUAGE RankNTypes #-}
@@ -23,19 +24,20 @@ import Prelude ()
23
24
-- local
24
25
import Distribution.PackageDescription
25
26
import Distribution.Pretty
27
+ import Distribution.Simple.Configure (findDistPrefOrDefault )
26
28
import Distribution.Simple.Errors
27
29
import Distribution.Simple.LocalBuildInfo
28
30
import Distribution.Simple.Program
29
31
import Distribution.Simple.Program.Db
30
32
import Distribution.Simple.Setup.Common
31
33
import Distribution.Simple.Setup.Config
32
34
import Distribution.Simple.Utils
33
- import Distribution.System (buildPlatform )
35
+ import Distribution.System (Platform , buildPlatform )
34
36
import Distribution.Utils.NubList
35
37
import Distribution.Utils.Path
36
- import Distribution.Verbosity
37
38
38
39
-- Base
40
+ import System.Directory (createDirectoryIfMissing , doesFileExist )
39
41
import qualified System.FilePath as FilePath
40
42
#ifdef mingw32_HOST_OS
41
43
import System.FilePath (normalise , splitDrive )
@@ -48,14 +50,24 @@ import qualified Data.List.NonEmpty as NonEmpty
48
50
import qualified Data.Map as Map
49
51
50
52
runConfigureScript
51
- :: Verbosity
52
- -> ConfigFlags
53
- -> LocalBuildInfo
53
+ :: ConfigFlags
54
+ -> FlagAssignment
55
+ -> ProgramDb
56
+ -> Platform -- ^ host platform
54
57
-> IO ()
55
- runConfigureScript verbosity flags lbi = do
58
+ runConfigureScript cfg flags programDb hp = do
59
+ let commonCfg = configCommonFlags cfg
60
+ verbosity = fromFlag $ setupVerbosity commonCfg
61
+ dist_dir <- findDistPrefOrDefault $ setupDistPref commonCfg
62
+ let build_dir = dist_dir </> makeRelativePathEx " build"
63
+ mbWorkDir = flagToMaybe $ setupWorkingDir commonCfg
64
+ configureScriptPath = packageRoot commonCfg </> " configure"
65
+ confExists <- doesFileExist configureScriptPath
66
+ unless confExists $
67
+ dieWithException verbosity (ConfigureScriptNotFound configureScriptPath)
68
+ configureFile <-
69
+ makeAbsolute $ configureScriptPath
56
70
env <- getEnvironment
57
- let commonFlags = configCommonFlags flags
58
- programDb = withPrograms lbi
59
71
(ccProg, ccFlags) <- configureCCompiler verbosity programDb
60
72
ccProgShort <- getShortPathName ccProg
61
73
-- The C compiler's compilation and linker flags (e.g.
@@ -64,8 +76,8 @@ runConfigureScript verbosity flags lbi = do
64
76
-- to ccFlags
65
77
-- We don't try and tell configure which ld to use, as we don't have
66
78
-- a way to pass its flags too
67
- configureFile <-
68
- makeAbsolute $ packageRoot commonFlags </> " configure "
79
+
80
+ let configureFile' = toUnix configureFile
69
81
-- autoconf is fussy about filenames, and has a set of forbidden
70
82
-- characters that can't appear in the build directory, etc:
71
83
-- https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions
@@ -79,7 +91,6 @@ runConfigureScript verbosity flags lbi = do
79
91
-- TODO: We don't check for colons, tildes or leading dashes. We
80
92
-- also should check the builddir's path, destdir, and all other
81
93
-- paths as well.
82
- let configureFile' = toUnix configureFile
83
94
for_ badAutoconfCharacters $ \ (c, cname) ->
84
95
when (c `elem` FilePath. dropDrive configureFile') $
85
96
warn verbosity $
@@ -111,7 +122,7 @@ runConfigureScript verbosity flags lbi = do
111
122
Map. fromListWith
112
123
(<>)
113
124
[ (flagEnvVar flag, (flag, bool) :| [] )
114
- | (flag, bool) <- unFlagAssignment $ flagAssignment lbi
125
+ | (flag, bool) <- unFlagAssignment flags
115
126
]
116
127
-- A map from env vars to flag names to the single flag we will go with
117
128
cabalFlagMapDeconflicted :: Map String (FlagName , Bool ) <-
@@ -143,10 +154,10 @@ runConfigureScript verbosity flags lbi = do
143
154
]
144
155
++ [
145
156
( " CABAL_FLAGS"
146
- , Just $ unwords [showFlagValue fv | fv <- unFlagAssignment $ flagAssignment lbi ]
157
+ , Just $ unwords [showFlagValue fv | fv <- unFlagAssignment flags ]
147
158
)
148
159
]
149
- let extraPath = fromNubList $ configProgramPathExtra flags
160
+ let extraPath = fromNubList $ configProgramPathExtra cfg
150
161
let cflagsEnv =
151
162
maybe (unwords ccFlags) (++ (" " ++ unwords ccFlags)) $
152
163
lookup " CFLAGS" env
@@ -160,7 +171,6 @@ runConfigureScript verbosity flags lbi = do
160
171
(" CFLAGS" , Just cflagsEnv)
161
172
: [(" PATH" , Just pathEnv) | not (null extraPath)]
162
173
++ cabalFlagEnv
163
- hp = hostPlatform lbi
164
174
maybeHostFlag = if hp == buildPlatform then [] else [" --host=" ++ show (pretty hp)]
165
175
args' = configureFile' : args ++ [" CC=" ++ ccProgShort] ++ maybeHostFlag
166
176
shProg = simpleProgram " sh"
@@ -169,14 +179,16 @@ runConfigureScript verbosity flags lbi = do
169
179
lookupProgram shProg
170
180
`fmap` configureProgram verbosity shProg progDb
171
181
case shConfiguredProg of
172
- Just sh ->
182
+ Just sh -> do
183
+ let build_in = interpretSymbolicPath mbWorkDir build_dir
184
+ createDirectoryIfMissing True build_in
173
185
runProgramInvocation verbosity $
174
186
(programInvocation (sh{programOverrideEnv = overEnv}) args')
175
- { progInvokeCwd = Just (interpretSymbolicPathLBI lbi $ buildDir lbi)
187
+ { progInvokeCwd = Just build_in
176
188
}
177
189
Nothing -> dieWithException verbosity NotFoundMsg
178
190
where
179
- args = configureArgs backwardsCompatHack flags
191
+ args = configureArgs backwardsCompatHack cfg
180
192
backwardsCompatHack = False
181
193
182
194
-- | Convert Windows path to Unix ones
0 commit comments