diff options
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 64 |
1 files changed, 53 insertions, 11 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 0e6daf4..dc38e39 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -210,6 +210,7 @@ data Compiler | Guile | NixBuild | Rustc + | Sbcl deriving (Eq, Show, Generic, Aeson.ToJSON) data Target = Target @@ -233,6 +234,7 @@ data Target = Target -- | We can't build everything yet... isBuildableNs :: Namespace -> Bool isBuildableNs (Namespace _ Namespace.Hs) = True +isBuildableNs (Namespace _ Namespace.Lisp) = True isBuildableNs (Namespace _ Namespace.Scm) = False isBuildableNs (Namespace _ Namespace.Rs) = True isBuildableNs ns @@ -289,6 +291,9 @@ detectImports (Namespace _ Namespace.Hs) contentLines = do /> map langdeps /> mconcat pure <| pkgs <> transitivePkgs +detectImports (Namespace _ Namespace.Lisp) contentLines = do + let requires = contentLines /> Text.unpack /> Regex.match lispRequires |> catMaybes + pure <| Set.fromList requires detectImports _ _ = Exit.die "can only detectImports for Haskell" -- | TODO: globally cache analyses, so I'm not re-analyzing modules all the @@ -305,7 +310,7 @@ analyze path = do Log.info ["bild", "analyze", str path] let ns = if "hs" `List.isSuffixOf` path - then Namespace.fromContent <| Text.unpack content + then Namespace.fromHaskellContent <| Text.unpack content else Namespace.fromPath root absPath case ns of Nothing -> @@ -337,6 +342,21 @@ analyze path = do |> Set.fromList, .. } + Namespace.Lisp -> do + langdeps <- detectImports namespace contentLines + pure + Target + { sysdeps = Set.empty, + compiler = Sbcl, + out = + contentLines + /> Text.unpack + /> Regex.match (metaOut ";;") + |> catMaybes + |> head, + builder = user <> "@localhost", + .. + } Namespace.Nix -> pure Target @@ -586,14 +606,7 @@ build andTest loud target@Target {..} = do Log.warn ["bild", "copy", "TODO", nschunk namespace] pure Exit.ExitSuccess Rustc -> do - Log.info - [ "bild", - "rust", - if Text.null builder - then "local" - else builder, - nschunk namespace - ] + Log.info ["bild", "dev", "rust", nschunk namespace] proc loud namespace @@ -602,6 +615,19 @@ build andTest loud target@Target {..} = do "-o", root </> bindir </> Maybe.fromJust out ] + Sbcl -> do + Log.info ["bild", "dev", "lisp", nschunk namespace] + proc + loud + namespace + "sbcl" + [ "--load", + path, + "--eval", + "(require :asdf)", + "--eval", + "(sb-ext:save-lisp-and-die #p\"" <> (root </> bindir </> Maybe.fromJust out) <> "\" :toplevel #'main :executable t)" + ] data Proc = Proc { loud :: Bool, @@ -667,6 +693,22 @@ haskellImports = *> Regex.many (Regex.psym Char.isSpace) *> Regex.some (Regex.psym isModuleChar) <* Regex.many Regex.anySym + +isModuleChar :: Char -> Bool +isModuleChar c = + elem c <| concat [['A' .. 'Z'], ['a' .. 'z'], ['.', '_'], ['0' .. '9']] + +-- Matches on `(require :package)` forms and returns `package`. The `require` +-- function is technically deprecated in Common Lisp, but no new spec has been +-- published with a replacement, and I don't wanna use asdf, so this is what we +-- use for Lisp imports. +lispRequires :: Regex.RE Char String +lispRequires = + Regex.string "(require" + *> Regex.some (Regex.psym Char.isSpace) + *> Regex.many (Regex.psym isQuote) + *> Regex.many (Regex.psym isModuleChar) + <* Regex.many (Regex.psym (== ')')) where - isModuleChar c = - elem c <| concat [['A' .. 'Z'], ['a' .. 'z'], ['.', '_'], ['0' .. '9']] + isQuote :: Char -> Bool + isQuote c = c `elem` ['\'', ':'] |