Skip to content

Commit

Permalink
Merge pull request haskell#7575 from runeksvendsen/ghcjs-build-runner
Browse files Browse the repository at this point in the history
Restore GHCJS "-build-runner" option
  • Loading branch information
Ericson2314 authored Sep 14, 2021
2 parents 99e1486 + 89e0a68 commit d9ec979
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Cabal/src/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,11 +1093,22 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
needProfiling = withProfExe lbi

-- build executables
buildRunner = case clbi of
LibComponentLocalBuildInfo {} -> False
FLibComponentLocalBuildInfo {} -> False
ExeComponentLocalBuildInfo {} -> True
TestComponentLocalBuildInfo {} -> True
BenchComponentLocalBuildInfo {} -> True
baseOpts = (componentGhcOptions verbosity lbi bnfo clbi tmpDir)
`mappend` mempty {
ghcOptMode = toFlag GhcModeMake,
ghcOptInputFiles = toNubListR inputFiles,
ghcOptInputModules = toNubListR inputModules
ghcOptInputModules = toNubListR inputModules,
-- for all executable components (exe/test/bench),
-- GHCJS must be passed the "-build-runner" option
ghcOptExtra =
if buildRunner then ["-build-runner"]
else mempty
}
staticOpts = baseOpts `mappend` mempty {
ghcOptDynLinkMode = toFlag GhcStaticOnly,
Expand Down
21 changes: 21 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/BuildRunner.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: BuildRunner
version: 1.0
build-type: Simple
cabal-version: >= 1.10

test-suite ghcjs-test
type: exitcode-stdio-1.0
main-is: BuildRunner.hs
build-depends: base
default-language: Haskell2010

executable ghcjs-exe
main-is: BuildRunner.hs
build-depends: base
default-language: Haskell2010

benchmark ghcjs-bench
type: exitcode-stdio-1.0
main-is: BuildRunner.hs
build-depends: base
default-language: Haskell2010
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/BuildRunner.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main where

import System.Exit (exitSuccess)

main :: IO ()
main = do
exitSuccess
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This test verifies that the `-build-runner` option is passed to GHCJS when the cabal commands `test`/`run`/`bench` are run with the `--ghcjs` option.

This test was created in order to avoid regressions in running GHCJS executables, e.g.:

* https://github.com/haskell/cabal/issues/6175
* https://github.com/haskell/cabal/issues/6361
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Test.Cabal.Prelude

main = cabalTest . recordMode DoNotRecord $ do
skipIfWindows -- disabled because (I presume) Windows doesn't have BASH
cwd <- fmap testCurrentDir getTestEnv
testInvokedWithBuildRunner cwd "test" []
testInvokedWithBuildRunner cwd "run" ["ghcjs-exe"]
testInvokedWithBuildRunner cwd "bench" []

magicString = "SUCCESS! GHCJS was invoked with '-build-runner' option"

testInvokedWithBuildRunner cwd cabalCmd extraArgs = do
output <- fails $ cabal' cabalCmd $ extraArgs ++
[ "--ghcjs"
, "--with-compiler", cwd </> fakeGhcjsPath
]
assertOutputContains magicString output
where
fakeGhcjsPath = "scripts/fake-ghcjs.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# A script that will print out $MAGIC_STRING when invoked with the
# '-build-runner' option.
#
# When cabal is invoked with the '--ghcjs' option and the '--with-compiler'
# option set to the path of this script, cabal will successfully get to the linking
# stage (where it *should* call this script with the '-build-runner' option).

MAGIC_STRING="SUCCESS! GHCJS was invoked with '-build-runner' option"

if [ "$1" == "--numeric-ghcjs-version" ]; then
ghc --numeric-version
elif [ "$1" == "--numeric-ghc-version" ]; then
ghc --numeric-version
elif [[ "$*" == *-build-runner* ]]; then
echo "$MAGIC_STRING"
else
ghc "$@"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

if [ "$1" == "--numeric-ghcjs-version" ]; then
ghc --numeric-version
elif [ "$1" == "--numeric-ghc-version" ]; then
ghc --numeric-version
else
ghc-pkg "$@"
fi
4 changes: 4 additions & 0 deletions changelog.d/pr-7575
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Fix running GHCJS executables
packages: cabal-install
prs: #7575
issues: #6175 #6361

0 comments on commit d9ec979

Please sign in to comment.