Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/nifmake/nifmake.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## by a .nif file or it can translate this file to a Makefile.

import std/[assertions, os, strutils, sequtils, tables, hashes, times, monotimes, sets, parseopt, syncio, osproc, algorithm, terminal]
import ".." / lib / [bitabs, lineinfos, nifreader, tooldirs, argsfinder, vfs, nifpools, nimversion]

Check warning on line 12 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot macos-arm64-nim-devel (master)

imported and not used: 'lineinfos' [UnusedImport]

Check warning on line 12 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot linux-amd64-nim-devel (master)

imported and not used: 'lineinfos' [UnusedImport]

Check warning on line 12 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot windows-amd64-nim-devel (master)

imported and not used: 'lineinfos' [UnusedImport]
when defined(windows):
import std/winlean
else:
Expand Down Expand Up @@ -91,7 +91,7 @@
cmdRun, cmdMakefile, cmdHelp, cmdVersion

CliOption = enum
Parallel, Force, Rerun, Verbose, Profile, Report, Progress
Parallel, Force, Rerun, Verbose, Profile, Report, Progress, KeepGoing

CmdStats = object
sec: float
Expand Down Expand Up @@ -374,6 +374,7 @@
stdout.write ")"
stdout.write ": "
stdout.writeLine command
stdout.flushFile()

proc toSeconds(d: Duration): float =
float(d.inNanoseconds) / 1e9
Expand Down Expand Up @@ -655,7 +656,7 @@

while sched.done < sortedNodes.len:
# Dispatch everything that fits.
while not aborted and pool.len < jobs and sched.ready.len > 0:
while (not aborted or KeepGoing in opt) and pool.len < jobs and sched.ready.len > 0:
let nodeId = sched.takeReady()
let node = addr dag.nodes[nodeId]
if Force in opt or Rerun in opt or needsRebuild(sc, node[]):
Expand Down Expand Up @@ -739,7 +740,7 @@
## `--lock`: wait until this process holds the OS lock on the file `path`.
## The OS drops it when the process ends, however it ends, so a crashed
## build never leaves it held.
if not open(result, path, fmAppend):

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot macos-arm64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot linux-amd64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot windows-amd64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / linux-arm64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]

Check warning on line 743 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

use explicit initialization of 'result' for clarity [Uninit]
quit "nifmake: cannot open the lock file " & path
when defined(windows):
const LockfileExclusiveLock = 2'i32
Expand Down Expand Up @@ -951,6 +952,8 @@

Options:
-j, --parallel[:N] Parallel builds (for 'run'); :N caps at N processes
-k, --keepgoing Keep going after a command fails (for 'run'), skipping
what depends on it. The run still fails.
--makefile:<name> Output Makefile name (default: Makefile)
--force Force rebuild of all targets
--rerun Run every command regardless of staleness, but leave
Expand Down Expand Up @@ -1080,7 +1083,7 @@
progressHi = 100
lockFile = ""

var p = initOptParser(allowWhitespaceAfterColon = false)

Check warning on line 1086 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot macos-arm64-nim-devel (master)

`allowWhitespaceAfterColon` is deprecated, use parser modes instead; initOptParser is deprecated [Deprecated]

Check warning on line 1086 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot linux-amd64-nim-devel (master)

`allowWhitespaceAfterColon` is deprecated, use parser modes instead; initOptParser is deprecated [Deprecated]

Check warning on line 1086 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / boot windows-amd64-nim-devel (master)

`allowWhitespaceAfterColon` is deprecated, use parser modes instead; initOptParser is deprecated [Deprecated]

Check warning on line 1086 in src/nifmake/nifmake.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

`allowWhitespaceAfterColon` is deprecated, use parser modes instead; initOptParser is deprecated [Deprecated]
for kind, key, val in p.getopt():
case kind
of cmdArgument:
Expand Down Expand Up @@ -1113,6 +1116,7 @@
if gMaxJobs < 1: quit "--parallel value must be >= 1"
of "makefile": outputMakefile = val
of "force": opt.incl Force
of "keepgoing", "k": opt.incl KeepGoing
of "rerun": opt.incl Rerun
of "verbose": opt.incl Verbose
of "base": baseDir = val
Expand Down
27 changes: 20 additions & 7 deletions tests/nifmake/setup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ proc runJob(job, dir: string) =
when defined(posix):
discard posix.kill(posix.getpid(), SIGTERM)
quit "FAILURE: signal job survived"
of "first", "blocked": discard
of "first", "blocked", "after": discard
else: quit "FAILURE: unknown job " & job
writeFile(dir / job, "done\n")

Expand Down Expand Up @@ -83,7 +83,7 @@ let root = currentSourcePath().parentDir.parentDir.parentDir
let cache = root / "nimcache_static" / "nifmake-jobs"
createDir(cache)

for scenario in ["serial", "parallel", "failure", "signal"]:
for scenario in ["serial", "parallel", "failure", "signal", "keepgoing"]:
when not defined(posix):
if scenario == "signal": continue
let dir = cache / scenario
Expand All @@ -101,13 +101,20 @@ for scenario in ["serial", "parallel", "failure", "signal"]:
graph.addJob(dir, "fast")
graph.addJob(dir, "dependent", "fast")
else:
# `after` becomes ready only once the failure was seen: `running` waits for
# the failing child to start.
let failing = if scenario == "keepgoing": "failure" else: scenario
graph.addJob(dir, "running")
graph.addJob(dir, scenario)
graph.addJob(dir, "blocked", scenario)
graph.addJob(dir, failing)
graph.addJob(dir, "blocked", failing)
graph.addJob(dir, "after", "running")
graph.add ")\n"
let graphFile = dir / "build.nif"
writeFile(graphFile, graph)
let parallel = if scenario == "serial": "" else: " --parallel:2"
let parallel = case scenario
of "serial": ""
of "keepgoing": " --parallel:2 --keepgoing"
else: " --parallel:2"
let command = nifmake & parallel & " --profile --report run " & graphFile.quoteShell
let (output, code) = execCmdEx(command)
writeFile(dir / "result.log", output)
Expand All @@ -122,10 +129,16 @@ for scenario in ["serial", "parallel", "failure", "signal"]:
require(cachedCode == 0 and cached.contains("total=0"),
"up-to-date build launched commands:\n" & cached)
else:
let expectedExit = if scenario == "failure": 7 else: 143
let expectedExit = if scenario == "signal": 143 else: 7
require(code != 0 and output.contains("exit code " & $expectedExit),
"wrong child failure status:\n" & output)
require(output.contains("total=2") and fileExists(dir / "running"),
require(fileExists(dir / "running"),
"did not drain the other running child:\n" & output)
require(not fileExists(dir / "blocked"), "launched dependent of failed child")
if scenario == "keepgoing":
require(output.contains("total=3") and fileExists(dir / "after"),
"--keepgoing stopped an independent job:\n" & output)
else:
require(output.contains("total=2") and not fileExists(dir / "after"),
"launched a job after a failure:\n" & output)
echo "nifmake: ", scenario, " execution passed"
Loading