Skip to content

Commit 58f3ef0

Browse files
committed
Rename fields of ConfigureOpts, and related
1 parent d9faf29 commit 58f3ef0

File tree

7 files changed

+82
-76
lines changed

7 files changed

+82
-76
lines changed

.stan.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@
8383

8484
# Anti-pattern: Data.ByteString.Char8.pack
8585
[[ignore]]
86-
id = "OBS-STAN-0203-tuE+RG-226:21"
86+
id = "OBS-STAN-0203-tuE+RG-228:21"
8787
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
8888
# ✦ Category: #AntiPattern
8989
# ✦ File: src\Stack\Build\ExecutePackage.hs
9090
#
91-
# 225
92-
# 226 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
93-
# 227 ┃ ^^^^^^^
91+
# 227
92+
# 228 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
93+
# 229 ┃ ^^^^^^^
9494

9595
# Anti-pattern: Data.ByteString.Char8.pack
9696
[[ignore]]

src/Stack/Build/Cache.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ getPrecompiledCacheKey ::
347347
-> ConfigureOpts
348348
-> Bool -- ^ build haddocks
349349
-> RIO env PrecompiledCacheKey
350-
getPrecompiledCacheKey loc copts buildHaddocks = do
350+
getPrecompiledCacheKey loc configureOpts buildHaddocks = do
351351
compiler <- view actualCompilerVersionL
352352
cabalVersion <- view cabalVersionL
353353

@@ -361,8 +361,9 @@ getPrecompiledCacheKey loc copts buildHaddocks = do
361361
-- In Cabal versions 1.22 and later, the configure options contain the
362362
-- installed package IDs, which is what we need for a unique hash. See also
363363
-- issue: https://github.com/commercialhaskell/stack/issues/1103
364-
let input = copts.noDirs
365-
optionsHash = Mem.convert $ hashWith SHA256 $ encodeUtf8 $ tshow input
364+
let optionsToHash = configureOpts.nonPathRelated
365+
optionsHash =
366+
Mem.convert $ hashWith SHA256 $ encodeUtf8 $ tshow optionsToHash
366367

367368
pure $ precompiledCacheKey
368369
platformGhcDir compiler cabalVersion packageKey optionsHash buildHaddocks

src/Stack/Build/ConstructPlan.hs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ import Stack.Types.CompilerPaths
6060
( CompilerPaths (..), HasCompiler (..) )
6161
import Stack.Types.Config ( Config (..), HasConfig (..), stackRootL )
6262
import Stack.Types.ConfigureOpts
63-
( BaseConfigOpts (..), ConfigureOpts (..), configureOpts )
63+
( BaseConfigOpts (..), ConfigureOpts (..) )
64+
import qualified Stack.Types.ConfigureOpts as ConfigureOpts
6465
import Stack.Types.Curator ( Curator (..) )
6566
import Stack.Types.Dependency ( DepValue (..), isDepTypeLibrary )
6667
import Stack.Types.DumpPackage ( DumpPackage (..), dpParentLibIdent )
@@ -440,7 +441,7 @@ addFinal lp package isAllInOne buildHaddocks = do
440441
pure $ Right Task
441442
{ configOpts = TaskConfigOpts missing $ \missing' ->
442443
let allDeps = Map.union present missing'
443-
in configureOpts
444+
in ConfigureOpts.configureOpts
444445
(view envConfigL ctx)
445446
ctx.baseConfigOpts
446447
allDeps
@@ -753,7 +754,7 @@ installPackageGivenDeps isAllInOne buildHaddocks ps package minstalled
753754
Nothing -> ADRToInstall Task
754755
{ configOpts = TaskConfigOpts missing $ \missing' ->
755756
let allDeps = Map.union present missing'
756-
in configureOpts
757+
in ConfigureOpts.configureOpts
757758
(view envConfigL ctx)
758759
ctx.baseConfigOpts
759760
allDeps
@@ -1009,22 +1010,22 @@ checkDirtiness ::
10091010
checkDirtiness ps installed package present buildHaddocks = do
10101011
ctx <- ask
10111012
moldOpts <- runRIO ctx $ tryGetFlagCache installed
1012-
let configOpts = configureOpts
1013+
let configureOpts = ConfigureOpts.configureOpts
10131014
(view envConfigL ctx)
10141015
ctx.baseConfigOpts
10151016
present
10161017
(psLocal ps)
10171018
(installLocationIsMutable $ psLocation ps) -- should be Local i.e. mutable always
10181019
package
1020+
components = case ps of
1021+
PSFilePath lp ->
1022+
Set.map (encodeUtf8 . renderComponent) lp.components
1023+
PSRemote{} -> Set.empty
10191024
wantConfigCache = ConfigCache
1020-
{ opts = configOpts
1025+
{ configureOpts
10211026
, deps = Set.fromList $ Map.elems present
1022-
, components =
1023-
case ps of
1024-
PSFilePath lp ->
1025-
Set.map (encodeUtf8 . renderComponent) lp.components
1026-
PSRemote{} -> Set.empty
1027-
, haddock = buildHaddocks
1027+
, components
1028+
, buildHaddocks
10281029
, pkgSrc = toCachePkgSrc ps
10291030
, pathEnvVar = ctx.pathEnvVar
10301031
}
@@ -1061,7 +1062,7 @@ describeConfigDiff config old new
10611062
| not $ Set.null newComponents =
10621063
Just $ "components added: " `T.append` T.intercalate ", "
10631064
(map (decodeUtf8With lenientDecode) (Set.toList newComponents))
1064-
| not old.haddock && new.haddock =
1065+
| not old.buildHaddocks && new.buildHaddocks =
10651066
Just "rebuilding with haddocks"
10661067
| oldOpts /= newOpts = Just $ T.pack $ concat
10671068
[ "flags changed from "
@@ -1099,7 +1100,7 @@ describeConfigDiff config old new
10991100
else stripGhcOptions)
11001101
. map T.pack
11011102
. (\(ConfigureOpts x y) -> x ++ y)
1102-
. (.opts)
1103+
. (.configureOpts)
11031104
where
11041105
-- options set by Stack
11051106
isStackOpt :: Text -> Bool

src/Stack/Build/ExecutePackage.hs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,19 @@ getConfigCache ee task installedMap enableTest enableBench = do
186186
TaskConfigOpts missing mkOpts = task.configOpts
187187
missingMapList <- traverse getMissing $ toList missing
188188
let missing' = Map.unions missingMapList
189-
opts = mkOpts missing'
190-
allDeps = Set.fromList $ Map.elems missing' ++ Map.elems task.present
189+
configureOpts' = mkOpts missing'
190+
configureOpts = configureOpts'
191+
{ nonPathRelated = configureOpts'.nonPathRelated ++ map T.unpack extra }
192+
deps = Set.fromList $ Map.elems missing' ++ Map.elems task.present
193+
components = case task.taskType of
194+
TTLocalMutable lp ->
195+
Set.map (encodeUtf8 . renderComponent) lp.components
196+
TTRemotePackage{} -> Set.empty
191197
cache = ConfigCache
192-
{ opts = opts { noDirs = opts.noDirs ++ map T.unpack extra }
193-
, deps = allDeps
194-
, components =
195-
case task.taskType of
196-
TTLocalMutable lp ->
197-
Set.map (encodeUtf8 . renderComponent) lp.components
198-
TTRemotePackage{} -> Set.empty
199-
, haddock = task.buildHaddocks
198+
{ configureOpts
199+
, deps
200+
, components
201+
, buildHaddocks = task.buildHaddocks
200202
, pkgSrc = task.cachePkgSrc
201203
, pathEnvVar = ee.pathEnvVar
202204
}
@@ -264,7 +266,6 @@ ensureConfig newConfigCache pkgDir buildOpts announce cabal cabalFP task = do
264266
|| mOldCabalMod /= Just newCabalMod
265267
|| mOldSetupConfigMod /= newSetupConfigMod
266268
|| mOldProjectRoot /= Just newProjectRoot
267-
let ConfigureOpts dirs nodirs = newConfigCache.opts
268269

269270
when task.buildTypeConfig $
270271
-- When build-type is Configure, we need to have a configure script in the
@@ -292,8 +293,8 @@ ensureConfig newConfigCache pkgDir buildOpts announce cabal cabalFP task = do
292293
-- Stack.Types.Build.ureOpts
293294
cabal KeepTHLoading $ "configure" : concat
294295
[ concat exes
295-
, dirs
296-
, nodirs
296+
, newConfigCache.configureOpts.pathRelated
297+
, newConfigCache.configureOpts.nonPathRelated
297298
]
298299
-- Only write the cache for local packages. Remote packages are built in a
299300
-- temporary directory so the cache would never be used anyway.
@@ -685,8 +686,8 @@ singleBuild
685686
writePrecompiledCache
686687
ee.baseConfigOpts
687688
loc
688-
cache.opts
689-
cache.haddock
689+
cache.configureOpts
690+
cache.buildHaddocks
690691
mpkgid
691692
subLibsPkgIds
692693
(buildableExes package)
@@ -762,8 +763,8 @@ getPrecompiled cache taskType bcoSnapInstallRoot =
762763
TTRemotePackage Immutable _ loc -> do
763764
mpc <- readPrecompiledCache
764765
loc
765-
cache.opts
766-
cache.haddock
766+
cache.configureOpts
767+
cache.buildHaddocks
767768
case mpc of
768769
Nothing -> pure Nothing
769770
-- Only pay attention to precompiled caches that refer to packages

src/Stack/Storage/Project.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ readConfigCache ::
115115
-> ReaderT SqlBackend (RIO env) ConfigCache
116116
readConfigCache (Entity parentId configCacheParent) = do
117117
let pkgSrc = configCacheParent.configCacheParentPkgSrc
118-
dirs <-
118+
pathRelated <-
119119
map ((.configCacheDirOptionValue) . entityVal) <$>
120120
selectList
121121
[ConfigCacheDirOptionParent ==. parentId]
122122
[Asc ConfigCacheDirOptionIndex]
123-
noDirs <-
123+
nonPathRelated <-
124124
map ((.configCacheNoDirOptionValue) . entityVal) <$>
125125
selectList
126126
[ConfigCacheNoDirOptionParent ==. parentId]
127127
[Asc ConfigCacheNoDirOptionIndex]
128-
let opts = ConfigureOpts
129-
{ dirs
130-
, noDirs
128+
let configureOpts = ConfigureOpts
129+
{ pathRelated
130+
, nonPathRelated
131131
}
132132
deps <-
133133
Set.fromList . map ((.configCacheDepValue) . entityVal) <$>
@@ -136,12 +136,12 @@ readConfigCache (Entity parentId configCacheParent) = do
136136
Set.fromList . map ((.configCacheComponentValue) . entityVal) <$>
137137
selectList [ConfigCacheComponentParent ==. parentId] []
138138
let pathEnvVar = configCacheParent.configCacheParentPathEnvVar
139-
let haddock = configCacheParent.configCacheParentHaddock
139+
let buildHaddocks = configCacheParent.configCacheParentHaddock
140140
pure ConfigCache
141-
{ opts
141+
{ configureOpts
142142
, deps
143143
, components
144-
, haddock
144+
, buildHaddocks
145145
, pkgSrc
146146
, pathEnvVar
147147
}
@@ -181,7 +181,7 @@ saveConfigCache key@(UniqueConfigCacheParent dir type_) new =
181181
, configCacheParentPkgSrc = new.pkgSrc
182182
, configCacheParentActive = True
183183
, configCacheParentPathEnvVar = new.pathEnvVar
184-
, configCacheParentHaddock = new.haddock
184+
, configCacheParentHaddock = new.buildHaddocks
185185
}
186186
Just parentEntity@(Entity parentId _) -> do
187187
old <- readConfigCache parentEntity
@@ -197,15 +197,15 @@ saveConfigCache key@(UniqueConfigCacheParent dir type_) new =
197197
ConfigCacheDirOptionParent
198198
parentId
199199
ConfigCacheDirOptionIndex
200-
(maybe [] (.opts.dirs) mold)
201-
new.opts.dirs
200+
(maybe [] (.configureOpts.pathRelated) mold)
201+
new.configureOpts.pathRelated
202202
updateList
203203
ConfigCacheNoDirOption
204204
ConfigCacheNoDirOptionParent
205205
parentId
206206
ConfigCacheNoDirOptionIndex
207-
(maybe [] (.opts.noDirs) mold)
208-
new.opts.noDirs
207+
(maybe [] (.configureOpts.nonPathRelated) mold)
208+
new.configureOpts.nonPathRelated
209209
updateSet
210210
ConfigCacheDep
211211
ConfigCacheDepParent

src/Stack/Types/Build.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ instance NFData BuildCache
8484

8585
-- | Stored on disk to know whether the flags have changed.
8686
data ConfigCache = ConfigCache
87-
{ opts :: !ConfigureOpts
88-
-- ^ All options used for this package.
87+
{ configureOpts :: !ConfigureOpts
88+
-- ^ All Cabal configure options used for this package.
8989
, deps :: !(Set GhcPkgId)
9090
-- ^ The GhcPkgIds of all of the dependencies. Since Cabal doesn't take
9191
-- the complete GhcPkgId (only a PackageIdentifier) in the configure
@@ -95,7 +95,7 @@ data ConfigCache = ConfigCache
9595
-- ^ The components to be built. It's a bit of a hack to include this in
9696
-- here, as it's not a configure option (just a build option), but this
9797
-- is a convenient way to force compilation when the components change.
98-
, haddock :: !Bool
98+
, buildHaddocks :: !Bool
9999
-- ^ Are haddocks to be built?
100100
, pkgSrc :: !CachePkgSrc
101101
, pathEnvVar :: !Text

src/Stack/Types/ConfigureOpts.hs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ module Stack.Types.ConfigureOpts
77
( ConfigureOpts (..)
88
, BaseConfigOpts (..)
99
, configureOpts
10-
, configureOptsDirs
11-
, configureOptsNoDir
10+
, configureOptsPathRelated
11+
, configureOptsNonPathRelated
1212
) where
1313

1414
import qualified Data.Map as Map
@@ -50,24 +50,26 @@ data BaseConfigOpts = BaseConfigOpts
5050
deriving Show
5151

5252
-- | Render a @BaseConfigOpts@ to an actual list of options
53-
configureOpts :: EnvConfig
54-
-> BaseConfigOpts
55-
-> Map PackageIdentifier GhcPkgId -- ^ dependencies
56-
-> Bool -- ^ local non-extra-dep?
57-
-> IsMutable
58-
-> Package
59-
-> ConfigureOpts
53+
configureOpts ::
54+
EnvConfig
55+
-> BaseConfigOpts
56+
-> Map PackageIdentifier GhcPkgId -- ^ dependencies
57+
-> Bool -- ^ local non-extra-dep?
58+
-> IsMutable
59+
-> Package
60+
-> ConfigureOpts
6061
configureOpts econfig bco deps isLocal isMutable package = ConfigureOpts
61-
{ dirs = configureOptsDirs bco isMutable package
62-
, noDirs = configureOptsNoDir econfig bco deps isLocal package
62+
{ pathRelated = configureOptsPathRelated bco isMutable package
63+
, nonPathRelated =
64+
configureOptsNonPathRelated econfig bco deps isLocal package
6365
}
6466

65-
66-
configureOptsDirs :: BaseConfigOpts
67-
-> IsMutable
68-
-> Package
69-
-> [String]
70-
configureOptsDirs bco isMutable package = concat
67+
configureOptsPathRelated ::
68+
BaseConfigOpts
69+
-> IsMutable
70+
-> Package
71+
-> [String]
72+
configureOptsPathRelated bco isMutable package = concat
7173
[ ["--user", "--package-db=clear", "--package-db=global"]
7274
, map (("--package-db=" ++) . toFilePathNoTrailingSep) $ case isMutable of
7375
Immutable -> bco.extraDBs ++ [bco.snapDB]
@@ -97,14 +99,14 @@ configureOptsDirs bco isMutable package = concat
9799
)
98100

99101
-- | Same as 'configureOpts', but does not include directory path options
100-
configureOptsNoDir ::
102+
configureOptsNonPathRelated ::
101103
EnvConfig
102104
-> BaseConfigOpts
103105
-> Map PackageIdentifier GhcPkgId -- ^ Dependencies.
104106
-> Bool -- ^ Is this a local, non-extra-dep?
105107
-> Package
106108
-> [String]
107-
configureOptsNoDir econfig bco deps isLocal package = concat
109+
configureOptsNonPathRelated econfig bco deps isLocal package = concat
108110
[ depOptions
109111
, [ "--enable-library-profiling"
110112
| bopts.libProfile || bopts.exeProfile
@@ -192,13 +194,14 @@ configureOptsNoDir econfig bco deps isLocal package = concat
192194
LSubLibName cn ->
193195
unPackageName subPkgName <> ":" <> unUnqualComponentName cn
194196

195-
-- | Configure options to be sent to Setup.hs configure
197+
-- | Configure options to be sent to Setup.hs configure.
196198
data ConfigureOpts = ConfigureOpts
197-
{ dirs :: ![String]
199+
{ pathRelated :: ![String]
198200
-- ^ Options related to various paths. We separate these out since they do
199-
-- not have an impact on the contents of the compiled binary for checking
201+
-- not have an effect on the contents of the compiled binary for checking
200202
-- if we can use an existing precompiled cache.
201-
, noDirs :: ![String]
203+
, nonPathRelated :: ![String]
204+
-- ^ Options other than path-related options.
202205
}
203206
deriving (Data, Eq, Generic, Show, Typeable)
204207

0 commit comments

Comments
 (0)