13
13
-----------------------------------------------------------------------------
14
14
module Distribution.Client.Configure (
15
15
configure ,
16
+ configureSetupScript ,
16
17
chooseCabalVersion ,
17
18
) where
18
19
@@ -30,6 +31,8 @@ import Distribution.Client.SetupWrapper
30
31
import Distribution.Client.Targets
31
32
( userToPackageConstraint )
32
33
import qualified Distribution.Client.ComponentDeps as CD
34
+ import Distribution.Package (PackageId )
35
+ import Distribution.Client.JobControl (Lock )
33
36
34
37
import Distribution.Simple.Compiler
35
38
( Compiler , CompilerInfo , compilerInfo , PackageDB (.. ), PackageDBStack )
@@ -41,7 +44,10 @@ import Distribution.Simple.Utils
41
44
( defaultPackageDesc )
42
45
import qualified Distribution.InstalledPackageInfo as Installed
43
46
import Distribution.Package
44
- ( Package (.. ), packageName , Dependency (.. ), thisPackageVersion )
47
+ ( Package (.. ), InstalledPackageId , packageName
48
+ , Dependency (.. ), thisPackageVersion
49
+ )
50
+ import qualified Distribution.PackageDescription as PkgDesc
45
51
import Distribution.PackageDescription.Parse
46
52
( readPackageDescription )
47
53
import Distribution.PackageDescription.Configuration
@@ -60,6 +66,7 @@ import Distribution.Version
60
66
#if !MIN_VERSION_base(4,8,0)
61
67
import Data.Monoid (Monoid (.. ))
62
68
#endif
69
+ import Data.Maybe (isJust , fromMaybe )
63
70
64
71
-- | Choose the Cabal version such that the setup scripts compiled against this
65
72
-- version will support the given command-line flags.
@@ -101,52 +108,114 @@ configure verbosity packageDBs repos comp platform conf
101
108
progress
102
109
case maybePlan of
103
110
Left message -> do
104
- info verbosity message
105
- setupWrapper verbosity (setupScriptOptions installedPkgIndex) Nothing
111
+ info verbosity $
112
+ " Warning: solver failed to find a solution:\n "
113
+ ++ message
114
+ ++ " Trying configure anyway."
115
+ setupWrapper verbosity (setupScriptOptions installedPkgIndex Nothing ) Nothing
106
116
configureCommand (const configFlags) extraArgs
107
117
108
118
Right installPlan -> case InstallPlan. ready installPlan of
109
- [pkg@ (ReadyPackage (SourcePackage _ _ (LocalUnpackedPackage _) _) _ _ _)] ->
119
+ [pkg@ (ReadyPackage (SourcePackage _ _ (LocalUnpackedPackage _) _) _ _ _)] -> do
110
120
configurePackage verbosity
111
121
(InstallPlan. planPlatform installPlan)
112
122
(InstallPlan. planCompiler installPlan)
113
- (setupScriptOptions installedPkgIndex)
123
+ (setupScriptOptions installedPkgIndex ( Just pkg) )
114
124
configFlags pkg extraArgs
115
125
116
126
_ -> die $ " internal error: configure install plan should have exactly "
117
127
++ " one local ready package."
118
128
119
129
where
120
- setupScriptOptions index = SetupScriptOptions {
121
- useCabalVersion = chooseCabalVersion configExFlags
122
- (flagToMaybe (configCabalVersion configExFlags)),
123
- useCompiler = Just comp,
124
- usePlatform = Just platform,
125
- usePackageDB = packageDBs',
126
- usePackageIndex = index',
127
- useProgramConfig = conf,
128
- useDistPref = fromFlagOrDefault
129
- (useDistPref defaultSetupScriptOptions)
130
- (configDistPref configFlags),
131
- useLoggingHandle = Nothing ,
132
- useWorkingDir = Nothing ,
133
- useWin32CleanHack = False ,
134
- forceExternalSetupMethod = False ,
135
- setupCacheLock = Nothing
136
- }
137
- where
138
- -- Hack: we typically want to allow the UserPackageDB for finding the
139
- -- Cabal lib when compiling any Setup.hs even if we're doing a global
140
- -- install. However we also allow looking in a specific package db.
141
- (packageDBs', index') =
142
- case packageDBs of
143
- (GlobalPackageDB : dbs) | UserPackageDB `notElem` dbs
144
- -> (GlobalPackageDB : UserPackageDB : dbs, Nothing )
145
- -- but if the user is using an odd db stack, don't touch it
146
- dbs -> (dbs, Just index)
130
+ setupScriptOptions :: InstalledPackageIndex -> Maybe ReadyPackage -> SetupScriptOptions
131
+ setupScriptOptions =
132
+ configureSetupScript
133
+ packageDBs
134
+ comp
135
+ platform
136
+ conf
137
+ (fromFlagOrDefault
138
+ (useDistPref defaultSetupScriptOptions)
139
+ (configDistPref configFlags))
140
+ (chooseCabalVersion
141
+ configExFlags
142
+ (flagToMaybe (configCabalVersion configExFlags)))
143
+ Nothing
144
+ False
147
145
148
146
logMsg message rest = debug verbosity message >> rest
149
147
148
+ configureSetupScript :: PackageDBStack
149
+ -> Compiler
150
+ -> Platform
151
+ -> ProgramConfiguration
152
+ -> FilePath
153
+ -> VersionRange
154
+ -> Maybe Lock
155
+ -> Bool
156
+ -> InstalledPackageIndex
157
+ -> Maybe ReadyPackage
158
+ -> SetupScriptOptions
159
+ configureSetupScript packageDBs
160
+ comp
161
+ platform
162
+ conf
163
+ distPref
164
+ cabalVersion
165
+ lock
166
+ forceExternal
167
+ index
168
+ mpkg
169
+ = SetupScriptOptions {
170
+ useCabalVersion = cabalVersion
171
+ , useCompiler = Just comp
172
+ , usePlatform = Just platform
173
+ , usePackageDB = packageDBs'
174
+ , usePackageIndex = index'
175
+ , useProgramConfig = conf
176
+ , useDistPref = distPref
177
+ , useLoggingHandle = Nothing
178
+ , useWorkingDir = Nothing
179
+ , setupCacheLock = lock
180
+ , useWin32CleanHack = False
181
+ , forceExternalSetupMethod = forceExternal
182
+ -- If we have explicit setup dependencies, list them; otherwise, we give
183
+ -- the empty list of dependencies; ideally, we would fix the version of
184
+ -- Cabal here, so that we no longer need the special case for that in
185
+ -- `compileSetupExecutable` in `externalSetupMethod`, but we don't yet
186
+ -- know the version of Cabal at this point, but only find this there.
187
+ -- Therefore, for now, we just leave this blank.
188
+ , useDependencies = fromMaybe [] explicitSetupDeps
189
+ , useDependenciesExclusive = isJust explicitSetupDeps
190
+ }
191
+ where
192
+ -- When we are compiling a legacy setup script without an explicit
193
+ -- setup stanza, we typically want to allow the UserPackageDB for
194
+ -- finding the Cabal lib when compiling any Setup.hs even if we're doing
195
+ -- a global install. However we also allow looking in a specific package
196
+ -- db.
197
+ packageDBs' :: PackageDBStack
198
+ index' :: Maybe InstalledPackageIndex
199
+ (packageDBs', index') =
200
+ case packageDBs of
201
+ (GlobalPackageDB : dbs) | UserPackageDB `notElem` dbs
202
+ , Nothing <- explicitSetupDeps
203
+ -> (GlobalPackageDB : UserPackageDB : dbs, Nothing )
204
+ -- but if the user is using an odd db stack, don't touch it
205
+ _otherwise -> (packageDBs, Just index)
206
+
207
+ explicitSetupDeps :: Maybe [(InstalledPackageId , PackageId )]
208
+ explicitSetupDeps = do
209
+ ReadyPackage (SourcePackage _ gpkg _ _) _ _ deps <- mpkg
210
+ -- Check if there is an explicit setup stanza
211
+ _buildInfo <- PkgDesc. setupBuildInfo (PkgDesc. packageDescription gpkg)
212
+ -- Return the setup dependencies computed by the solver
213
+ return [ ( Installed. installedPackageId deppkg
214
+ , Installed. sourcePackageId deppkg
215
+ )
216
+ | deppkg <- CD. setupDeps deps
217
+ ]
218
+
150
219
-- | Make an 'InstallPlan' for the unpacked package in the current directory,
151
220
-- and all its dependencies.
152
221
--
0 commit comments