Skip to content

Commit fa9c76c

Browse files
authored
Merge pull request #6614 from theobat/refactoring-toward-cabal
Refactoring toward cabal
2 parents 8e78b78 + fa82e63 commit fa9c76c

31 files changed

+343
-243
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-234:24"
86+
id = "OBS-STAN-0203-tuE+RG-236:24"
8787
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
8888
# ✦ Category: #AntiPattern
8989
# ✦ File: src\Stack\Build\ExecutePackage.hs
9090
#
91-
# 233
92-
# 234 ┃ newConfigFileRoot <- S8.pack . toFilePath <$> view configFileRootL
93-
# 235 ┃ ^^^^^^^
91+
# 235
92+
# 236 ┃ newConfigFileRoot <- S8.pack . toFilePath <$> view configFileRootL
93+
# 237 ┃ ^^^^^^^
9494

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

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ dependencies:
8383
- fsnotify >= 0.4.1
8484
- generic-deriving
8585
- ghc-boot
86+
- hashable
8687
- hi-file-parser >= 0.1.6.0
8788
- hpack >= 0.36.0
8889
- hpc

src/Path/CheckInstall.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Path.CheckInstall
66
) where
77

88
import Control.Monad.Extra ( (&&^), anyM )
9-
import qualified Data.Text as T
109
import Stack.Prelude
1110
import Stack.Types.Config ( HasConfig )
1211
import qualified System.Directory as D
@@ -15,7 +14,11 @@ import qualified System.FilePath as FP
1514
-- | Checks if the installed executable will be available on the user's PATH.
1615
-- This doesn't use @envSearchPath menv@ because it includes paths only visible
1716
-- when running in the Stack environment.
18-
warnInstallSearchPathIssues :: HasConfig env => FilePath -> [Text] -> RIO env ()
17+
warnInstallSearchPathIssues ::
18+
HasConfig env
19+
=> FilePath
20+
-> [String]
21+
-> RIO env ()
1922
warnInstallSearchPathIssues destDir installed = do
2023
searchPath <- liftIO FP.getSearchPath
2124
destDirIsInPATH <- liftIO $
@@ -26,28 +29,28 @@ warnInstallSearchPathIssues destDir installed = do
2629
searchPath
2730
if destDirIsInPATH
2831
then forM_ installed $ \exe -> do
29-
mexePath <- (liftIO . D.findExecutable . T.unpack) exe
32+
mexePath <- (liftIO . D.findExecutable) exe
3033
case mexePath of
3134
Just exePath -> do
3235
exeDir <-
3336
(liftIO . fmap FP.takeDirectory . D.canonicalizePath) exePath
3437
unless (exeDir `FP.equalFilePath` destDir) $
3538
prettyWarnL
3639
[ flow "The"
37-
, style File . fromString . T.unpack $ exe
40+
, style File . fromString $ exe
3841
, flow "executable found on the PATH environment variable is"
3942
, style File . fromString $ exePath
4043
, flow "and not the version that was just installed."
4144
, flow "This means that"
42-
, style File . fromString . T.unpack $ exe
45+
, style File . fromString $ exe
4346
, "calls on the command line will not use this version."
4447
]
4548
Nothing ->
4649
prettyWarnL
4750
[ flow "Installation path"
4851
, style Dir . fromString $ destDir
4952
, flow "is on the PATH but the"
50-
, style File . fromString . T.unpack $ exe
53+
, style File . fromString $ exe
5154
, flow "executable that was just installed could not be found on \
5255
\the PATH."
5356
]

src/Stack/Build.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import Data.List ( (\\) )
2020
import Data.List.Extra ( groupSort )
2121
import qualified Data.Map as Map
2222
import qualified Data.Set as Set
23-
import qualified Data.Text as T
2423
-- import qualified Distribution.PackageDescription as C
2524
-- import Distribution.Types.Dependency ( Dependency (..), depLibraries )
2625
import Distribution.Version ( mkVersion )
@@ -52,9 +51,10 @@ import Stack.Types.BuildOptsMonoid
5251
)
5352
import Stack.Types.Compiler ( getGhcVersion )
5453
import Stack.Types.CompilerPaths ( HasCompiler, cabalVersionL )
54+
import Stack.Types.ComponentUtils
55+
( StackUnqualCompName, unqualCompToString )
5556
import Stack.Types.Config
56-
( Config (..), HasConfig (..), buildOptsL
57-
)
57+
( Config (..), HasConfig (..), buildOptsL )
5858
import Stack.Types.ConfigureOpts ( BaseConfigOpts (..) )
5959
import Stack.Types.EnvConfig
6060
( EnvConfig (..), HasEnvConfig (..), HasSourceMap
@@ -266,7 +266,7 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
266266
","
267267
[ style
268268
PkgComponent
269-
(fromString $ packageNameString p <> ":" <> T.unpack exe)
269+
(fromString $ packageNameString p <> ":" <> unqualCompToString exe)
270270
| p <- pkgs
271271
]
272272
prettyWarnL $
@@ -295,7 +295,7 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
295295
-- , package names for other project packages that have an
296296
-- executable with the same name
297297
-- )
298-
warnings :: Map Text ([PackageName],[PackageName])
298+
warnings :: Map StackUnqualCompName ([PackageName],[PackageName])
299299
warnings =
300300
Map.mapMaybe
301301
(\(pkgsToBuild, localPkgs) ->
@@ -315,15 +315,15 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
315315
-- Both cases warrant a warning.
316316
Just (NE.toList pkgsToBuild, otherLocals))
317317
(Map.intersectionWith (,) exesToBuild localExes)
318-
exesToBuild :: Map Text (NonEmpty PackageName)
318+
exesToBuild :: Map StackUnqualCompName (NonEmpty PackageName)
319319
exesToBuild =
320320
collect
321321
[ (exe, pkgName')
322322
| (pkgName', task) <- Map.toList plan.tasks
323323
, TTLocalMutable lp <- [task.taskType]
324324
, exe <- (Set.toList . exeComponents . (.components)) lp
325325
]
326-
localExes :: Map Text (NonEmpty PackageName)
326+
localExes :: Map StackUnqualCompName (NonEmpty PackageName)
327327
localExes =
328328
collect
329329
[ (exe, pkg.name)

src/Stack/Build/Cache.hs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import qualified Data.ByteArray as Mem ( convert )
3535
import Data.ByteString.Builder ( byteString )
3636
import qualified Data.Map as M
3737
import qualified Data.Set as Set
38-
import qualified Data.Text as T
3938
import qualified Data.Yaml as Yaml
4039
import Foreign.C.Types ( CTime )
4140
import Path ( (</>), filename, parent, parseRelFile )
@@ -63,6 +62,8 @@ import Stack.Types.Build
6362
)
6463
import Stack.Types.Cache ( ConfigCacheType (..) )
6564
import Stack.Types.CompilerPaths ( cabalVersionL )
65+
import Stack.Types.ComponentUtils
66+
( StackUnqualCompName, unqualCompToString )
6667
import Stack.Types.Config ( stackRootL )
6768
import Stack.Types.ConfigureOpts
6869
( BaseConfigOpts (..), ConfigureOpts (..) )
@@ -74,10 +75,11 @@ import Stack.Types.EnvConfig
7475
import Stack.Types.GhcPkgId ( ghcPkgIdString )
7576
import Stack.Types.Installed
7677
(InstalledLibraryInfo (..), foldOnGhcPkgId' )
77-
import Stack.Types.NamedComponent ( NamedComponent (..) )
78+
import Stack.Types.NamedComponent
79+
( NamedComponent (..), componentCachePath )
7880
import Stack.Types.SourceMap ( smRelDir )
7981
import System.PosixCompat.Files
80-
( modificationTime, getFileStatus, setFileTimes )
82+
( getFileStatus, modificationTime, setFileTimes )
8183

8284
-- | Directory containing files to mark an executable as installed
8385
exeInstalledDir :: (HasEnvConfig env)
@@ -134,14 +136,7 @@ buildCacheFile dir component = do
134136
cachesDir <- buildCachesDir dir
135137
smh <- view $ envConfigL . to (.sourceMapHash)
136138
smDirName <- smRelDir smh
137-
let nonLibComponent prefix name = prefix <> "-" <> T.unpack name
138-
cacheFileName <- parseRelFile $ case component of
139-
CLib -> "lib"
140-
CSubLib name -> nonLibComponent "sub-lib" name
141-
CFlib name -> nonLibComponent "flib" name
142-
CExe name -> nonLibComponent "exe" name
143-
CTest name -> nonLibComponent "test" name
144-
CBench name -> nonLibComponent "bench" name
139+
cacheFileName <- parseRelFile $ componentCachePath component
145140
pure $ cachesDir </> smDirName </> cacheFileName
146141

147142
-- | Try to read the dirtiness cache for the given package directory.
@@ -376,7 +371,7 @@ writePrecompiledCache ::
376371
-> ConfigureOpts
377372
-> Bool -- ^ build haddocks
378373
-> Installed -- ^ library
379-
-> Set Text -- ^ executables
374+
-> Set StackUnqualCompName -- ^ executables
380375
-> RIO env ()
381376
writePrecompiledCache
382377
baseConfigOpts
@@ -390,7 +385,7 @@ writePrecompiledCache
390385
ec <- view envConfigL
391386
let stackRootRelative = makeRelative (view stackRootL ec)
392387
exes' <- forM (Set.toList exes) $ \exe -> do
393-
name <- parseRelFile $ T.unpack exe
388+
name <- parseRelFile $ unqualCompToString exe
394389
stackRootRelative $
395390
baseConfigOpts.snapInstallRoot </> bindirSuffix </> name
396391
let installedLibToPath libName ghcPkgId pcAction = do

src/Stack/Build/ConstructPlan.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Stack.Types.CompCollection ( collectionMember )
5959
import Stack.Types.Compiler ( WhichCompiler (..) )
6060
import Stack.Types.CompilerPaths
6161
( CompilerPaths (..), HasCompiler (..) )
62+
import Stack.Types.ComponentUtils ( unqualCompFromText )
6263
import Stack.Types.Config ( Config (..), HasConfig (..), stackRootL )
6364
import Stack.Types.ConfigureOpts ( BaseConfigOpts (..) )
6465
import qualified Stack.Types.ConfigureOpts as ConfigureOpts
@@ -1182,7 +1183,8 @@ checkAndWarnForUnknownTools p = do
11821183
-- From Cabal 1.12, build-tools can specify another executable in the same
11831184
-- package.
11841185
notPackageExe toolName =
1185-
MaybeT $ skipIf $ collectionMember toolName p.executables
1186+
MaybeT $ skipIf $
1187+
collectionMember (unqualCompFromText toolName) p.executables
11861188
warn name = MaybeT . pure . Just $ ToolWarning (ExeName name) p.name
11871189
skipIf p' = pure $ if p' then Nothing else Just ()
11881190

src/Stack/Build/Execute.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import Stack.Types.BuildOptsCLI ( BuildOptsCLI (..) )
6464
import Stack.Types.BuildOptsMonoid ( ProgressBarFormat (..) )
6565
import Stack.Types.Compiler ( ActualCompiler (..) )
6666
import Stack.Types.CompilerPaths ( HasCompiler (..), getGhcPkgExe )
67+
import Stack.Types.ComponentUtils
68+
( StackUnqualCompName, unqualCompToString )
6769
import Stack.Types.Config
6870
( Config (..), HasConfig (..), buildOptsL )
6971
import Stack.Types.ConfigureOpts
@@ -162,7 +164,7 @@ printPlan plan = do
162164
<> line
163165
xs -> do
164166
let executableMsg (name, loc) = fillSep $
165-
fromString (T.unpack name)
167+
fromString (unqualCompToString name)
166168
: "from"
167169
: ( case loc of
168170
Snap -> "snapshot" :: StyleDoc
@@ -260,7 +262,7 @@ executePlan
260262

261263
copyExecutables ::
262264
HasEnvConfig env
263-
=> Map Text InstallLocation
265+
=> Map StackUnqualCompName InstallLocation
264266
-> RIO env ()
265267
copyExecutables exes | Map.null exes = pure ()
266268
copyExecutables exes = do
@@ -283,23 +285,24 @@ copyExecutables exes = do
283285
currExe <- liftIO getExecutablePath -- needed for windows, see below
284286

285287
installed <- forMaybeM (Map.toList exes) $ \(name, loc) -> do
286-
let bindir =
288+
let strName = unqualCompToString name
289+
bindir =
287290
case loc of
288291
Snap -> snapBin
289292
Local -> localBin
290-
mfp <- forgivingResolveFile bindir (T.unpack name ++ ext)
293+
mfp <- forgivingResolveFile bindir (strName ++ ext)
291294
>>= rejectMissingFile
292295
case mfp of
293296
Nothing -> do
294297
prettyWarnL
295298
[ flow "Couldn't find executable"
296-
, style Current (fromString $ T.unpack name)
299+
, style Current (fromString strName)
297300
, flow "in directory"
298301
, pretty bindir <> "."
299302
]
300303
pure Nothing
301304
Just file -> do
302-
let destFile = destDir' FP.</> T.unpack name ++ ext
305+
let destFile = destDir' FP.</> strName ++ ext
303306
prettyInfoL
304307
[ flow "Copying from"
305308
, pretty file
@@ -311,7 +314,7 @@ copyExecutables exes = do
311314
Platform _ Windows | FP.equalFilePath destFile currExe ->
312315
windowsRenameCopy (toFilePath file) destFile
313316
_ -> D.copyFile (toFilePath file) destFile
314-
pure $ Just (name <> T.pack ext)
317+
pure $ Just (strName ++ ext)
315318

316319
unless (null installed) $ do
317320
prettyInfo $
@@ -321,7 +324,7 @@ copyExecutables exes = do
321324
]
322325
<> line
323326
<> bulletedList
324-
(map (fromString . T.unpack . textDisplay) installed :: [StyleDoc])
327+
(map fromString installed :: [StyleDoc])
325328
unless compilerSpecific $ warnInstallSearchPathIssues destDir' installed
326329

327330
-- | Windows can't write over the current executable. Instead, we rename the

0 commit comments

Comments
 (0)