Skip to content

Commit 1d99fee

Browse files
committed
Reformatting, for consistency
1 parent b5e5cb5 commit 1d99fee

17 files changed

+230
-159
lines changed

.stan.toml

+11-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
id = "OBS-STAN-0102-luLR/n-522:30"
2929
# ✦ Category: #Infinite #List
3030
# ✦ File: src\Stack\New.hs
31+
#
3132
# 522 ┃
3233
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
3334
# 524 ┃ ^^^^^^^^^^^^^^
@@ -38,6 +39,7 @@
3839
id = "OBS-STAN-0102-luLR/n-522:65"
3940
# ✦ Category: #Infinite #List
4041
# ✦ File: src\Stack\New.hs
42+
#
4143
# 522 ┃
4244
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
4345
# 524 ┃ ^^^^^^^^^^^^^^
@@ -52,32 +54,33 @@
5254

5355
# Anti-pattern: Data.ByteString.Char8.pack
5456
[[ignore]]
55-
id = "OBS-STAN-0203-fki0nd-1127:21"
57+
id = "OBS-STAN-0203-fki0nd-1128:21"
5658
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
5759
# ✦ Category: #AntiPattern
5860
# ✦ File: src\Stack\Build\Execute.hs
5961
#
60-
# 1126
61-
# 1127 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
62-
# 1128 ┃ ^^^^^^^
62+
# 1127
63+
# 1128 ┃ newProjectRoot <- S8.pack . toFilePath <$> view projectRootL
64+
# 1129 ┃ ^^^^^^^
6365

6466
# Anti-pattern: Data.ByteString.Char8.pack
6567
[[ignore]]
66-
id = "OBS-STAN-0203-fki0nd-2669:3"
68+
id = "OBS-STAN-0203-fki0nd-2672:3"
6769
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
6870
# ✦ Category: #AntiPattern
6971
# ✦ File: src\Stack\Build\Execute.hs
7072
#
71-
# 2668
72-
# 2669 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
73-
# 2670 ┃ ^^^^^^^
73+
# 2671
74+
# 2672 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
75+
# 2673 ┃ ^^^^^^^
7476

7577
# Anti-pattern: Data.ByteString.Char8.pack
7678
[[ignore]]
7779
id = "OBS-STAN-0203-hTeu0Y-380:17"
7880
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
7981
# ✦ Category: #AntiPattern
8082
# ✦ File: src\Stack\Init.hs
83+
#
8184
# 378 ┃
8285
# 379 ┃ commentHelp = BC.pack . intercalate "\n" . map commentLine
8386
# 380 ┃ ^^^^^^^

package.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ library:
265265
- Stack.Types.ApplyGhcOptions
266266
- Stack.Types.ApplyProgOptions
267267
- Stack.Types.Build
268+
- Stack.Types.Build.ConstructPlan
268269
- Stack.Types.Build.Exception
269270
- Stack.Types.BuildConfig
270271
- Stack.Types.BuildOpts
@@ -277,6 +278,7 @@ library:
277278
- Stack.Types.CompilerPaths
278279
- Stack.Types.Compiler
279280
- Stack.Types.Component
281+
- Stack.Types.ComponentUtils
280282
- Stack.Types.Config
281283
- Stack.Types.Config.Exception
282284
- Stack.Types.ConfigMonoid

src/Stack/Build.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ import Stack.Types.GlobalOpts ( globalOptsBuildOptsMonoidL )
6262
import Stack.Types.NamedComponent ( exeComponents )
6363
import Stack.Types.Package
6464
( InstallLocation (..), LocalPackage (..), Package (..)
65-
, PackageConfig (..), lpFiles, lpFilesForComponents )
65+
, PackageConfig (..), lpFiles, lpFilesForComponents
66+
)
6667
import Stack.Types.Platform ( HasPlatform (..) )
6768
import Stack.Types.Runner ( Runner, globalOptsL )
6869
import Stack.Types.SourceMap

src/Stack/Build/Cache.hs

+35-28
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ import Stack.Types.EnvConfig
7272
)
7373
import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdString )
7474
import Stack.Types.NamedComponent ( NamedComponent (..) )
75+
import Stack.Types.Package
76+
(InstalledLibraryInfo (..), installedGhcPkgId )
7577
import Stack.Types.SourceMap ( smRelDir )
7678
import System.PosixCompat.Files
7779
( modificationTime, getFileStatus, setFileTimes )
78-
import Stack.Types.Package (installedGhcPkgId, InstalledLibraryInfo (iliId))
7980

8081
-- | Directory containing files to mark an executable as installed
8182
exeInstalledDir :: (HasEnvConfig env)
@@ -265,13 +266,9 @@ flagCacheKey installed = do
265266
case installed of
266267
Library _ installedInfo -> do
267268
let gid = iliId installedInfo
268-
pure $
269-
configCacheKey installationRoot (ConfigCacheTypeFlagLibrary gid)
270-
Executable ident ->
271-
pure $
272-
configCacheKey
273-
installationRoot
274-
(ConfigCacheTypeFlagExecutable ident)
269+
pure $ configCacheKey installationRoot (ConfigCacheTypeFlagLibrary gid)
270+
Executable ident -> pure $
271+
configCacheKey installationRoot (ConfigCacheTypeFlagExecutable ident)
275272

276273
-- | Loads the flag cache for the given installed extra-deps
277274
tryGetFlagCache :: HasEnvConfig env
@@ -380,26 +377,36 @@ writePrecompiledCache ::
380377
-> [GhcPkgId] -- ^ sub-libraries, in the GhcPkgId format
381378
-> Set Text -- ^ executables
382379
-> RIO env ()
383-
writePrecompiledCache baseConfigOpts loc copts buildHaddocks mghcPkgId subLibs exes = do
384-
key <- getPrecompiledCacheKey loc copts buildHaddocks
385-
ec <- view envConfigL
386-
let stackRootRelative = makeRelative (view stackRootL ec)
387-
mlibpath <- traverse (pathFromPkgId stackRootRelative) (installedGhcPkgId mghcPkgId)
388-
subLibPaths <- mapM (pathFromPkgId stackRootRelative) subLibs
389-
exes' <- forM (Set.toList exes) $ \exe -> do
390-
name <- parseRelFile $ T.unpack exe
391-
stackRootRelative $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
392-
let precompiled = PrecompiledCache
393-
{ pcLibrary = mlibpath
394-
, pcSubLibs = subLibPaths
395-
, pcExes = exes'
396-
}
397-
savePrecompiledCache key precompiled
398-
-- reuse precompiled cache with haddocks also in case when haddocks are not
399-
-- required
400-
when buildHaddocks $ do
401-
key' <- getPrecompiledCacheKey loc copts False
402-
savePrecompiledCache key' precompiled
380+
writePrecompiledCache
381+
baseConfigOpts
382+
loc
383+
copts
384+
buildHaddocks
385+
mghcPkgId
386+
subLibs
387+
exes
388+
= do
389+
key <- getPrecompiledCacheKey loc copts buildHaddocks
390+
ec <- view envConfigL
391+
let stackRootRelative = makeRelative (view stackRootL ec)
392+
mlibpath <-
393+
traverse (pathFromPkgId stackRootRelative) (installedGhcPkgId mghcPkgId)
394+
subLibPaths <- mapM (pathFromPkgId stackRootRelative) subLibs
395+
exes' <- forM (Set.toList exes) $ \exe -> do
396+
name <- parseRelFile $ T.unpack exe
397+
stackRootRelative $
398+
bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
399+
let precompiled = PrecompiledCache
400+
{ pcLibrary = mlibpath
401+
, pcSubLibs = subLibPaths
402+
, pcExes = exes'
403+
}
404+
savePrecompiledCache key precompiled
405+
-- reuse precompiled cache with haddocks also in case when haddocks are
406+
-- not required
407+
when buildHaddocks $ do
408+
key' <- getPrecompiledCacheKey loc copts False
409+
savePrecompiledCache key' precompiled
403410
where
404411
pathFromPkgId stackRootRelative ipid = do
405412
ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf"

src/Stack/Build/ConstructPlan.hs

+18-14
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import Stack.Build.Haddock ( shouldHaddockDeps )
2727
import Stack.Build.Source ( loadLocalPackage )
2828
import Stack.Constants ( compilerOptionsCabalFlag )
2929
import Stack.Package
30-
( applyForceCustomBuild, buildableExes
31-
, packageUnknownTools, processPackageDepsToList
30+
( applyForceCustomBuild, buildableExes, packageUnknownTools
31+
, processPackageDepsToList
3232
)
3333
import Stack.Prelude hiding ( loadPackage )
3434
import Stack.SourceMap ( getPLIVersion, mkProjectPackage )
@@ -38,6 +38,11 @@ import Stack.Types.Build
3838
, installLocationIsMutable, taskIsTarget, taskLocation
3939
, taskProvides, taskTargetIsMutable, toCachePkgSrc
4040
)
41+
import Stack.Types.Build.ConstructPlan
42+
( AddDepRes (..), CombinedMap, Ctx (..), M, NotOnlyLocal (..)
43+
, PackageInfo (..), ToolWarning(..), UnregisterState (..)
44+
, W (..), adrHasLibrary, adrVersion, toTask
45+
)
4146
import Stack.Types.Build.Exception
4247
( BadDependency (..), BuildException (..)
4348
, BuildPrettyException (..), ConstructPlanException (..)
@@ -53,16 +58,10 @@ import Stack.Types.CompilerPaths
5358
import Stack.Types.Config ( Config (..), HasConfig (..), stackRootL )
5459
import Stack.Types.ConfigureOpts
5560
( BaseConfigOpts (..), ConfigureOpts (..), configureOpts )
56-
import Stack.Types.Build.ConstructPlan
57-
( UnregisterState(..), NotOnlyLocal(NotOnlyLocal), ToolWarning(..),
58-
Ctx(..), M, CombinedMap, AddDepRes(..),
59-
W(..), PackageInfo(..), toTask, adrVersion, adrHasLibrary
60-
)
6161
import Stack.Types.Curator ( Curator (..) )
6262
import Stack.Types.Dependency ( DepValue (..), isDepTypeLibrary )
6363
import Stack.Types.DumpPackage ( DumpPackage (..), dpParentLibIdent )
64-
import Stack.Types.EnvConfig
65-
( EnvConfig (..), HasEnvConfig (..) )
64+
import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..) )
6665
import Stack.Types.EnvSettings
6766
( EnvSettings (..), minimalEnvSettings )
6867
import Stack.Types.GhcPkgId ( GhcPkgId )
@@ -72,8 +71,8 @@ import Stack.Types.NamedComponent ( exeComponents, renderComponent )
7271
import Stack.Types.Package
7372
( ExeName (..), InstallLocation (..), Installed (..)
7473
, InstalledMap, LocalPackage (..), Package (..)
75-
, PackageSource (..), installedVersion, packageIdentifier
76-
, psVersion, runMemoizedWith, installedMapGhcPkgId
74+
, PackageSource (..), installedMapGhcPkgId, installedVersion
75+
, packageIdentifier, psVersion, runMemoizedWith
7776
)
7877
import Stack.Types.ProjectConfig ( isPCGlobalProject )
7978
import Stack.Types.Runner ( HasRunner (..), globalOptsL )
@@ -82,7 +81,9 @@ import Stack.Types.SourceMap
8281
, GlobalPackage (..), SMTargets (..), SourceMap (..)
8382
)
8483
import Stack.Types.Version
85-
( latestApplicableVersion, versionRangeText, withinRange, VersionRange )
84+
( VersionRange, latestApplicableVersion, versionRangeText
85+
, withinRange
86+
)
8687
import System.Environment ( lookupEnv )
8788

8889
-- | Computes a build plan. This means figuring out which build 'Task's to take,
@@ -986,7 +987,10 @@ processAdr adr = case adr of
986987
ADRFound loc (Executable _) ->
987988
(Set.empty, Map.empty, installLocationIsMutable loc)
988989
ADRFound loc (Library ident installedInfo) ->
989-
(Set.empty, installedMapGhcPkgId ident installedInfo, installLocationIsMutable loc)
990+
( Set.empty
991+
, installedMapGhcPkgId ident installedInfo
992+
, installLocationIsMutable loc
993+
)
990994

991995
checkDirtiness ::
992996
PackageSource
@@ -1235,4 +1239,4 @@ combineMap :: Map PackageName PackageSource -> InstalledMap -> CombinedMap
12351239
combineMap = Map.merge
12361240
(Map.mapMissing (\_ s -> PIOnlySource s))
12371241
(Map.mapMissing (\_ i -> uncurry PIOnlyInstalled i))
1238-
(Map.zipWithMatched (\_ s i -> combineSourceInstalled s i))
1242+
(Map.zipWithMatched (\_ s i -> combineSourceInstalled s i))

src/Stack/Build/Execute.hs

+7-5
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ import Stack.Types.BuildOpts
150150
)
151151
import Stack.Types.CompCollection
152152
( collectionKeyValueList, collectionLookup
153-
, getBuildableListText, getBuildableListAs
153+
, getBuildableListAs, getBuildableListText
154154
)
155155
import Stack.Types.Compiler
156156
( ActualCompiler (..), WhichCompiler (..)
@@ -184,10 +184,12 @@ import Stack.Types.NamedComponent
184184
, isCTest, renderComponent, testComponents
185185
)
186186
import Stack.Types.Package
187-
( InstallLocation (..), Installed (..), InstalledMap
188-
, LocalPackage (..), Package (..), InstalledLibraryInfo (..)
189-
, installedPackageIdentifier, packageIdentifier, runMemoizedWith
190-
, installedMapGhcPkgId, toCabalMungedPackageName, simpleInstalledLib
187+
( InstallLocation (..), Installed (..)
188+
, InstalledLibraryInfo (..), InstalledMap, LocalPackage (..)
189+
, Package (..), installedMapGhcPkgId
190+
, installedPackageIdentifier, packageIdentifier
191+
, runMemoizedWith, simpleInstalledLib
192+
, toCabalMungedPackageName
191193
)
192194
import Stack.Types.PackageFile ( PackageWarning (..) )
193195
import Stack.Types.Platform ( HasPlatform (..) )

src/Stack/Build/Installed.hs

+41-25
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Stack.Build.Installed
1010

1111
import Data.Conduit ( ZipSink (..), getZipSink )
1212
import qualified Data.Conduit.List as CL
13+
import Data.Foldable ( Foldable (..) )
1314
import qualified Data.Set as Set
1415
import qualified Data.Map.Strict as Map
1516
import Stack.Build.Cache ( getInstalledExes )
@@ -19,21 +20,23 @@ import Stack.PackageDump
1920
import Stack.Prelude
2021
import Stack.SourceMap ( getPLIVersion, loadVersion )
2122
import Stack.Types.CompilerPaths ( getGhcPkgExe )
22-
import Stack.Types.DumpPackage ( DumpPackage (..), dpParentLibIdent, SublibDump (..), sdPackageName )
23+
import Stack.Types.DumpPackage
24+
( DumpPackage (..), SublibDump (..), dpParentLibIdent
25+
, sdPackageName
26+
)
2327
import Stack.Types.EnvConfig
2428
( HasEnvConfig, packageDatabaseDeps, packageDatabaseExtra
2529
, packageDatabaseLocal
2630
)
2731
import Stack.Types.GhcPkgId ( GhcPkgId )
2832
import Stack.Types.Package
2933
( InstallLocation (..), InstallMap, Installed (..)
30-
, InstalledMap, InstalledPackageLocation (..)
31-
, PackageDatabase (..), PackageDbVariety (..)
32-
, toPackageDbVariety, InstalledLibraryInfo (InstalledLibraryInfo, iliSublib, iliId)
34+
, InstalledLibraryInfo (..), InstalledMap
35+
, InstalledPackageLocation (..), PackageDatabase (..)
36+
, PackageDbVariety (..), toPackageDbVariety
3337
)
3438
import Stack.Types.SourceMap
3539
( DepPackage (..), ProjectPackage (..), SourceMap (..) )
36-
import Data.Foldable (Foldable(..))
3740

3841
toInstallMap :: MonadIO m => SourceMap -> m InstallMap
3942
toInstallMap sourceMap = do
@@ -76,7 +79,8 @@ getInstalled {-opts-} installMap = do
7679
loadDatabase' (UserPkgDb (InstalledTo Snap) snapDBPath) installedLibs1
7780
(installedLibs3, localDumpPkgs) <-
7881
loadDatabase' (UserPkgDb (InstalledTo Local) localDBPath) installedLibs2
79-
let installedLibs = foldr' gatherAndTransformSubLoadHelper mempty installedLibs3
82+
let installedLibs =
83+
foldr' gatherAndTransformSubLoadHelper mempty installedLibs3
8084

8185
-- Add in the executables that are installed, making sure to only trust a
8286
-- listed installation under the right circumstances (see below)
@@ -280,27 +284,39 @@ toLoadHelper pkgDb dp = LoadHelper
280284
toInstallLocation WriteOnlyDb = Snap
281285
toInstallLocation MutableDb = Local
282286

283-
-- | This is where sublibraries and main libraries are assembled into
284-
-- a single entity Installed package, where all ghcPkgId live.
287+
-- | This is where sublibraries and main libraries are assembled into a single
288+
-- entity Installed package, where all ghcPkgId live.
285289
gatherAndTransformSubLoadHelper ::
286-
LoadHelper
290+
LoadHelper
287291
-> Map PackageName (InstallLocation, Installed)
288292
-> Map PackageName (InstallLocation, Installed)
289293
gatherAndTransformSubLoadHelper lh =
290294
Map.insertWith onPreviousLoadHelper key value
291-
where
292-
-- here we assume that both have the same location
293-
-- which already was a prior assumption in stack
294-
onPreviousLoadHelper (pLoc, Library pn incomingLibInfo) (_, Library _ existingLibInfo) =
295-
(pLoc, Library pn existingLibInfo{
296-
iliSublib=Map.union (iliSublib incomingLibInfo) (iliSublib existingLibInfo),
297-
iliId=if isJust $ lhSublibrary lh then iliId existingLibInfo else iliId incomingLibInfo
298-
})
299-
onPreviousLoadHelper newVal _oldVal = newVal
300-
(key, value) = case lhSublibrary lh of
301-
Nothing -> (rawPackageName, rawValue)
302-
Just sd -> (sdPackageName sd, updateAsSublib sd <$> rawValue)
303-
(rawPackageName, rawValue) = lhPair lh
304-
updateAsSublib sd (Library (PackageIdentifier _sublibMungedPackageName version) libInfo) =
305-
Library (PackageIdentifier key version) libInfo{iliSublib=Map.singleton (sdLibraryName sd) (iliId libInfo)}
306-
updateAsSublib _ v = v
295+
where
296+
-- Here we assume that both have the same location which already was a prior
297+
-- assumption in Stack.
298+
onPreviousLoadHelper
299+
(pLoc, Library pn incomingLibInfo)
300+
(_, Library _ existingLibInfo)
301+
= ( pLoc
302+
, Library pn existingLibInfo
303+
{ iliSublib = Map.union
304+
(iliSublib incomingLibInfo)
305+
(iliSublib existingLibInfo)
306+
, iliId = if isJust $ lhSublibrary lh
307+
then iliId existingLibInfo
308+
else iliId incomingLibInfo
309+
}
310+
)
311+
onPreviousLoadHelper newVal _oldVal = newVal
312+
(key, value) = case lhSublibrary lh of
313+
Nothing -> (rawPackageName, rawValue)
314+
Just sd -> (sdPackageName sd, updateAsSublib sd <$> rawValue)
315+
(rawPackageName, rawValue) = lhPair lh
316+
updateAsSublib
317+
sd
318+
(Library (PackageIdentifier _sublibMungedPackageName version) libInfo)
319+
= Library
320+
(PackageIdentifier key version)
321+
libInfo {iliSublib = Map.singleton (sdLibraryName sd) (iliId libInfo)}
322+
updateAsSublib _ v = v

src/Stack/Package.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ import Stack.Types.Package
9999
( BioInput(..), BuildInfoOpts (..), InstallMap
100100
, Installed (..), InstalledMap, Package (..)
101101
, PackageConfig (..), PackageException (..)
102-
, dotCabalCFilePath, packageIdentifier, installedToPackageIdOpt
102+
, dotCabalCFilePath, installedToPackageIdOpt
103+
, packageIdentifier
103104
)
104105
import Stack.Types.PackageFile
105106
( DotCabalPath, PackageComponentFile (..) )

0 commit comments

Comments
 (0)