@@ -15,10 +15,8 @@ module Stack.Setup
15
15
( setupEnv
16
16
, ensureCompilerAndMsys
17
17
, ensureDockerStackExe
18
- , getCabalInstallVersion
19
18
, SetupOpts (.. )
20
19
, defaultSetupInfoYaml
21
- , removeHaskellEnvVars
22
20
, withNewLocalBuildTargets
23
21
24
22
-- * Stack binary download
@@ -38,7 +36,6 @@ import "cryptonite" Crypto.Hash (SHA1(..), SHA256(..))
38
36
import Data.Aeson.Extended
39
37
import qualified Data.ByteString as S
40
38
import qualified Data.ByteString.Lazy as LBS
41
- import Data.Char (isSpace )
42
39
import qualified Data.Conduit.Binary as CB
43
40
import Data.Conduit.Lazy (lazyConsume )
44
41
import Data.Conduit.Lift (evalStateC )
@@ -75,11 +72,9 @@ import qualified RIO
75
72
import RIO.List
76
73
import RIO.PrettyPrint
77
74
import RIO.Process
78
- import Stack.Build (build )
79
75
import Stack.Build.Haddock (shouldHaddockDeps )
80
76
import Stack.Build.Source (loadSourceMap , hashSourceMapData )
81
77
import Stack.Build.Target (NeedTargets (.. ), parseTargets )
82
- import Stack.Config (loadConfig , loadBuildConfig )
83
78
import Stack.Constants
84
79
import Stack.Constants.Config (distRelativeDir )
85
80
import Stack.GhcPkg (createDatabase , getGlobalDB , mkGhcPackagePath , ghcPkgPathEnvVar )
@@ -149,6 +144,7 @@ data SetupException = UnsupportedSetupCombo OS Arch
149
144
| DockerStackExeNotFound Version Text
150
145
| UnsupportedSetupConfiguration
151
146
| InvalidGhcAt (Path Abs File ) SomeException
147
+ | NoLongerBuildGhcjs
152
148
deriving Typeable
153
149
instance Exception SetupException
154
150
instance Show SetupException where
@@ -204,6 +200,8 @@ instance Show SetupException where
204
200
" I don't know how to install GHC on your system configuration, please install manually"
205
201
show (InvalidGhcAt compiler e) =
206
202
" Found an invalid compiler at " ++ show (toFilePath compiler) ++ " : " ++ displayException e
203
+ show NoLongerBuildGhcjs =
204
+ " Since Stack 2.0, Stack does not support building GHCJS itself"
207
205
208
206
-- | Modify the environment variables (like PATH) appropriately, possibly doing installation too
209
207
setupEnv :: NeedTargets
@@ -570,7 +568,7 @@ installGhcBindist sopts getSetupInfo' installed = do
570
568
forM ghcBuilds $ \ ghcBuild -> do
571
569
ghcPkgName <- parsePackageNameThrowing (" ghc" ++ ghcVariantSuffix ghcVariant ++ compilerBuildSuffix ghcBuild)
572
570
return (getInstalledTool installed ghcPkgName (isWanted . ACGhc ), ghcBuild)
573
- Ghcjs -> return [(getInstalledGhcjs installed isWanted, CompilerBuildStandard ) ]
571
+ Ghcjs -> return []
574
572
let existingCompilers = concatMap
575
573
(\ (installedCompiler, compilerBuild) ->
576
574
case (installedCompiler, soptsForceReinstall sopts) of
@@ -661,7 +659,7 @@ ensureSandboxedCompiler
661
659
-> RIO env (CompilerPaths , ExtraDirs )
662
660
ensureSandboxedCompiler sopts getSetupInfo' = do
663
661
let wanted = soptsWantedCompiler sopts
664
- (compilerBuild, mcompiler, isSandboxed, paths, mcompilerTool ) <- do
662
+ (compilerBuild, mcompiler, isSandboxed, paths) <- do
665
663
-- List installed tools
666
664
config <- view configL
667
665
let localPrograms = configLocalPrograms config
@@ -673,7 +671,7 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
673
671
WCGhcGit commitId flavour -> buildGhcFromSource getSetupInfo' installed (configCompilerRepository config) commitId flavour
674
672
_ -> installGhcBindist sopts getSetupInfo' installed
675
673
paths <- extraDirs compilerTool
676
- pure (compilerBuild, Nothing , True , paths, Just compilerTool )
674
+ pure (compilerBuild, Nothing , True , paths)
677
675
678
676
let wc = whichCompiler $ wantedToActual wanted
679
677
compiler <-
@@ -685,12 +683,6 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
685
683
$ augmentPathMap (toFilePath <$> edBins paths) (view envVarsL menv0)
686
684
menv <- mkProcessContext (removeHaskellEnvVars m)
687
685
688
- case mcompilerTool of
689
- Just (ToolGhcjs cv) ->
690
- withProcessContext menv $
691
- ensureGhcjsBooted cv (soptsInstallIfMissing sopts) (soptsGHCJSBootOpts sopts)
692
- _ -> pure ()
693
-
694
686
let names =
695
687
case wanted of
696
688
WCGhc version -> [" ghc-" ++ versionString version, " ghc" ]
@@ -1123,18 +1115,6 @@ getInstalledTool installed name goodVersion =
1123
1115
else Nothing
1124
1116
goodPackage _ = Nothing
1125
1117
1126
- getInstalledGhcjs :: [Tool ]
1127
- -> (ActualCompiler -> Bool )
1128
- -> Maybe Tool
1129
- getInstalledGhcjs installed goodVersion =
1130
- if null available
1131
- then Nothing
1132
- else Just $ ToolGhcjs $ maximum available
1133
- where
1134
- available = mapMaybe goodPackage installed
1135
- goodPackage (ToolGhcjs cv) = if goodVersion cv then Just cv else Nothing
1136
- goodPackage _ = Nothing
1137
-
1138
1118
downloadAndInstallTool :: HasTerm env
1139
1119
=> Path Abs Dir
1140
1120
-> DownloadInfo
@@ -1202,19 +1182,7 @@ downloadAndInstallCompiler ghcBuild si wanted@WCGhc{} versionCheck mbindistURL =
1202
1182
let tool = Tool $ PackageIdentifier ghcPkgName selectedVersion
1203
1183
downloadAndInstallTool (configLocalPrograms config) (gdiDownloadInfo downloadInfo) tool (installer si)
1204
1184
1205
- downloadAndInstallCompiler compilerBuild si wanted@ WCGhcjs {} versionCheck _mbindistUrl = do
1206
- config <- view configL
1207
- ghcVariant <- view ghcVariantL
1208
- case (ghcVariant, compilerBuild) of
1209
- (GHCStandard , CompilerBuildStandard ) -> return ()
1210
- _ -> throwM GHCJSRequiresStandardVariant
1211
- (selectedVersion, downloadInfo) <- case Map. lookup " source" $ siGHCJSs si of
1212
- Nothing -> throwM $ UnknownOSKey " source"
1213
- Just pairs_ -> getWantedCompilerInfo " source" versionCheck wanted id pairs_
1214
- logInfo " Preparing to install GHCJS to an isolated location."
1215
- logInfo " This will not interfere with any system-level installation."
1216
- let tool = ToolGhcjs selectedVersion
1217
- downloadAndInstallTool (configLocalPrograms config) downloadInfo tool (installGHCJS si)
1185
+ downloadAndInstallCompiler _ _ WCGhcjs {} _ _ = throwIO NoLongerBuildGhcjs
1218
1186
1219
1187
downloadAndInstallCompiler _ _ WCGhcGit {} _ _ =
1220
1188
error " downloadAndInstallCompiler: shouldn't be reached with ghc-git"
@@ -1446,244 +1414,6 @@ installGHCPosix mversion downloadInfo _ archiveFile archiveType tempDir destDir
1446
1414
logStickyDone $ " Installed GHC."
1447
1415
logDebug $ " GHC installed to " <> fromString (toFilePath destDir)
1448
1416
1449
- installGHCJS :: HasConfig env
1450
- => SetupInfo
1451
- -> Path Abs File
1452
- -> ArchiveType
1453
- -> Path Abs Dir
1454
- -> Path Abs Dir
1455
- -> RIO env ()
1456
- installGHCJS si archiveFile archiveType _tempDir destDir = do
1457
- platform <- view platformL
1458
- menv0 <- view processContextL
1459
- -- This ensures that locking is disabled for the invocations of
1460
- -- stack below.
1461
- let removeLockVar = Map. delete " STACK_LOCK"
1462
- menv <- mkProcessContext (removeLockVar (removeHaskellEnvVars (view envVarsL menv0)))
1463
- logDebug $ " menv = " <> displayShow (view envVarsL menv)
1464
-
1465
- -- NOTE: this is a bit of a hack - instead of using the temp
1466
- -- directory, leave the unpacked source tarball in the destination
1467
- -- directory. This way, the absolute paths in the wrapper scripts
1468
- -- will point to executables that exist in
1469
- -- src/.stack-work/install/... - see
1470
- -- https://github.com/commercialhaskell/stack/issues/1016
1471
- --
1472
- -- This is also used by 'ensureGhcjsBooted', because it can use the
1473
- -- environment of the stack.yaml which came with ghcjs, in order to
1474
- -- install cabal-install. This lets us also fix the version of
1475
- -- cabal-install used.
1476
- let unpackDir = destDir </> relDirSrc
1477
- runUnpack <- case platform of
1478
- Platform _ Cabal. Windows -> return $
1479
- withUnpackedTarball7z " GHCJS" si archiveFile archiveType Nothing unpackDir
1480
- _ -> do
1481
- zipTool' <-
1482
- case archiveType of
1483
- TarXz -> return " xz"
1484
- TarBz2 -> return " bzip2"
1485
- TarGz -> return " gzip"
1486
- SevenZ -> throwString " Don't know how to deal with .7z files on non-Windows"
1487
- (zipTool, tarTool) <- checkDependencies $ (,)
1488
- <$> checkDependency zipTool'
1489
- <*> checkDependency " tar"
1490
- logDebug $ " ziptool: " <> fromString zipTool
1491
- logDebug $ " tar: " <> fromString tarTool
1492
- return $ do
1493
- liftIO $ ignoringAbsence (removeDirRecur destDir)
1494
- liftIO $ ignoringAbsence (removeDirRecur unpackDir)
1495
- withProcessContext menv $ withWorkingDir (toFilePath destDir) $ readProcessNull tarTool [" xf" , toFilePath archiveFile]
1496
- innerDir <- expectSingleUnpackedDir archiveFile destDir
1497
- renameDir innerDir unpackDir
1498
-
1499
- logSticky $
1500
- " Unpacking GHCJS into " <>
1501
- fromString (toFilePath unpackDir) <>
1502
- " ..."
1503
- logDebug $ " Unpacking " <> fromString (toFilePath archiveFile)
1504
- runUnpack
1505
-
1506
- logSticky " Setting up GHCJS build environment"
1507
- let stackYaml = unpackDir </> stackDotYaml
1508
- destBinDir = destDir </> relDirBin
1509
- ensureDir destBinDir
1510
- loadGhcjsEnvConfig stackYaml destBinDir $ \ envConfig' -> do
1511
-
1512
- -- On windows we need to copy options files out of the install dir. Argh!
1513
- -- This is done before the build, so that if it fails, things fail
1514
- -- earlier.
1515
- mwindowsInstallDir <- case platform of
1516
- Platform _ Cabal. Windows ->
1517
- liftM Just $ runRIO envConfig' installationRootLocal
1518
- _ -> return Nothing
1519
-
1520
- logSticky " Installing GHCJS (this will take a long time) ..."
1521
- buildInGhcjsEnv envConfig'
1522
- -- Copy over *.options files needed on windows.
1523
- forM_ mwindowsInstallDir $ \ dir -> do
1524
- (_, files) <- listDir (dir </> relDirBin)
1525
- forM_ (filter ((" .options" `isSuffixOf` ). toFilePath) files) $ \ optionsFile -> do
1526
- let dest = destDir </> relDirBin </> filename optionsFile
1527
- liftIO $ ignoringAbsence (removeFile dest)
1528
- copyFile optionsFile dest
1529
- logStickyDone " Installed GHCJS."
1530
-
1531
- ensureGhcjsBooted :: HasConfig env
1532
- => ActualCompiler -> Bool -> [String ]
1533
- -> RIO env ()
1534
- ensureGhcjsBooted cv shouldBoot bootOpts = do
1535
- eres <- try $ sinkProcessStdout " ghcjs" [] (return () )
1536
- case eres of
1537
- Right () -> return ()
1538
- Left ece | " no input files" `S.isInfixOf` LBS. toStrict (eceStderr ece) ->
1539
- return ()
1540
- Left ece | " ghcjs_boot.completed" `S.isInfixOf` LBS. toStrict (eceStderr ece) ->
1541
- if not shouldBoot then throwM GHCJSNotBooted else do
1542
- config <- view configL
1543
- destDir <- installDir (configLocalPrograms config) (ToolGhcjs cv)
1544
- let stackYaml = destDir </> relDirSrc </> stackDotYaml
1545
- -- TODO: Remove 'actualStackYaml' and just use
1546
- -- 'stackYaml' for a version after 0.1.6. It's for
1547
- -- compatibility with the directories setup used for
1548
- -- most of the life of the development branch between
1549
- -- 0.1.5 and 0.1.6. See
1550
- -- https://github.com/commercialhaskell/stack/issues/749#issuecomment-147382783
1551
- -- This only affects the case where GHCJS has been
1552
- -- installed with an older version and not yet booted.
1553
- stackYamlExists <- doesFileExist stackYaml
1554
- ghcjsVersion <- case cv of
1555
- ACGhcjs version _ -> return version
1556
- _ -> error " ensureGhcjsBooted invoked on non GhcjsVersion"
1557
- actualStackYaml <- if stackYamlExists then return stackYaml
1558
- else
1559
- liftM ((destDir </> relDirSrc) </> ) $
1560
- parseRelFile $ " ghcjs-" ++ versionString ghcjsVersion ++ " /stack.yaml"
1561
- actualStackYamlExists <- doesFileExist actualStackYaml
1562
- unless actualStackYamlExists $
1563
- throwString " Error: Couldn't find GHCJS stack.yaml in old or new location."
1564
- bootGhcjs ghcjsVersion actualStackYaml destDir bootOpts
1565
- Left ece -> throwIO ece
1566
-
1567
- bootGhcjs :: (HasRunner env , HasProcessContext env )
1568
- => Version -> Path Abs File -> Path Abs Dir -> [String ] -> RIO env ()
1569
- bootGhcjs ghcjsVersion stackYaml destDir bootOpts =
1570
- loadGhcjsEnvConfig stackYaml (destDir </> relDirBin) $ \ envConfig -> do
1571
- menv <- liftIO $ configProcessContextSettings (view configL envConfig) defaultEnvSettings
1572
- -- Install cabal-install if missing, or if the installed one is old.
1573
- mcabal <- withProcessContext menv getCabalInstallVersion
1574
- shouldInstallCabal <- case mcabal of
1575
- Nothing -> do
1576
- logInfo " No cabal-install binary found for use with GHCJS."
1577
- return True
1578
- Just v
1579
- | v < mkVersion [1 , 22 , 4 ] -> do
1580
- logInfo $
1581
- " The cabal-install found on PATH is too old to be used for booting GHCJS (version " <>
1582
- fromString (versionString v) <>
1583
- " )."
1584
- return True
1585
- | v >= mkVersion [1 , 23 ] -> do
1586
- logWarn $
1587
- " The cabal-install found on PATH is a version stack doesn't know about, version " <>
1588
- fromString (versionString v) <>
1589
- " . This may or may not work.\n " <>
1590
- " See this issue: https://github.com/ghcjs/ghcjs/issues/470"
1591
- return False
1592
- | ghcjsVersion >= mkVersion [0 , 2 , 0 , 20160413 ] && v >= mkVersion [1 , 22 , 8 ] -> do
1593
- logWarn $
1594
- " The cabal-install found on PATH, version " <>
1595
- fromString (versionString v) <>
1596
- " , is >= 1.22.8.\n " <>
1597
- " That version has a bug preventing ghcjs < 0.2.0.20160413 from booting.\n " <>
1598
- " See this issue: https://github.com/ghcjs/ghcjs/issues/470"
1599
- return True
1600
- | otherwise -> return False
1601
- let envSettings = EnvSettings
1602
- { esIncludeLocals = True
1603
- , esIncludeGhcPackagePath = False
1604
- , esStackExe = True
1605
- , esLocaleUtf8 = True
1606
- , esKeepGhcRts = False
1607
- }
1608
- menv' <- liftIO $ configProcessContextSettings (view configL envConfig) envSettings
1609
- shouldInstallAlex <- runRIO menv $ not <$> doesExecutableExist " alex"
1610
- shouldInstallHappy <- runRIO menv $ not <$> doesExecutableExist " happy"
1611
- let bootDepsToInstall =
1612
- [ " cabal-install" | shouldInstallCabal ] ++
1613
- [ " alex" | shouldInstallAlex ] ++
1614
- [ " happy" | shouldInstallHappy ]
1615
- when (not (null bootDepsToInstall)) $ do
1616
- logInfo $ " Building tools from source, needed for ghcjs-boot: " <> displayShow bootDepsToInstall
1617
- let haddockDeps = False
1618
- envConfig' <- rebuildEnv envConfig NeedTargets haddockDeps $
1619
- defaultBuildOptsCLI { boptsCLITargets = bootDepsToInstall }
1620
- buildInGhcjsEnv envConfig'
1621
- let failedToFindErr = do
1622
- logError " This shouldn't happen, because it gets built to the snapshot bin directory, which should be treated as being on the PATH."
1623
- liftIO exitFailure
1624
- when shouldInstallCabal $ do
1625
- mcabal' <- withProcessContext menv' getCabalInstallVersion
1626
- case mcabal' of
1627
- Nothing -> do
1628
- logError " Failed to get cabal-install version after installing it."
1629
- failedToFindErr
1630
- Just v | v >= mkVersion [1 , 22 , 8 ] && v < mkVersion [1 , 23 ] ->
1631
- logWarn $
1632
- " Installed version of cabal-install is in a version range which may not work.\n " <>
1633
- " See this issue: https://github.com/ghcjs/ghcjs/issues/470\n " <>
1634
- " This version is specified by the stack.yaml file included in the ghcjs tarball.\n "
1635
- _ -> return ()
1636
- when shouldInstallAlex $ do
1637
- alexInstalled <- runRIO menv $ doesExecutableExist " alex"
1638
- when (not alexInstalled) $ do
1639
- logError " Failed to find 'alex' executable after installing it."
1640
- failedToFindErr
1641
- when shouldInstallHappy $ do
1642
- happyInstalled <- runRIO menv $ doesExecutableExist " happy"
1643
- when (not happyInstalled) $ do
1644
- logError " Failed to find 'happy' executable after installing it."
1645
- failedToFindErr
1646
- logSticky " Booting GHCJS (this will take a long time) ..."
1647
- withProcessContext menv' $ proc " ghcjs-boot" bootOpts logProcessStderrStdout
1648
- logStickyDone " GHCJS booted."
1649
-
1650
- loadGhcjsEnvConfig
1651
- :: HasRunner env
1652
- => Path Abs File
1653
- -> Path b t
1654
- -> (EnvConfig -> RIO env a )
1655
- -> RIO env a
1656
- loadGhcjsEnvConfig stackYaml binPath inner =
1657
- local (over globalOptsL modifyGO) $
1658
- loadConfig $ \ config -> do
1659
- bconfig <- runRIO config loadBuildConfig
1660
- envConfig <- runRIO bconfig $ setupEnv AllowNoTargets defaultBuildOptsCLI Nothing
1661
- inner envConfig
1662
- where
1663
- modifyGO go = go
1664
- { globalConfigMonoid = mempty
1665
- { configMonoidInstallGHC = FirstTrue (Just True )
1666
- , configMonoidLocalBinPath = First (Just (toFilePath binPath))
1667
- }
1668
- , globalResolver = Nothing
1669
- , globalStackYaml = SYLOverride stackYaml
1670
- }
1671
-
1672
- buildInGhcjsEnv :: (HasEnvConfig env , MonadIO m ) => env -> m ()
1673
- buildInGhcjsEnv envConfig = do
1674
- runRIO (set (buildOptsL. buildOptsInstallExesL) True $
1675
- set (buildOptsL. buildOptsHaddockL) False envConfig) $
1676
- build Nothing
1677
-
1678
- getCabalInstallVersion :: (HasProcessContext env , HasLogFunc env ) => RIO env (Maybe Version )
1679
- getCabalInstallVersion = do
1680
- ebs <- tryAny $ proc " cabal" [" --numeric-version" ] readProcess_
1681
- case ebs of
1682
- Left _ ->
1683
- return Nothing
1684
- Right (bs, _) ->
1685
- Just <$> parseVersionThrowing (T. unpack $ T. dropWhileEnd isSpace (T. decodeUtf8 (LBS. toStrict bs)))
1686
-
1687
1417
-- | Check if given processes appear to be present, throwing an exception if
1688
1418
-- missing.
1689
1419
checkDependencies :: CheckDependency env a -> RIO env a
0 commit comments