Skip to content

Commit c94b040

Browse files
committed
Remove support for installing GHCJS (fixes commercialhaskell#4086)
1 parent 1c3245f commit c94b040

File tree

4 files changed

+17
-287
lines changed

4 files changed

+17
-287
lines changed

ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Major changes:
6161
the newer GHC build system), hence `compiler` can be set to use a GHC
6262
built from source with `ghc-git-COMMIT-FLAVOUR`
6363

64+
* Remove support for building GHCJS itself. Future releases of Stack
65+
may remove GHCJS support entirely.
66+
6467
Behavior changes:
6568
* `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256)
6669

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ information.
1212
### Subsystem maintainers
1313

1414
* GHCJS - [Matchwood](https://github.com/matchwood)
15+
16+
NOTE: GHCJS support is considered experimental. In Stack 2.0, we are
17+
removing support for building GHCJS itself; links will be added to
18+
this README for information on separate tools. Issues on GHCJS may be
19+
closed as not supported, and the next major Stack release may remove
20+
GHCJS support entirely.

src/Stack/Setup.hs

+7-277
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ module Stack.Setup
1515
( setupEnv
1616
, ensureCompilerAndMsys
1717
, ensureDockerStackExe
18-
, getCabalInstallVersion
1918
, SetupOpts (..)
2019
, defaultSetupInfoYaml
21-
, removeHaskellEnvVars
2220
, withNewLocalBuildTargets
2321

2422
-- * Stack binary download
@@ -38,7 +36,6 @@ import "cryptonite" Crypto.Hash (SHA1(..), SHA256(..))
3836
import Data.Aeson.Extended
3937
import qualified Data.ByteString as S
4038
import qualified Data.ByteString.Lazy as LBS
41-
import Data.Char (isSpace)
4239
import qualified Data.Conduit.Binary as CB
4340
import Data.Conduit.Lazy (lazyConsume)
4441
import Data.Conduit.Lift (evalStateC)
@@ -75,11 +72,9 @@ import qualified RIO
7572
import RIO.List
7673
import RIO.PrettyPrint
7774
import RIO.Process
78-
import Stack.Build (build)
7975
import Stack.Build.Haddock (shouldHaddockDeps)
8076
import Stack.Build.Source (loadSourceMap, hashSourceMapData)
8177
import Stack.Build.Target (NeedTargets(..), parseTargets)
82-
import Stack.Config (loadConfig, loadBuildConfig)
8378
import Stack.Constants
8479
import Stack.Constants.Config (distRelativeDir)
8580
import Stack.GhcPkg (createDatabase, getGlobalDB, mkGhcPackagePath, ghcPkgPathEnvVar)
@@ -149,6 +144,7 @@ data SetupException = UnsupportedSetupCombo OS Arch
149144
| DockerStackExeNotFound Version Text
150145
| UnsupportedSetupConfiguration
151146
| InvalidGhcAt (Path Abs File) SomeException
147+
| NoLongerBuildGhcjs
152148
deriving Typeable
153149
instance Exception SetupException
154150
instance Show SetupException where
@@ -204,6 +200,8 @@ instance Show SetupException where
204200
"I don't know how to install GHC on your system configuration, please install manually"
205201
show (InvalidGhcAt compiler e) =
206202
"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"
207205

208206
-- | Modify the environment variables (like PATH) appropriately, possibly doing installation too
209207
setupEnv :: NeedTargets
@@ -570,7 +568,7 @@ installGhcBindist sopts getSetupInfo' installed = do
570568
forM ghcBuilds $ \ghcBuild -> do
571569
ghcPkgName <- parsePackageNameThrowing ("ghc" ++ ghcVariantSuffix ghcVariant ++ compilerBuildSuffix ghcBuild)
572570
return (getInstalledTool installed ghcPkgName (isWanted . ACGhc), ghcBuild)
573-
Ghcjs -> return [(getInstalledGhcjs installed isWanted, CompilerBuildStandard)]
571+
Ghcjs -> return []
574572
let existingCompilers = concatMap
575573
(\(installedCompiler, compilerBuild) ->
576574
case (installedCompiler, soptsForceReinstall sopts) of
@@ -661,7 +659,7 @@ ensureSandboxedCompiler
661659
-> RIO env (CompilerPaths, ExtraDirs)
662660
ensureSandboxedCompiler sopts getSetupInfo' = do
663661
let wanted = soptsWantedCompiler sopts
664-
(compilerBuild, mcompiler, isSandboxed, paths, mcompilerTool) <- do
662+
(compilerBuild, mcompiler, isSandboxed, paths) <- do
665663
-- List installed tools
666664
config <- view configL
667665
let localPrograms = configLocalPrograms config
@@ -673,7 +671,7 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
673671
WCGhcGit commitId flavour -> buildGhcFromSource getSetupInfo' installed (configCompilerRepository config) commitId flavour
674672
_ -> installGhcBindist sopts getSetupInfo' installed
675673
paths <- extraDirs compilerTool
676-
pure (compilerBuild, Nothing, True, paths, Just compilerTool)
674+
pure (compilerBuild, Nothing, True, paths)
677675

678676
let wc = whichCompiler $ wantedToActual wanted
679677
compiler <-
@@ -685,12 +683,6 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
685683
$ augmentPathMap (toFilePath <$> edBins paths) (view envVarsL menv0)
686684
menv <- mkProcessContext (removeHaskellEnvVars m)
687685

688-
case mcompilerTool of
689-
Just (ToolGhcjs cv) ->
690-
withProcessContext menv $
691-
ensureGhcjsBooted cv (soptsInstallIfMissing sopts) (soptsGHCJSBootOpts sopts)
692-
_ -> pure ()
693-
694686
let names =
695687
case wanted of
696688
WCGhc version -> ["ghc-" ++ versionString version, "ghc"]
@@ -1123,18 +1115,6 @@ getInstalledTool installed name goodVersion =
11231115
else Nothing
11241116
goodPackage _ = Nothing
11251117

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-
11381118
downloadAndInstallTool :: HasTerm env
11391119
=> Path Abs Dir
11401120
-> DownloadInfo
@@ -1202,19 +1182,7 @@ downloadAndInstallCompiler ghcBuild si wanted@WCGhc{} versionCheck mbindistURL =
12021182
let tool = Tool $ PackageIdentifier ghcPkgName selectedVersion
12031183
downloadAndInstallTool (configLocalPrograms config) (gdiDownloadInfo downloadInfo) tool (installer si)
12041184

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
12181186

12191187
downloadAndInstallCompiler _ _ WCGhcGit{} _ _ =
12201188
error "downloadAndInstallCompiler: shouldn't be reached with ghc-git"
@@ -1446,244 +1414,6 @@ installGHCPosix mversion downloadInfo _ archiveFile archiveType tempDir destDir
14461414
logStickyDone $ "Installed GHC."
14471415
logDebug $ "GHC installed to " <> fromString (toFilePath destDir)
14481416

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-
16871417
-- | Check if given processes appear to be present, throwing an exception if
16881418
-- missing.
16891419
checkDependencies :: CheckDependency env a -> RIO env a

0 commit comments

Comments
 (0)