From 618d7f6cb422b119d00a4a08ea9abe3b6dc0c918 Mon Sep 17 00:00:00 2001 From: Jon Doe Date: Sat, 12 Sep 2020 23:56:49 +0200 Subject: [PATCH] try to build all plugins --- .gitignore | 3 +++ GypsFulvus.cabal | 8 +++++-- plugins/STDIO/Plugin.hs | 1 + src/GypsFulvus.hs | 22 +++++++++-------- src/GypsFulvus/PluginStuff.hs | 45 +++++++++++++++++++++++++++++++++-- stack.yaml | 7 +++--- stack.yaml.lock | 17 +++++++++---- 7 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 plugins/STDIO/Plugin.hs diff --git a/.gitignore b/.gitignore index 8a0194e..3d1d46e 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ Thumbs.db #hs .stack* + +# fuck you, cabal, fuck you +dist-newstyle \ No newline at end of file diff --git a/GypsFulvus.cabal b/GypsFulvus.cabal index 94c421e..b008be9 100644 --- a/GypsFulvus.cabal +++ b/GypsFulvus.cabal @@ -22,7 +22,9 @@ library base >= 4.7 && < 5, stm, containers, - text + text, + plugins >= 1.6.0, + directory ghc-options: -O2 -threaded @@ -34,7 +36,9 @@ executable GypsFulvus base >= 4.7 && < 5, stm, containers, - text + text, + plugins >= 1.6.0, + directory ghc-options: -O2 -threaded diff --git a/plugins/STDIO/Plugin.hs b/plugins/STDIO/Plugin.hs new file mode 100644 index 0000000..84bfe84 --- /dev/null +++ b/plugins/STDIO/Plugin.hs @@ -0,0 +1 @@ +main = putStrLn "HELLO WORLD" diff --git a/src/GypsFulvus.hs b/src/GypsFulvus.hs index 73b1bb3..63a6e00 100644 --- a/src/GypsFulvus.hs +++ b/src/GypsFulvus.hs @@ -6,6 +6,7 @@ import qualified Data.Map as M import qualified Data.Text as T import Control.Concurrent(ThreadId, forkIO, killThread) import GypsFulvus.PluginStuff +import Control.Monad(liftM) data Placeholder = Placeholder data CommandMap = CommandMap (M.Map T.Text Placeholder) data CommandWorkspace = CommandWorkspace Placeholder @@ -36,15 +37,16 @@ execMain :: IO () execMain = do collectorChannel <- atomically newTChan -- normal channel for dumping any user input consumerBroadcastChannel <- atomically newBroadcastTChan - loadCommsPlugins collectorChannel - availableCommandMap <- atomically $ newTMVar CommandMap - loadLabourPlugins availableCommandMap - sharedCommandWorkspace <- atomically $ newTMVar CommandWorkspace - sharedTaskQueue <- atomically $ newTChan - dispatchTID <- forkIO $ dispatchCommands sharedCommandWorkspace sharedTaskQueue - broadcastTID <- forkIO $ broadcastToConsumers consumerBroadcastChannel sharedCommandWorkspace sharedTaskQueue - collectorTID <- forkIO $ collectInputs collectorChannel availableCommandMap sharedCommandWorkspace sharedTaskQueue - canary <- atomically $ newTMVar False -- simple 'should I exit' canary + forkIO $ loadCommsPlugins canary collectorChannel +-- availableCommandMap <- atomically $ newTMVar CommandMap +-- loadLabourPlugins availableCommandMap +-- sharedCommandWorkspace <- atomically $ newTMVar CommandWorkspace +-- sharedTaskQueue <- atomically $ newTChan +-- dispatchTID <- forkIO $ dispatchCommands sharedCommandWorkspace sharedTaskQueue +-- broadcastTID <- forkIO $ broadcastToConsumers consumerBroadcastChannel sharedCommandWorkspace sharedTaskQueue +-- collectorTID <- forkIO $ collectInputs collectorChannel availableCommandMap sharedCommandWorkspace sharedTaskQueue +-- myTIDs = [dispatchTID,broadcastTID,collectorTID] + let myTIDs = [] runForever canary - mapM_ killThread [dispatchTID, broadcastTID, collectorTID] + mapM_ killThread myTIDs diff --git a/src/GypsFulvus/PluginStuff.hs b/src/GypsFulvus/PluginStuff.hs index 9c9241d..286939a 100644 --- a/src/GypsFulvus/PluginStuff.hs +++ b/src/GypsFulvus/PluginStuff.hs @@ -1,7 +1,48 @@ -module GypsFulvus.PluginStuff(loadCommsPlugins, loadLabourPlugins) where +module GypsFulvus.PluginStuff(loadCommsPlugins) where +import Control.Monad +import System.Directory +import System.Plugins.Make +import Data.Maybe +import Control.Concurrent.STM +import Control.Concurrent.STM.TMVar + +pluginPath :: IO FilePath +pluginPath = getXdgDirectory XdgData "gypsfulvus/plugins" >>= makeAbsolute + + +configPath :: IO FilePath +configPath = getXdgDirectory XdgConfig "gypsfulvus" + + + -- load all the plugins for IO (e.g. IRC, stdio, maybe matrix procol, telnet, whatever) -loadCommsPlugins collectorChannel = undefined + + + +loadCommsPlugins canary collectorChannel = + let potentialPlugins = pluginPath >>= \pp -> listDirectory pp >>= filterM (\fuku -> doesDirectoryExist (pp ++ "/" ++ fuku)) >>= mapM (\fuku -> return (pp ++ "/" ++ fuku)) + in do + pluginPath >>= putStrLn + pluginPath >>= listDirectory >>= mapM putStrLn + pluginPath >>= \pp -> listDirectory pp >>= filterM (\fuku -> putStrLn (pp ++ "/" ++ fuku) >> doesDirectoryExist (pp ++ "/" ++ fuku)) + pp <- potentialPlugins + mapM_ putStrLn pp + ff <- mapM (\d -> findFile [d] "Plugin.hs") pp + let rff = map (fromMaybe "") $ filter (/= Nothing) ff + s <- mapM (\hng -> makeAll hng ["-v","-dynamic"]) rff + mapM (\s' -> case s' of + MakeSuccess _ p -> putStrLn p + MakeFailure e -> do + putStrLn $ show e + + return ()) s + _ <- atomically $ swapTMVar canary True + -- I don't actually want to quit here but I don't like errors from STM heuristics when the canary is GCed + + return () + + -- load all the routines that the bot can run (e.g. run tcl code, calculator, youtube, etc.) loadLabourPlugins availableCommandMap = undefined -- thread to pass any work to be done diff --git a/stack.yaml b/stack.yaml index 112c601..053b171 100644 --- a/stack.yaml +++ b/stack.yaml @@ -17,8 +17,8 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-16.13 - +#resolver: lts-16.13 +resolver: lts-14.27 # User packages to be built. # Various formats can be used as shown in the example below. # @@ -34,7 +34,8 @@ packages: # These entries can reference officially published versions as well as # forks / in-progress versions pinned to a git hash. For example: # -# extra-deps: +extra-deps: + - plugins-1.6.0 # - acme-missiles-0.3 # - git: https://github.com/commercialhaskell/stack.git # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a diff --git a/stack.yaml.lock b/stack.yaml.lock index 3be9a4b..7a2faa7 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -3,10 +3,17 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] +packages: +- completed: + hackage: plugins-1.6.0@sha256:5eb50363b5f7a5539d91db5ce245adc2fd5bec634c58ad8c9498fcfd1c183d69,2531 + pantry-tree: + size: 1526 + sha256: 2805b6d574a4603833a17ce18974f7fbbdafba3db281dd3400422e3a36cb5762 + original: + hackage: plugins-1.6.0 snapshots: - completed: - size: 532381 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/13.yaml - sha256: 6ee17f7996e5bc75ae4406250841f1362ad4196418a4d90a0615ff4f26ac98df - original: lts-16.13 + size: 524996 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/27.yaml + sha256: 7ea31a280c56bf36ff591a7397cc384d0dff622e7f9e4225b47d8980f019a0f0 + original: lts-14.27