summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2023-10-10 13:15:59 -0400
committerBen Sima <ben@bsima.me>2023-10-10 13:15:59 -0400
commit904de577261e7024373e7a42fd763184764238f9 (patch)
tree563e4968eab568466ae3e7a1c747dd24a77986c0 /Biz
parent6107f8178e26ada67e5d5ec60501e24528b3db56 (diff)
Don't swallow namespace-parsing errors
Previously, if there was a problem with the inputs and bild failed to determine the namespace, 'fromPath' would return 'Nothing' and then 'catMaybes' would drop the error-causing input altogether. In the one time that I had a bad input, this made debugging incredibly difficult. It's always a bad idea to swallow errors silently, so instead lets just kill the program if we have bad inputs.
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Bild.hs55
-rw-r--r--Biz/Bild.nix27
-rwxr-xr-xBiz/Cloud/post-receive.bash (renamed from Biz/Cloud/post-receive)0
-rw-r--r--Biz/Dev/Dns.nix8
-rw-r--r--Biz/Dev/Home.zone23
-rw-r--r--Biz/Dragons/env.bash (renamed from Biz/Dragons/env)0
-rwxr-xr-xBiz/Ide/ftags.bash (renamed from Biz/Ide/ftags)0
-rwxr-xr-xBiz/Ide/hoog.bash (renamed from Biz/Ide/hoog)0
-rwxr-xr-xBiz/Ide/hooks/commit-msg.bash (renamed from Biz/Ide/hooks/commit-msg)0
-rwxr-xr-xBiz/Ide/hooks/post-checkout.bash (renamed from Biz/Ide/hooks/post-checkout)0
-rwxr-xr-xBiz/Ide/hooks/post-merge.bash (renamed from Biz/Ide/hooks/post-merge)0
-rwxr-xr-xBiz/Ide/hooks/pre-commit.bash (renamed from Biz/Ide/hooks/pre-commit)0
-rwxr-xr-xBiz/Ide/hooks/pre-push.bash (renamed from Biz/Ide/hooks/pre-push)0
-rwxr-xr-xBiz/Ide/mktags.bash (renamed from Biz/Ide/mktags)0
-rwxr-xr-xBiz/Ide/ns.bash (renamed from Biz/Ide/ns)0
-rwxr-xr-xBiz/Ide/push.bash (renamed from Biz/Ide/push)0
-rwxr-xr-xBiz/Ide/repl.bash (renamed from Biz/Ide/repl)0
-rwxr-xr-xBiz/Ide/run.bash (renamed from Biz/Ide/run)0
-rwxr-xr-xBiz/Ide/ship.bash (renamed from Biz/Ide/ship)0
-rwxr-xr-xBiz/Ide/tidy.bash (renamed from Biz/Ide/tidy)0
-rwxr-xr-xBiz/Ide/tips13
-rwxr-xr-xBiz/Ide/tips.bash13
-rwxr-xr-xBiz/Ide/version.bash (renamed from Biz/Ide/version)0
-rw-r--r--Biz/Namespace.hs17
24 files changed, 88 insertions, 68 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 "#"
diff --git a/Biz/Bild.nix b/Biz/Bild.nix
index 1e4bcf8..9647983 100644
--- a/Biz/Bild.nix
+++ b/Biz/Bild.nix
@@ -59,18 +59,6 @@ in nixpkgs // { bild = rec {
;
};
- # this is needed to do builds without calling out to nix, remove this when I
- # switch to all-nix builds
- bildRuntimeDeps = with nixpkgs; [
- pkg-config
- # this is just to get access to ghc-pkg in bild
- (haskell.ghcWith (_: []))
-
- # lisp deps
- guile
- (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp
- ];
-
# a standard nix build for bild, for bootstrapping. this should be the only
# hand-written builder we need
bild = nixpkgs.stdenv.mkDerivation {
@@ -78,7 +66,16 @@ in nixpkgs // { bild = rec {
src = ../.;
nativeBuildInputs = [ haskell.ghcPackageSetBild ];
buildInputs = [ nixpkgs.makeWrapper ];
- propagatedBuildInputs = bildRuntimeDeps;
+ propagatedBuildInputs = with nixpkgs; [
+ pkg-config
+ git
+ # this is just to get access to ghc-pkg in bild
+ (haskell.ghcWith (_: []))
+
+ # lisp deps, remove this when i implement nix builds for lisp
+ guile
+ (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp
+ ];
strictDeps = true;
buildPhase = ''
mkdir -p $out/bin $out/lib/ghc-${haskell.ghcPackageSetFull.version}
@@ -95,7 +92,7 @@ in nixpkgs // { bild = rec {
'';
installPhase = ''
wrapProgram $out/bin/bild \
- --prefix PATH : ${lib.makeBinPath [ haskell.ghcPackageSetBild ]} \
+ --prefix PATH : ${lib.makeBinPath [ haskell.ghcPackageSetBild pkgs.git ]} \
--set GHC_PACKAGE_PATH \
$out/lib/ghc-${haskell.ghcPackageSetFull.version}/package.conf.d
'';
@@ -108,7 +105,7 @@ in nixpkgs // { bild = rec {
USER = "nixbld";
HOSTNAME = "nix-sandbox";
# this is the default sandbox path where bild will be working:
- CODEROOT = "/build/biz";
+ CODEROOT = "/build/omni";
# we need to remove the $src root because bild expects paths relative to the
# working directory:
TARGET = "." + lib.strings.removePrefix (toString src) (toString target);
diff --git a/Biz/Cloud/post-receive b/Biz/Cloud/post-receive.bash
index 4a67043..4a67043 100755
--- a/Biz/Cloud/post-receive
+++ b/Biz/Cloud/post-receive.bash
diff --git a/Biz/Dev/Dns.nix b/Biz/Dev/Dns.nix
index 4720b39..0490ead 100644
--- a/Biz/Dev/Dns.nix
+++ b/Biz/Dev/Dns.nix
@@ -18,14 +18,6 @@
extraOptions = ''
dnssec-validation auto;
'';
- zones = [
- {
- master = true;
- name = "home";
- slaves = [];
- file = ./Home.zone;
- }
- ];
};
#networking.extraHosts = ''
diff --git a/Biz/Dev/Home.zone b/Biz/Dev/Home.zone
deleted file mode 100644
index 86d4919..0000000
--- a/Biz/Dev/Home.zone
+++ /dev/null
@@ -1,23 +0,0 @@
-;$TTL 3D
-;@ IN SOA home. hostmaster (
-; 1 ; serial
-; 8H ; refresh
-; 2H ; retry
-; 4W ; expire
-; 1D) ; min ttl
-; IN NS ns.home.
-;home. IN A 192.168.0.196
-;router IN A 192.168.0.196
-;
-$TTL 1D
-@ IN SOA ns.home. hostmaster (
- 3 ; Serial
- 604800 ; Refresh
- 86400 ; Retry
- 2419200 ; Expire
- 604800 ) ; Minimum
-@ IN NS ns. ; Name Server for the domain
-@ IN A 192.168.0.196 ;
-example.com. IN A 192.168.0.1 ; test
-router IN A 192.168.0.1 ; IP address for 'router'
-lithium IN A 192.168.0.196 ; my dev server
diff --git a/Biz/Dragons/env b/Biz/Dragons/env.bash
index 86a2f69..86a2f69 100644
--- a/Biz/Dragons/env
+++ b/Biz/Dragons/env.bash
diff --git a/Biz/Ide/ftags b/Biz/Ide/ftags.bash
index 02d78c5..02d78c5 100755
--- a/Biz/Ide/ftags
+++ b/Biz/Ide/ftags.bash
diff --git a/Biz/Ide/hoog b/Biz/Ide/hoog.bash
index 976f0d4..976f0d4 100755
--- a/Biz/Ide/hoog
+++ b/Biz/Ide/hoog.bash
diff --git a/Biz/Ide/hooks/commit-msg b/Biz/Ide/hooks/commit-msg.bash
index 64e400d..64e400d 100755
--- a/Biz/Ide/hooks/commit-msg
+++ b/Biz/Ide/hooks/commit-msg.bash
diff --git a/Biz/Ide/hooks/post-checkout b/Biz/Ide/hooks/post-checkout.bash
index 73488b0..73488b0 100755
--- a/Biz/Ide/hooks/post-checkout
+++ b/Biz/Ide/hooks/post-checkout.bash
diff --git a/Biz/Ide/hooks/post-merge b/Biz/Ide/hooks/post-merge.bash
index c21211f..c21211f 100755
--- a/Biz/Ide/hooks/post-merge
+++ b/Biz/Ide/hooks/post-merge.bash
diff --git a/Biz/Ide/hooks/pre-commit b/Biz/Ide/hooks/pre-commit.bash
index 2b4575c..2b4575c 100755
--- a/Biz/Ide/hooks/pre-commit
+++ b/Biz/Ide/hooks/pre-commit.bash
diff --git a/Biz/Ide/hooks/pre-push b/Biz/Ide/hooks/pre-push.bash
index 0c313cb..0c313cb 100755
--- a/Biz/Ide/hooks/pre-push
+++ b/Biz/Ide/hooks/pre-push.bash
diff --git a/Biz/Ide/mktags b/Biz/Ide/mktags.bash
index c83f319..c83f319 100755
--- a/Biz/Ide/mktags
+++ b/Biz/Ide/mktags.bash
diff --git a/Biz/Ide/ns b/Biz/Ide/ns.bash
index e988bfe..e988bfe 100755
--- a/Biz/Ide/ns
+++ b/Biz/Ide/ns.bash
diff --git a/Biz/Ide/push b/Biz/Ide/push.bash
index 2238e06..2238e06 100755
--- a/Biz/Ide/push
+++ b/Biz/Ide/push.bash
diff --git a/Biz/Ide/repl b/Biz/Ide/repl.bash
index b10f0f0..b10f0f0 100755
--- a/Biz/Ide/repl
+++ b/Biz/Ide/repl.bash
diff --git a/Biz/Ide/run b/Biz/Ide/run.bash
index f7b9d36..f7b9d36 100755
--- a/Biz/Ide/run
+++ b/Biz/Ide/run.bash
diff --git a/Biz/Ide/ship b/Biz/Ide/ship.bash
index 33197c8..33197c8 100755
--- a/Biz/Ide/ship
+++ b/Biz/Ide/ship.bash
diff --git a/Biz/Ide/tidy b/Biz/Ide/tidy.bash
index ec666ba..ec666ba 100755
--- a/Biz/Ide/tidy
+++ b/Biz/Ide/tidy.bash
diff --git a/Biz/Ide/tips b/Biz/Ide/tips
deleted file mode 100755
index 21808eb..0000000
--- a/Biz/Ide/tips
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-echo ""
-echo "bizdev" | figlet | lolcat
-echo ""
-echo " bild compile code"
-echo " repl start a repl"
-echo " deps manage dependencies with niv"
-echo " tips show this message"
-echo " lint auto-lint all changed files"
-echo " push send a namespace to the cloud"
-echo " ship lint, bild, and push one (or all) namespace(s)"
-echo " tidy cleanup common working files"
-echo ""
diff --git a/Biz/Ide/tips.bash b/Biz/Ide/tips.bash
new file mode 100755
index 0000000..ba458ac
--- /dev/null
+++ b/Biz/Ide/tips.bash
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+echo ""
+echo "bizdev" | figlet | lolcat
+echo ""
+echo " bild.bash compile code"
+echo " repl.bash start a repl"
+echo " deps.bash manage dependencies with niv"
+echo " tips.bash show this message"
+echo " lint.bash auto-lint all changed files"
+echo " push.bash send a namespace to the cloud"
+echo " ship.bash lint, bild, and push one (or all) namespace(s)"
+echo " tidy.bash cleanup common working files"
+echo ""
diff --git a/Biz/Ide/version b/Biz/Ide/version.bash
index 5b017d9..5b017d9 100755
--- a/Biz/Ide/version
+++ b/Biz/Ide/version.bash
diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs
index 48f6277..bd283a6 100644
--- a/Biz/Namespace.hs
+++ b/Biz/Namespace.hs
@@ -31,9 +31,11 @@ import qualified Data.Text as Text
import qualified Text.Regex.Applicative as Regex
data Ext
- = C
+ = Bash
+ | C
| Css
| Hs
+ | Html
| Json
| Keys
| Lisp
@@ -44,6 +46,7 @@ data Ext
| Rs
| Scm
| Sh
+ | Toml
deriving (Eq, Show, Generic, Aeson.ToJSON, Ord)
data Namespace = Namespace {path :: [String], ext :: Ext}
@@ -65,9 +68,11 @@ toPath (Namespace parts ext) =
toExt :: Ext -> String
toExt =
("." <>) <. \case
+ Bash -> "bash"
C -> "c"
Css -> "css"
Hs -> "hs"
+ Html -> "html"
Json -> "json"
Keys -> "pub"
Lisp -> "lisp"
@@ -78,6 +83,7 @@ toExt =
Rs -> "rs"
Scm -> "scm"
Sh -> "sh"
+ Toml -> "toml"
fromHaskellContent :: String -> Maybe Namespace
fromHaskellContent c = case Regex.findFirstInfix haskellModule c of
@@ -95,6 +101,7 @@ toModule (Namespace parts Py) = joinWith "." parts
toModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")"
toModule (Namespace parts Rs) = joinWith "::" parts
toModule (Namespace parts C) = joinWith "/" parts <> ".c"
+toModule (Namespace parts Nix) = joinWith "/" parts <> ".nix"
toModule (Namespace {..}) = panic <| "toModule not implemented for " <> show ext
toHaskellModule :: Namespace -> String
@@ -115,7 +122,10 @@ dot = Regex.some <| Regex.sym '.'
name :: Regex.RE Char String
name =
Regex.many (Regex.psym Char.isUpper)
- <> Regex.many (Regex.psym (\c -> Char.isAlphaNum c || (c == '_')))
+ <> ( Regex.many
+ <| Regex.psym
+ <| \c -> Char.isAlphaNum c || c == '_' || c == '-'
+ )
rePath :: Regex.RE Char [String]
rePath = Regex.many (name <* Regex.string "/" <|> name)
@@ -125,6 +135,7 @@ reExt =
C <$ Regex.string "c"
<|> Css <$ Regex.string "css"
<|> Hs <$ Regex.string "hs"
+ <|> Html <$ Regex.string "html"
<|> Json <$ Regex.string "json"
<|> Keys <$ Regex.string "pub"
<|> Lisp <$ Regex.string "lisp"
@@ -134,6 +145,8 @@ reExt =
<|> Rs <$ Regex.string "rs"
<|> Scm <$ Regex.string "scm"
<|> Sh <$ Regex.string "sh"
+ <|> Bash <$ Regex.string "bash"
+ <|> Toml <$ Regex.string "toml"
-- | The cab dir is for temporary files and build outputs, not for source
-- inputs.