Skip to content

Commit f4a580f

Browse files
committed
Move all mkRel TH calls into Stack.Constants (fixes #4272)
1 parent 60302c9 commit f4a580f

File tree

27 files changed

+500
-179
lines changed

27 files changed

+500
-179
lines changed

src/Data/Attoparsec/Interpreter.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import Conduit
6262
import Data.Conduit.Attoparsec
6363
import Data.List (intercalate)
6464
import Data.Text (pack)
65-
import Stack.Constants
6665
import Stack.Prelude
6766
import System.FilePath (takeExtension)
6867
import System.IO (stderr, hPutStrLn)

src/Stack/Build/Cache.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Data.Store.VersionTagged
4949
import qualified Data.Text as T
5050
import Path
5151
import Path.IO
52+
import Stack.Constants
5253
import Stack.Constants.Config
5354
import Stack.Types.Build
5455
import Stack.Types.Compiler
@@ -61,8 +62,8 @@ import qualified System.FilePath as FP
6162
-- | Directory containing files to mark an executable as installed
6263
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
6364
=> InstallLocation -> m (Path Abs Dir)
64-
exeInstalledDir Snap = (</> $(mkRelDir "installed-packages")) `liftM` installationRootDeps
65-
exeInstalledDir Local = (</> $(mkRelDir "installed-packages")) `liftM` installationRootLocal
65+
exeInstalledDir Snap = (</> relDirInstalledPackages) `liftM` installationRootDeps
66+
exeInstalledDir Local = (</> relDirInstalledPackages) `liftM` installationRootLocal
6667

6768
-- | Get all of the installed executables
6869
getInstalledExes :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
@@ -268,7 +269,7 @@ precompiledCacheFile loc copts installedPackageIDs = do
268269
platformRelDir <- platformGhcRelDir
269270
let precompiledDir =
270271
view stackRootL ec
271-
</> $(mkRelDir "precompiled")
272+
</> relDirPrecompiled
272273
</> platformRelDir
273274
</> compiler
274275
</> cabal

src/Stack/Build/Execute.hs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
{-# LANGUAGE MultiParamTypeClasses #-}
77
{-# LANGUAGE OverloadedStrings #-}
88
{-# LANGUAGE RecordWildCards #-}
9-
{-# LANGUAGE TemplateHaskell #-}
109
{-# LANGUAGE LambdaCase #-}
1110
{-# LANGUAGE TypeFamilies #-}
1211
{-# LANGUAGE ScopedTypeVariables #-}
@@ -43,7 +42,6 @@ import Data.Conduit.Process.Typed
4342
createPipe, runProcess_, getStdout,
4443
getStderr, createSource)
4544
import qualified Data.Conduit.Text as CT
46-
import Data.FileEmbed (embedFile, makeRelativeToProject)
4745
import Data.IORef.RunOnce (runOnce)
4846
import Data.List hiding (any)
4947
import qualified Data.Map.Strict as M
@@ -228,11 +226,6 @@ buildSetupArgs =
228226
, "StackSetupShim.mainOverride"
229227
]
230228

231-
setupGhciShimCode :: S.ByteString
232-
setupGhciShimCode = $(do
233-
path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
234-
embedFile path)
235-
236229
simpleSetupCode :: S.ByteString
237230
simpleSetupCode = "import Distribution.Simple\nmain = defaultMain"
238231

@@ -274,7 +267,7 @@ getSetupExe setupHs setupShimHs tmpdir = do
274267
baseNameS ++ ".jsexe"
275268
setupDir =
276269
view stackRootL config </>
277-
$(mkRelDir "setup-exe-cache") </>
270+
relDirSetupExeCache </>
278271
platformDir
279272

280273
exePath <- (setupDir </>) <$> parseRelFile exeNameS
@@ -333,7 +326,7 @@ withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPacka
333326
-- Create files for simple setup and setup shim, if necessary
334327
let setupSrcDir =
335328
view stackRootL config </>
336-
$(mkRelDir "setup-exe-src")
329+
relDirSetupExeSrc
337330
ensureDir setupSrcDir
338331
setupFileName <- parseRelFile ("setup-" ++ simpleSetupHash ++ ".hs")
339332
let setupHs = setupSrcDir </> setupFileName
@@ -864,7 +857,7 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
864857
-- with autoreconf -i. See:
865858
-- https://github.com/commercialhaskell/stack/issues/3534
866859
ensureConfigureScript = do
867-
let fp = pkgDir </> $(mkRelFile "configure")
860+
let fp = pkgDir </> relFileConfigure
868861
exists <- doesFileExist fp
869862
unless exists $ do
870863
logInfo $ "Trying to generate configure with autoreconf in " <> fromString (toFilePath pkgDir)
@@ -951,7 +944,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi
951944

952945
-- See: https://github.com/fpco/stack/issues/157
953946
distDir <- distRelativeDir
954-
let oldDist = dir </> $(mkRelDir "dist")
947+
let oldDist = dir </> relDirDist
955948
newDist = dir </> distDir
956949
exists <- doesDirExist oldDist
957950
when exists $ do
@@ -1086,7 +1079,7 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi
10861079
let depsArgs = map fst matchedDeps
10871080
-- Generate setup_macros.h and provide it to ghc
10881081
let macroDeps = mapMaybe snd matchedDeps
1089-
cppMacrosFile = toFilePath $ setupDir </> $(mkRelFile "setup_macros.h")
1082+
cppMacrosFile = toFilePath $ setupDir </> relFileSetupMacrosH
10901083
cppArgs = ["-optP-include", "-optP" ++ cppMacrosFile]
10911084
liftIO $ S.writeFile cppMacrosFile (encodeUtf8 (T.pack (C.generatePackageVersionMacros macroDeps)))
10921085
return (packageDBArgs ++ depsArgs ++ cppArgs)
@@ -1193,8 +1186,8 @@ withSingleContext ActionContext {..} ExecuteEnv {..} task@Task {..} mdeps msuffi
11931186
Left setupExe -> return setupExe
11941187
Right setuphs -> do
11951188
distDir <- distDirFromDir pkgDir
1196-
let setupDir = distDir </> $(mkRelDir "setup")
1197-
outputFile = setupDir </> $(mkRelFile "setup")
1189+
let setupDir = distDir </> relDirSetup
1190+
outputFile = setupDir </> relFileSetupLower
11981191
customBuilt <- liftIO $ readIORef eeCustomBuilt
11991192
if Set.member (packageName package) customBuilt
12001193
then return outputFile
@@ -1662,7 +1655,7 @@ checkExeStatus
16621655
-> RIO env (Text, ExecutableBuildStatus)
16631656
checkExeStatus compiler platform distDir name = do
16641657
exename <- parseRelDir (T.unpack name)
1665-
exists <- checkPath (distDir </> $(mkRelDir "build") </> exename)
1658+
exists <- checkPath (distDir </> relDirBuild </> exename)
16661659
pure
16671660
( name
16681661
, if exists
@@ -1984,8 +1977,8 @@ getSetupHs dir = do
19841977
then return fp2
19851978
else throwM $ NoSetupHsFound dir
19861979
where
1987-
fp1 = dir </> $(mkRelFile "Setup.hs")
1988-
fp2 = dir </> $(mkRelFile "Setup.lhs")
1980+
fp1 = dir </> relFileSetupHs
1981+
fp2 = dir </> relFileSetupLhs
19891982

19901983
-- Do not pass `-hpcdir` as GHC option if the coverage is not enabled.
19911984
-- This helps running stack-compiled programs with dynamic interpreters like `hint`.

src/Stack/Build/Haddock.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE OverloadedStrings #-}
66
{-# LANGUAGE RecordWildCards #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
8-
{-# LANGUAGE TemplateHaskell #-}
98

109
-- | Generate haddocks
1110
module Stack.Build.Haddock
@@ -26,6 +25,7 @@ import Data.Time (UTCTime)
2625
import Path
2726
import Path.Extra
2827
import Path.IO
28+
import Stack.Constants
2929
import Stack.PackageDump
3030
import Stack.PrettyPrint
3131
import Stack.Types.Build
@@ -283,15 +283,15 @@ lookupDumpPackage ghcPkgId dumpPkgs =
283283

284284
-- | Path of haddock index file.
285285
haddockIndexFile :: Path Abs Dir -> Path Abs File
286-
haddockIndexFile destDir = destDir </> $(mkRelFile "index.html")
286+
haddockIndexFile destDir = destDir </> relFileIndexHtml
287287

288288
-- | Path of local packages documentation directory.
289289
localDocDir :: BaseConfigOpts -> Path Abs Dir
290290
localDocDir bco = bcoLocalInstallRoot bco </> docDirSuffix
291291

292292
-- | Path of documentation directory for the dependencies of local packages
293293
localDepsDocDir :: BaseConfigOpts -> Path Abs Dir
294-
localDepsDocDir bco = localDocDir bco </> $(mkRelDir "all")
294+
localDepsDocDir bco = localDocDir bco </> relDirAll
295295

296296
-- | Path of snapshot packages documentation directory.
297297
snapDocDir :: BaseConfigOpts -> Path Abs Dir

src/Stack/Config.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{-# LANGUAGE DeriveTraversable #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
99
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
10-
{-# LANGUAGE TemplateHaskell #-}
1110
{-# LANGUAGE FlexibleContexts #-}
1211
{-# LANGUAGE OverloadedStrings #-}
1312
{-# LANGUAGE RecordWildCards #-}
@@ -237,7 +236,7 @@ configFromConfigMonoid
237236
-- If --stack-work is passed, prefer it. Otherwise, if STACK_WORK
238237
-- is set, use that. If neither, use the default ".stack-work"
239238
mstackWorkEnv <- liftIO $ lookupEnv stackWorkEnvVar
240-
configWorkDir0 <- maybe (return $(mkRelDir ".stack-work")) (liftIO . parseRelDir) mstackWorkEnv
239+
configWorkDir0 <- maybe (return relDirStackWork) (liftIO . parseRelDir) mstackWorkEnv
241240
let configWorkDir = fromFirst configWorkDir0 configMonoidWorkDir
242241
-- This code is to handle the deprecation of latest-snapshot-url
243242
configUrls <- case (getFirst configMonoidLatestSnapshotUrl, getFirst (urlsMonoidLatestSnapshot configMonoidUrls)) of
@@ -315,7 +314,7 @@ configFromConfigMonoid
315314
case getFirst configMonoidLocalBinPath of
316315
Nothing -> do
317316
localDir <- getAppUserDataDir "local"
318-
return $ localDir </> $(mkRelDir "bin")
317+
return $ localDir </> relDirBin
319318
Just userPath ->
320319
(case mproject of
321320
-- Not in a project
@@ -381,7 +380,7 @@ configFromConfigMonoid
381380
Just [hsc] -> pure hsc
382381
Just x -> error $ "When overriding the default package index, you must provide exactly one value, received: " ++ show x
383382
withPantryConfig
384-
(configStackRoot </> $(mkRelDir "pantry"))
383+
(configStackRoot </> relDirPantry)
385384
hsc
386385
(maybe HpackBundled HpackCommand $ getFirst configMonoidOverrideHpack)
387386
clConnectionCount
@@ -395,7 +394,7 @@ getDefaultLocalProgramsBase :: MonadThrow m
395394
-> m (Path Abs Dir)
396395
getDefaultLocalProgramsBase configStackRoot configPlatform override =
397396
let
398-
defaultBase = configStackRoot </> $(mkRelDir "programs")
397+
defaultBase = configStackRoot </> relDirPrograms
399398
in
400399
case configPlatform of
401400
-- For historical reasons, on Windows a subdirectory of LOCALAPPDATA is
@@ -407,7 +406,8 @@ getDefaultLocalProgramsBase configStackRoot configPlatform override =
407406
Just t ->
408407
case parseAbsDir $ T.unpack t of
409408
Nothing -> throwM $ stringException ("Failed to parse LOCALAPPDATA environment variable (expected absolute directory): " ++ show t)
410-
Just lad -> return $ lad </> $(mkRelDir "Programs") </> $(mkRelDir stackProgName)
409+
Just lad ->
410+
return $ lad </> relDirUpperPrograms </> relDirStackProgName
411411
Nothing -> return defaultBase
412412
_ -> return defaultBase
413413

@@ -583,7 +583,7 @@ loadBuildConfig mproject maresolver mcompiler = do
583583
, "# http://docs.haskellstack.org/en/stable/yaml_configuration/\n"
584584
, "#\n"
585585
, Yaml.encode p]
586-
S.writeFile (toFilePath $ parent dest </> $(mkRelFile "README.txt")) $ S.concat
586+
S.writeFile (toFilePath $ parent dest </> relFileReadmeTxt) $ S.concat
587587
[ "This is the implicit global project, which is used only when 'stack' is run\n"
588588
, "outside of a real project.\n" ]
589589
return (p, dest)
@@ -922,7 +922,7 @@ getFakeConfigPath stackRoot ar = do
922922
-- Better would be to defer figuring out this value until
923923
-- after we have a fully loaded snapshot with a hash.
924924
asDir <- parseRelDir $ takeWhile (/= ':') asString
925-
let full = stackRoot </> $(mkRelDir "script") </> asDir </> $(mkRelFile "config.yaml")
925+
let full = stackRoot </> relDirScript </> asDir </> relFileConfigYaml
926926
ensureDir (parent full)
927927
return full
928928

src/Stack/Config/Docker.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards, TemplateHaskell #-}
3+
{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards #-}
44

55
-- | Docker configuration
66
module Stack.Config.Docker where
@@ -11,6 +11,7 @@ import qualified Data.Text as T
1111
import Data.Text.Read (decimal)
1212
import Distribution.Version (simplifyVersionRange)
1313
import Path
14+
import Stack.Constants
1415
import Stack.Types.Version
1516
import Stack.Types.Config
1617
import Stack.Types.Docker
@@ -78,7 +79,7 @@ dockerOptsFromMonoid mproject stackRoot maresolver DockerOptsMonoid{..} = do
7879
dockerSetUser = getFirst dockerMonoidSetUser
7980
dockerRequireDockerVersion =
8081
simplifyVersionRange (getIntersectingVersionRange dockerMonoidRequireDockerVersion)
81-
dockerDatabasePath = fromFirst (stackRoot </> $(mkRelFile "docker.db")) dockerMonoidDatabasePath
82+
dockerDatabasePath = fromFirst (stackRoot </> relFileDockerDb) dockerMonoidDatabasePath
8283
dockerStackExe = getFirst dockerMonoidStackExe
8384

8485
return DockerOpts{..}

0 commit comments

Comments
 (0)