diff options
author | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
commit | f723b8b878a3c4a4687b9e337a875500bebb39b1 (patch) | |
tree | e85204cf042c355e90cff61c111e7d8cd15df311 /third_party/bazel/rules_haskell/haskell/assets/ghci_script | |
parent | 2eb1dc26e42ffbdc168f05ef744bd4b4f3e4c36f (diff) |
feat(third_party/bazel): Check in rules_haskell from Tweag r/17
Diffstat (limited to 'third_party/bazel/rules_haskell/haskell/assets/ghci_script')
-rw-r--r-- | third_party/bazel/rules_haskell/haskell/assets/ghci_script | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/haskell/assets/ghci_script b/third_party/bazel/rules_haskell/haskell/assets/ghci_script new file mode 100644 index 000000000000..ddf9e7917482 --- /dev/null +++ b/third_party/bazel/rules_haskell/haskell/assets/ghci_script @@ -0,0 +1,39 @@ +:add {ADD_SOURCES} +:module + System.IO GHC.IO.Handle Control.Exception System.Directory +import qualified GHC.IO.Handle as Handle +import qualified System.IO as IO +import qualified System.Directory as Dir +rules_haskell_stdout_dupe <- Handle.hDuplicate IO.stdout +:{ +(rules_haskell_stdout_copy_file, rules_haskell_stdout_copy_h) <- do + rules_haskell_tmp_dir <- Dir.getTemporaryDirectory Prelude.>>= Dir.canonicalizePath + (rules_haskell_fn, rules_haskell_h) <- IO.openTempFile rules_haskell_tmp_dir "rules-haskell-ghci-repl" + Handle.hDuplicateTo rules_haskell_h IO.stdout + Prelude.return (rules_haskell_fn, rules_haskell_h) +:} +:show modules +:{ +rules_haskell_loaded_modules <- do + Handle.hClose rules_haskell_stdout_copy_h + -- I had to do it like this because flushing and then searching in the + -- stream at offset 0 did not work (no data is there, although the + -- corresponding file certainly contained it after flushing). Couldn't + -- figure this one out, so we first close the file and then read from it. + rules_haskell_h <- IO.openFile rules_haskell_stdout_copy_file IO.ReadMode + rules_haskell_xs <- Handle.hGetContents rules_haskell_h + Dir.removeFile rules_haskell_stdout_copy_file + Prelude.return Prelude.$ Prelude.takeWhile (Prelude./= ' ') Prelude.<$> Prelude.lines rules_haskell_xs +:} +hDuplicateTo rules_haskell_stdout_dupe IO.stdout +:{ +let rules_haskell_add_loaded_modules _ = + Prelude.return Prelude.$ ":module + " Prelude.++ + Data.List.intercalate " " (("*" Prelude.++) Prelude.<$> rules_haskell_loaded_modules) +:} +:module - System.IO GHC.IO.Handle Control.Exception System.Directory +:def rules_haskell_add_loaded_modules rules_haskell_add_loaded_modules +:rules_haskell_add_loaded_modules +:undef rules_haskell_add_loaded_modules +-- reload modules to drop the rules_haskell* definitions +:reload +{COMMANDS} |