diff options
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index d8cdc6f..d178a83 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -10,6 +10,7 @@ -- | A specific-purpose build tool. -- -- : out bild +-- : run git -- -- == Design constraints -- @@ -157,7 +158,8 @@ main = Cli.Plan help move test_ pure |> Cli.main Test.group "Biz.Bild" [ test_bildBild, - test_bildExamples + test_bildExamples, + test_isGitIgnored ] test_bildBild :: Test.Tree @@ -196,11 +198,10 @@ move args = IO.hSetBuffering stdout IO.NoBuffering >> Env.getEnv "CODEROOT" +> \root -> Cli.getAllArgs args (Cli.argument "target") - |> filter (not <. Namespace.isCab) |> filterM Dir.doesFileExist + +> filterM (\x -> isGitIgnored x /> don't) +> traverse Dir.makeAbsolute - /> map (Namespace.fromPath root) - /> catMaybes + +> traverse (namespaceFromPathOrDie root) +> foldM analyze mempty /> Map.filter (namespace .> isBuildableNs) +> printOrBuild @@ -223,6 +224,11 @@ move args = Just n -> n printOrBuild :: Analysis -> IO [ExitCode] printOrBuild targets + | Map.null targets = + Log.wipe + >> Log.fail ["bild", "nothing to build"] + >> Log.br + >> exitWith (ExitFailure 1) | args `Cli.has` Cli.longOption "json" = Log.wipe >> putJSON targets >> pure [Exit.ExitSuccess] | otherwise = do @@ -233,6 +239,35 @@ move args = isLoud = args `Cli.has` Cli.longOption "loud" putJSON = Aeson.encode .> ByteString.Lazy.toStrict .> Char8.putStrLn +-- | Don't try to build stuff that isn't part of the git repo. +isGitIgnored :: FilePath -> IO Bool +isGitIgnored path = + Process.readProcessWithExitCode "git" ["check-ignore", path] "" + +> \case + (ExitSuccess, _, _) -> pure True + (ExitFailure _, _, _) -> pure False + +test_isGitIgnored :: Test.Tree +test_isGitIgnored = + Test.group + "isGitIgnored" + [ Test.unit "filters one" <| do + res <- isGitIgnored "_" + res @=? True, + Test.unit "filters many" <| do + traverse isGitIgnored ["Biz/Bild.hs", "__pycache__"] + +> (@=? [False, True]) + ] + +namespaceFromPathOrDie :: FilePath -> FilePath -> IO Namespace +namespaceFromPathOrDie root path = + Namespace.fromPath root path |> \case + Just x -> pure x + Nothing -> + Log.fail ["bild", str path, "could not get namespace"] + >> Log.br + >> exitWith (ExitFailure 1) + nixStore :: String nixStore = "/nix/store/00000000000000000000000000000000-" @@ -367,21 +402,24 @@ instance ToNixFlag Builder where -- | We can't build everything yet... isBuildableNs :: Namespace -> Bool isBuildableNs = \case + (Namespace _ Namespace.Bash) -> False (Namespace _ Namespace.C) -> True (Namespace _ Namespace.Css) -> False (Namespace _ Namespace.Hs) -> True + (Namespace _ Namespace.Html) -> False (Namespace _ Namespace.Json) -> False (Namespace _ Namespace.Keys) -> False (Namespace _ Namespace.Lisp) -> True (Namespace _ Namespace.Md) -> False + (Namespace path Namespace.Nix) + | path `elem` nixTargets -> True + | otherwise -> False (Namespace _ Namespace.None) -> False (Namespace _ Namespace.Py) -> True (Namespace _ Namespace.Sh) -> False (Namespace _ Namespace.Scm) -> True (Namespace _ Namespace.Rs) -> True - (Namespace path Namespace.Nix) - | path `elem` nixTargets -> True - | otherwise -> False + (Namespace _ Namespace.Toml) -> True where nixTargets = [ ["Biz", "Pie"], @@ -461,11 +499,14 @@ analyze hmap ns = case Map.lookup ns hmap of /> Text.lines case ext of -- basically we don't support building these + Namespace.Bash -> pure Nothing Namespace.Css -> pure Nothing Namespace.Json -> pure Nothing Namespace.Keys -> pure Nothing Namespace.Md -> pure Nothing Namespace.None -> pure Nothing + Namespace.Html -> pure Nothing + Namespace.Toml -> pure Nothing Namespace.Py -> contentLines |> Meta.detectAll "#" |