Skip to content

Commit 3e9d8c0

Browse files
authored
Merge pull request #361 from pkgxdev/better-debugging
feat(build): Print config logs on build failure if debug verbosity enabled
2 parents a478884 + a34add7 commit 3e9d8c0

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎build/build.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fix_up from "brewkit/porcelain/fix-up.ts"
66
import { Command } from "cliffy/command/mod.ts"
77
import fetch from "brewkit/porcelain/fetch.ts"
88
import get_config, { platform_cache } from "brewkit/config.ts"
9-
import { Path, hooks, utils } from "pkgx"
9+
import { Path, hooks, utils, Verbosity, verbosity } from "pkgx"
1010
import * as YAML from "deno/yaml/mod.ts"
1111
const { useConfig } = hooks
1212
const { host } = utils
@@ -134,7 +134,23 @@ platform_cache(() => config.path.home).mkdir('p') // we’ve indeed found thing
134134

135135
const proc = new Deno.Command(script.string, {clearEnv: true, env}).spawn()
136136
const rv = await proc.status
137-
if (!rv.success) throw new Error(`UR BUILD FAILED WITH CODE ${rv.code} & SIGNAL ${rv.signal}`)
137+
if (!rv.success) {
138+
// If verbosity is debug (DEBUG=1, or GITHUB_ACTIONS=true with RUNNER_DEBUG=1), print config logs to aid diagnosis
139+
if (verbosity >= Verbosity.debug) {
140+
const wanted = new Set(['config.log', 'CMakeError.log', 'CMakeOutput.log', 'meson-log.txt'])
141+
try {
142+
console.debug("\n==== CONFIG LOGS ====")
143+
for await (const [path, { isFile }] of config.path.build.walk()) {
144+
if (isFile && wanted.has(path.basename())) {
145+
console.debug(`==== START ${path} ====`)
146+
console.debug(await path.read())
147+
console.debug(`==== END ${path} ====`)
148+
}
149+
}
150+
} catch (err) { console.warn("failed to read config logs:", err) }
151+
}
152+
throw new Error(`UR BUILD FAILED WITH CODE ${rv.code} & SIGNAL ${rv.signal}`)
153+
}
138154

139155
/// move installation products to destination
140156
await gum(`rsync install to final path`)

‎lib/pkgx.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export enum Verbosity {
3434
trace = 3
3535
}
3636

37-
(() => {
38-
const verbosity = getVerbosity(Deno.env.toObject())
37+
export const verbosity = getVerbosity(Deno.env.toObject())
3938

39+
;(() => {
4040
function noop() {}
4141
if (verbosity < Verbosity.debug) console.debug = noop
4242
if (verbosity < Verbosity.normal) {

0 commit comments

Comments
 (0)