summaryrefslogtreecommitdiff
path: root/testsuite/tests/plugins
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2015-12-10 20:41:53 -0800
committerEdward Z. Yang <ezyang@cs.stanford.edu>2015-12-12 00:38:47 -0800
commita3c2a26b3af034f09c960b2dad38f73be7e3a655 (patch)
tree74efe130fc04633aebfe6f022689089fd2a8318d /testsuite/tests/plugins
parent779dfea1d9cc713d9b1e26bb559e8da309b2aeec (diff)
downloadhaskell-a3c2a26b3af034f09c960b2dad38f73be7e3a655.tar.gz
Frontend plugins.
Summary: Frontend plugins enable users to write plugins to replace GHC major modes. E.g. instead of saying ghc --make A B C a user can now say ghc --frontend GHC.Frontend.Shake A B C which might provide an alternative implementation of a multi-module build. For more details, see the manual entry. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: simonmar, bgamari, austin, simonpj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1598 GHC Trac Issues: #11194
Diffstat (limited to 'testsuite/tests/plugins')
-rw-r--r--testsuite/tests/plugins/FrontendPlugin.hs52
-rw-r--r--testsuite/tests/plugins/Makefile7
-rw-r--r--testsuite/tests/plugins/all.T3
-rw-r--r--testsuite/tests/plugins/frontend01.hs1
-rw-r--r--testsuite/tests/plugins/frontend01.stdout4
5 files changed, 67 insertions, 0 deletions
diff --git a/testsuite/tests/plugins/FrontendPlugin.hs b/testsuite/tests/plugins/FrontendPlugin.hs
new file mode 100644
index 0000000000..9a6c5d0514
--- /dev/null
+++ b/testsuite/tests/plugins/FrontendPlugin.hs
@@ -0,0 +1,52 @@
+module FrontendPlugin where
+
+import GhcPlugins
+import qualified GHC
+import GHC ( Ghc, LoadHowMuch(..) )
+
+import DriverPipeline hiding ( hsc_env )
+import DriverPhases
+import System.Exit
+import Control.Monad
+import Data.List
+
+frontendPlugin :: FrontendPlugin
+frontendPlugin = defaultFrontendPlugin {
+ frontend = doMake
+ }
+
+-- Copypasted from ghc/Main.hs
+doMake :: [String] -> [(String,Maybe Phase)] -> Ghc ()
+doMake opts srcs = do
+ liftIO $ print opts
+ let (hs_srcs, non_hs_srcs) = partition haskellish srcs
+
+ haskellish (f,Nothing) =
+ looksLikeModuleName f || isHaskellUserSrcFilename f || '.' `notElem` f
+ haskellish (_,Just phase) =
+ phase `notElem` [ As True, As False, Cc, Cobjc, Cobjcxx, CmmCpp, Cmm
+ , StopLn]
+
+ hsc_env <- GHC.getSession
+
+ -- if we have no haskell sources from which to do a dependency
+ -- analysis, then just do one-shot compilation and/or linking.
+ -- This means that "ghc Foo.o Bar.o -o baz" links the program as
+ -- we expect.
+ if (null hs_srcs)
+ then liftIO (oneShot hsc_env StopLn srcs)
+ else do
+
+ o_files <- mapM (\x -> liftIO $ compileFile hsc_env StopLn x)
+ non_hs_srcs
+ dflags <- GHC.getSessionDynFlags
+ let dflags' = dflags { ldInputs = map (FileOption "") o_files
+ ++ ldInputs dflags }
+ _ <- GHC.setSessionDynFlags dflags'
+
+ targets <- mapM (uncurry GHC.guessTarget) hs_srcs
+ GHC.setTargets targets
+ ok_flag <- GHC.load LoadAllTargets
+
+ when (failed ok_flag) (liftIO $ exitWith (ExitFailure 1))
+ return ()
diff --git a/testsuite/tests/plugins/Makefile b/testsuite/tests/plugins/Makefile
index 42a4d1af0a..c12c33c9c7 100644
--- a/testsuite/tests/plugins/Makefile
+++ b/testsuite/tests/plugins/Makefile
@@ -24,3 +24,10 @@ T10294:
.PHONY: T10294a
T10294a:
"$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -c -v0 T10294a.hs -package-db annotation-plugin/pkg.T10294a/local.package.conf -package annotation-plugin -fplugin=SayAnnNames
+
+.PHONY: frontend01
+frontend01:
+ $(RM) FrontendPlugin.hi FrontendPlugin.o frontend01 frontend01.hi frontend.o
+ "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) -Wall -package ghc -c FrontendPlugin.hs
+ "$(TEST_HC)" $(TEST_HC_OPTS) $(ghcPluginWayFlags) --frontend FrontendPlugin -ffrontend-opt foobar frontend01
+ ./frontend01
diff --git a/testsuite/tests/plugins/all.T b/testsuite/tests/plugins/all.T
index bc3bcfa2dd..2e4aacf29c 100644
--- a/testsuite/tests/plugins/all.T
+++ b/testsuite/tests/plugins/all.T
@@ -62,3 +62,6 @@ test('T10294a',
clean_cmd('$MAKE -s --no-print-directory -C annotation-plugin clean.T10294a')],
run_command,
['$MAKE -s --no-print-directory T10294a'])
+
+test('frontend01', [ extra_clean(['FrontendPlugin.hi', 'FrontendPlugin.o', 'frontend01', 'frontend01.o', 'frontend01.hi']) ],
+ run_command, ['$MAKE -s --no-print-directory frontend01'])
diff --git a/testsuite/tests/plugins/frontend01.hs b/testsuite/tests/plugins/frontend01.hs
new file mode 100644
index 0000000000..db014568d4
--- /dev/null
+++ b/testsuite/tests/plugins/frontend01.hs
@@ -0,0 +1 @@
+main = putStrLn "hello world"
diff --git a/testsuite/tests/plugins/frontend01.stdout b/testsuite/tests/plugins/frontend01.stdout
new file mode 100644
index 0000000000..84950bcbc9
--- /dev/null
+++ b/testsuite/tests/plugins/frontend01.stdout
@@ -0,0 +1,4 @@
+["foobar"]
+[1 of 1] Compiling Main ( frontend01.hs, frontend01.o )
+Linking frontend01 ...
+hello world