diff options
author | Ben Sima <ben@bsima.me> | 2022-08-02 11:53:55 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2022-08-02 11:53:55 -0400 |
commit | 0727ad4ea80991e2fb104090b6d922557bbea281 (patch) | |
tree | be960ca3530a18278301a8d6ca6f14dc2da0302f /Biz/Bild.hs | |
parent | 25c1d6a43fbfbf8896f5528e4015dadb57c02177 (diff) |
Break up monolithic detectImports function
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index c5777f9..0489185 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -289,29 +289,6 @@ removeVersion = takeWhile (/= '.') .> butlast2 where butlast2 s = take (length s - 2) s -detectImports :: Namespace -> [Text] -> IO (Set Dep) -detectImports (Namespace _ Namespace.Hs) contentLines = do - let imports = - contentLines - /> Text.unpack - /> Regex.match haskellImports - |> catMaybes - pkgs <- foldM ghcPkgFindModule Set.empty imports - transitivePkgs <- - imports - |> map (Namespace.fromHaskellModule .> Namespace.toPath) - |> traverse Dir.makeAbsolute - +> filterM Dir.doesFileExist - +> Async.mapConcurrently analyze - /> catMaybes - /> 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 -- time. This is important as it would speed up building by a lot. analyze :: FilePath -> IO (Maybe Target) @@ -376,7 +353,7 @@ analyze path = do .. } Namespace.Hs -> do - langdeps <- detectImports namespace contentLines + langdeps <- detectHaskellImports contentLines let out = contentLines /> Text.unpack @@ -396,7 +373,7 @@ analyze path = do .. } Namespace.Lisp -> do - langdeps <- detectImports namespace contentLines + langdeps <- detectLispImports contentLines pure Target { sysdeps = Set.empty, @@ -460,6 +437,28 @@ analyze path = do builder = user <> "@localhost", .. } + where + detectHaskellImports :: [Text] -> IO (Set Dep) + detectHaskellImports contentLines = do + let imports = + contentLines + /> Text.unpack + /> Regex.match haskellImports + |> catMaybes + pkgs <- foldM ghcPkgFindModule Set.empty imports + transitivePkgs <- + imports + |> map (Namespace.fromHaskellModule .> Namespace.toPath) + |> traverse Dir.makeAbsolute + +> filterM Dir.doesFileExist + +> Async.mapConcurrently analyze + /> catMaybes + /> map langdeps + /> mconcat + pure <| pkgs <> transitivePkgs + detectLispImports contentLines = do + let requires = contentLines /> Text.unpack /> Regex.match lispRequires |> catMaybes + pure <| Set.fromList requires ghcPkgFindModule :: Set String -> String -> IO (Set String) ghcPkgFindModule acc m = do |