diff options
author | Ben Sima <ben@bsima.me> | 2023-09-21 16:59:15 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2023-09-21 21:44:16 -0400 |
commit | dbdf4da2576f889544a33ce0bad4b8a5ff3eca87 (patch) | |
tree | 169690c7827f77b2dd7ae6e0ec45aee202d03c1c /Biz/Bild.hs | |
parent | 6e4a65579c3ade76feea0890072099f0d0caf416 (diff) |
Add a 10-minute timeout for all builds
A build should never take more than 10 minutes. If it does, then force the
programmer to make stuff faster. This should be a forcing function to either
delete unneeded code, or improve the build system.
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 22d3882..1e0422a 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -147,6 +147,7 @@ import System.FilePath (replaceExtension, (</>)) import qualified System.IO as IO import System.IO.Unsafe (unsafePerformIO) import qualified System.Process as Process +import qualified System.Timeout as Timeout import qualified Text.Regex.Applicative as Regex main :: IO () @@ -204,7 +205,22 @@ move args = /> Map.filter (namespace .> isBuildableNs) +> printOrBuild +> exitSummary + -- convert minutes to microseconds + |> Timeout.timeout (minutes * 60_000_000) + +> \case + Nothing -> + Log.wipe + >> Log.fail ["bild", "timeout after " <> tshow minutes <> " minutes"] + >> exitWith (ExitFailure 124) + Just _ -> + pure () where + minutes = + Cli.getArgWithDefault args (Cli.longOption "time") + |> readMaybe + |> \case + Nothing -> panic "could not read --time argument" + Just n -> n printOrBuild :: Analysis -> IO [ExitCode] printOrBuild targets | args `Cli.has` Cli.longOption "json" = @@ -230,10 +246,11 @@ Usage: bild [options] <target>... Options: - --test Run tests on a target after building - --loud Show all output from compiler - --json Print the build plan as JSON, don't build - -h, --help Print this info + --test, -t Run tests on a target after building + --loud, -l Show all output from compiler + --json, -j Print the build plan as JSON, don't build + --time N Set timeout to N minutes [default: 10] + --help, -h Print this info |] exitSummary :: [Exit.ExitCode] -> IO () |