summaryrefslogtreecommitdiff
path: root/Biz/Bild.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r--Biz/Bild.hs94
1 files changed, 60 insertions, 34 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 9c4f035..22d3882 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -312,10 +312,10 @@ data Target = Target
deriving (Show, Generic, Aeson.ToJSON)
-- | Use this to just get a target to play with at the repl.
-dev_getTarget :: IO Target
-dev_getTarget = do
+dev_getTarget :: FilePath -> IO Target
+dev_getTarget fp = do
root <- Env.getEnv "BIZ_ROOT"
- path <- Dir.makeAbsolute "Biz/Bild.hs"
+ path <- Dir.makeAbsolute fp
Namespace.fromPath root path
|> \case
Nothing -> panic "Could not get namespace from path"
@@ -448,34 +448,35 @@ analyze hmap ns = case Map.lookup ns hmap of
Namespace.Md -> pure Nothing
Namespace.None -> pure Nothing
Namespace.Py ->
- Meta.detectAll "#" contentLines |> \Meta.Parsed {..} ->
- Target
- { builder = "python",
- wrapper = Nothing,
- compiler = CPython,
- compilerFlags =
- -- This doesn't really make sense for python, but I'll leave
- -- it here for eventual --dev builds
- [ "-c",
- "\"import py_compile;import os;"
- <> "py_compile.compile(file='"
- <> str quapath
- <> "', cfile=os.getenv('BIZ_ROOT')+'/_/int/"
- <> str quapath
- <> "', doraise=True)\""
- ],
- sysdeps = psys,
- langdeps = pdep,
- outPath = outToPath pout,
- out = pout,
- -- implement detectPythonImports, then I can fill this out
- srcs = Set.empty,
- packageSet = "python.packages",
- mainModule = Namespace.toModule namespace,
- ..
- }
- |> Just
- |> pure
+ contentLines
+ |> Meta.detectAll "#"
+ |> \Meta.Parsed {..} ->
+ detectPythonImports contentLines +> \srcs ->
+ Target
+ { builder = "python",
+ wrapper = Nothing,
+ compiler = CPython,
+ compilerFlags =
+ -- This doesn't really make sense for python, but I'll leave
+ -- it here for eventual --dev builds
+ [ "-c",
+ "\"import py_compile;import os;"
+ <> "py_compile.compile(file='"
+ <> str quapath
+ <> "', cfile=os.getenv('BIZ_ROOT')+'/_/int/"
+ <> str quapath
+ <> "', doraise=True)\""
+ ],
+ sysdeps = psys,
+ langdeps = pdep,
+ outPath = outToPath pout,
+ out = pout,
+ packageSet = "python.packages",
+ mainModule = Namespace.toModule namespace,
+ ..
+ }
+ |> Just
+ |> pure
Namespace.Sh -> pure Nothing
Namespace.C ->
Meta.detectAll "//" contentLines |> \Meta.Parsed {..} -> do
@@ -713,6 +714,27 @@ detectLispImports contentLines =
|> Set.fromList
|> pure
+-- | Finds local imports. Does not recurse to find transitive imports like
+-- 'detectHaskellImports' does. Someday I will refactor these detection
+-- functions and have a common, well-performing, complete solution.
+detectPythonImports :: [Text] -> IO (Set FilePath)
+detectPythonImports contentLines =
+ contentLines
+ /> Text.unpack
+ /> Regex.match pythonImport
+ |> catMaybes
+ /> Namespace.fromPythonModule
+ /> Namespace.toPath
+ |> filterM Dir.doesPathExist
+ /> Set.fromList
+ where
+ -- only detects 'import x' because I don't like 'from'
+ pythonImport :: Regex.RE Char String
+ pythonImport =
+ Regex.string "import"
+ *> Regex.some (Regex.psym Char.isSpace)
+ *> Regex.many (Regex.psym isModuleChar)
+
ghcPkgFindModule :: Set String -> String -> IO (Set String)
ghcPkgFindModule acc m =
Env.getEnv "GHC_PACKAGE_PATH" +> \packageDb ->
@@ -755,9 +777,13 @@ build andTest loud analysis =
Env.getEnv "BIZ_ROOT" +> \root ->
forM (Map.elems analysis) <| \target@Target {..} ->
fst </ case compiler of
- CPython ->
- Log.info ["bild", "nix", "python", nschunk namespace]
- >> nixBuild loud target
+ CPython -> case out of
+ Meta.Bin _ ->
+ Log.info ["bild", "nix", "python", nschunk namespace]
+ >> nixBuild loud target
+ _ ->
+ Log.info ["bild", "nix", "python", nschunk namespace, "cannot build library"]
+ >> pure (Exit.ExitSuccess, mempty)
Gcc ->
Log.info ["bild", label, "gcc", nschunk namespace]
>> nixBuild loud target