From 985da04a702f78fd569e62a8df119adb72b9d537 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 5 Aug 2022 20:39:17 -0400 Subject: Refactoring to simplify some code Reduced duplication of out and sysdeps detection. Some other readibility cleanups. --- Biz/Bild.hs | 69 +++++++++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 48 deletions(-) (limited to 'Biz') diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 07a4fee..5af1676 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -356,7 +356,7 @@ analyze hmap ns = case Map.lookup ns hmap of root <- Env.getEnv "BIZ_ROOT" absPath <- Dir.makeAbsolute path user <- Env.getEnv "USER" /> Text.pack - host <- Text.pack fromMaybe "interactive" /> Text.pack Log.info ["bild", "analyze", str path] case ext of -- basically we don't support building these @@ -368,19 +368,8 @@ analyze hmap ns = case Map.lookup ns hmap of Namespace.Py -> pure Nothing Namespace.Sh -> pure Nothing Namespace.C -> do - let out = - contentLines - /> Text.unpack - /> Regex.match (metaOut "//" <|> metaLib "//") - |> catMaybes - |> head - |> fromMaybe None - let sysdeps = - contentLines - /> Text.unpack - /> Regex.match (metaSys "//") - |> catMaybes - |> Set.fromList + let out = detectOut (metaOut "//" <|> metaLib "//") contentLines + let sysdeps = detectSysdeps (metaSys "//") contentLines ("guile_3_0" `elem` sysdeps) ?. ( pure mempty, Process.readProcess "guile-config" ["compile"] "" @@ -407,13 +396,7 @@ analyze hmap ns = case Map.lookup ns hmap of |> pure Namespace.Hs -> do langdeps <- detectHaskellImports contentLines - let out = - contentLines - /> Text.unpack - /> Regex.match (metaOut "--") - |> catMaybes - |> head - |> fromMaybe None + let out = detectOut (metaOut "--") contentLines Just Text.unpack - /> Regex.match (metaSys "--") - |> catMaybes - |> Set.fromList, + sysdeps = detectSysdeps (metaSys "--") contentLines, outPath = outToPath out, .. } Namespace.Lisp -> do - let out = - contentLines - /> Text.unpack - /> Regex.match (metaOut ";;") - |> catMaybes - |> head - |> fromMaybe None + let out = detectOut (metaOut ";;") contentLines langdeps <- detectLispImports contentLines Just do - let out = - contentLines - /> Text.unpack - /> Regex.match (metaOut ";;") - |> catMaybes - |> head - |> fromMaybe None + let out = detectOut (metaOut ";;") contentLines Just do - let out = - contentLines - /> Text.unpack - /> Regex.match (metaOut "//") - |> catMaybes - |> head - |> fromMaybe None + let out = detectOut (metaOut "//") contentLines Just Text.unpack /> Regex.match lispRequires |> catMaybes pure <| Set.fromList requires + detectOut m cl = + cl + /> Text.unpack + /> Regex.match m + |> catMaybes + |> head + |> fromMaybe None + detectSysdeps m cl = + cl + /> Text.unpack + /> Regex.match m + |> catMaybes + |> Set.fromList ghcPkgFindModule :: Set String -> String -> IO (Set String) ghcPkgFindModule acc m = do -- cgit v1.2.3