Skip to content

Commit b9ac532

Browse files
authored
Merge pull request commercialhaskell#6527 from commercialhaskell/re6524-refactor
2 parents a3ad794 + 4aa63a5 commit b9ac532

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed

.stan.toml

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

7373
# Anti-pattern: Data.ByteString.Char8.pack
7474
[[ignore]]
75-
id = "OBS-STAN-0203-erw24B-1015:3"
75+
id = "OBS-STAN-0203-erw24B-1024:3"
7676
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
7777
# ✦ Category: #AntiPattern
7878
# ✦ File: src\Stack\Build\ExecuteEnv.hs
7979
#
80-
# 1014
81-
# 1015 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
82-
# 1016 ┃ ^^^^^^^
80+
# 1023
81+
# 1024 ┃ S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q"
82+
# 1025 ┃ ^^^^^^^
8383

8484
# Anti-pattern: Data.ByteString.Char8.pack
8585
[[ignore]]

src/Stack/Build/ExecuteEnv.hs

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ data ExecuteEnv = ExecuteEnv
126126
, setupExe :: !(Maybe (Path Abs File))
127127
-- ^ Compiled version of eeSetupHs
128128
, cabalPkgVer :: !Version
129+
-- ^ The version of the compiler's Cabal boot package.
129130
, totalWanted :: !Int
130131
, locals :: ![LocalPackage]
131132
, globalDB :: !(Path Abs Dir)
@@ -142,6 +143,15 @@ data ExecuteEnv = ExecuteEnv
142143
-- ^ Value of the PATH environment variable
143144
}
144145

146+
-- | Type representing setup executable circumstances.
147+
data SetupExe
148+
= SimpleSetupExe !(Path Abs File)
149+
-- ^ The build type is Simple and there is a path to an existing setup
150+
-- executable.
151+
| OtherSetupHs !(Path Abs File)
152+
-- ^ Other circumstances with a path to the source code for the setup
153+
-- executable.
154+
145155
buildSetupArgs :: [String]
146156
buildSetupArgs =
147157
[ "-rtsopts"
@@ -669,13 +679,13 @@ withSingleContext
669679
}
670680
menv <- liftIO $ config.processContextSettings envSettings
671681
distRelativeDir' <- distRelativeDir
672-
esetupexehs <-
682+
setupexehs <-
673683
-- Avoid broken Setup.hs files causing problems for simple build
674684
-- types, see:
675685
-- https://github.com/commercialhaskell/stack/issues/370
676686
case (package.buildType, ee.setupExe) of
677-
(C.Simple, Just setupExe) -> pure $ Left setupExe
678-
_ -> liftIO $ Right <$> getSetupHs pkgDir
687+
(C.Simple, Just setupExe) -> pure $ SimpleSetupExe setupExe
688+
_ -> liftIO $ OtherSetupHs <$> getSetupHs pkgDir
679689
inner $ \keepOutputOpen stripTHLoading args -> do
680690
let cabalPackageArg
681691
-- Omit cabal package dependency when building
@@ -717,11 +727,10 @@ withSingleContext
717727
getPackageArgs :: Path Abs Dir -> RIO env [String]
718728
getPackageArgs setupDir =
719729
case package.setupDeps of
720-
-- The package is using the Cabal custom-setup
721-
-- configuration introduced in Cabal 1.24. In
722-
-- this case, the package is providing an
723-
-- explicit list of dependencies, and we
724-
-- should simply use all of them.
730+
-- The package is using the Cabal custom-setup configuration
731+
-- introduced in Cabal 1.24. In this case, the package is
732+
-- providing an explicit list of dependencies, and we should
733+
-- simply use all of them.
725734
Just customSetupDeps -> do
726735
unless (Map.member (mkPackageName "Cabal") customSetupDeps) $
727736
prettyWarnL
@@ -789,13 +798,13 @@ withSingleContext
789798
-- NOTE: This is different from packageDBArgs above in
790799
-- that it does not include the local database and does
791800
-- not pass in the -hide-all-packages argument
792-
++ ( "-clear-package-db"
793-
: "-global-package-db"
794-
: map
795-
(("-package-db=" ++) . toFilePathNoTrailingSep)
796-
ee.baseConfigOpts.extraDBs
797-
++ [ "-package-db="
798-
++ toFilePathNoTrailingSep ee.baseConfigOpts.snapDB
801+
<> ( "-clear-package-db"
802+
: "-global-package-db"
803+
: map
804+
(("-package-db=" ++) . toFilePathNoTrailingSep)
805+
ee.baseConfigOpts.extraDBs
806+
<> [ "-package-db="
807+
<> toFilePathNoTrailingSep ee.baseConfigOpts.snapDB
799808
]
800809
)
801810

@@ -861,9 +870,9 @@ withSingleContext
861870
ExcludeTHLoading -> ConvertPathsToAbsolute
862871
KeepTHLoading -> KeepPathsAsIs
863872

864-
exeName <- case esetupexehs of
865-
Left setupExe -> pure setupExe
866-
Right setuphs -> do
873+
exeName <- case setupexehs of
874+
SimpleSetupExe setupExe -> pure setupExe
875+
OtherSetupHs setuphs -> do
867876
distDir <- distDirFromDir pkgDir
868877
let setupDir = distDir </> relDirSetup
869878
outputFile = setupDir </> relFileSetupLower
@@ -875,32 +884,32 @@ withSingleContext
875884
compilerPath <- view $ compilerPathsL . to (.compiler)
876885
packageArgs <- getPackageArgs setupDir
877886
runExe compilerPath $
878-
[ "--make"
879-
, "-odir", toFilePathNoTrailingSep setupDir
880-
, "-hidir", toFilePathNoTrailingSep setupDir
881-
, "-i", "-i."
882-
] ++ packageArgs ++
883-
[ toFilePath setuphs
884-
, toFilePath ee.setupShimHs
885-
, "-main-is"
886-
, "StackSetupShim.mainOverride"
887-
, "-o", toFilePath outputFile
888-
, "-threaded"
889-
] ++
890-
887+
[ "--make"
888+
, "-odir", toFilePathNoTrailingSep setupDir
889+
, "-hidir", toFilePathNoTrailingSep setupDir
890+
, "-i", "-i."
891+
]
892+
<> packageArgs
893+
<> [ toFilePath setuphs
894+
, toFilePath ee.setupShimHs
895+
, "-main-is"
896+
, "StackSetupShim.mainOverride"
897+
, "-o", toFilePath outputFile
898+
, "-threaded"
899+
]
891900
-- Apply GHC options
892901
-- https://github.com/commercialhaskell/stack/issues/4526
893-
map
894-
T.unpack
895-
( Map.findWithDefault
896-
[]
897-
AGOEverything
898-
config.ghcOptionsByCat
899-
++ case config.applyGhcOptions of
900-
AGOEverything -> ee.buildOptsCLI.ghcOptions
901-
AGOTargets -> []
902-
AGOLocals -> []
903-
)
902+
<> map
903+
T.unpack
904+
( Map.findWithDefault
905+
[]
906+
AGOEverything
907+
config.ghcOptionsByCat
908+
<> case config.applyGhcOptions of
909+
AGOEverything -> ee.buildOptsCLI.ghcOptions
910+
AGOTargets -> []
911+
AGOLocals -> []
912+
)
904913

905914
liftIO $ atomicModifyIORef' ee.customBuilt $
906915
\oldCustomBuilt ->

0 commit comments

Comments
 (0)