magus v0.3.0 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
2 min read

MGS1008: target missing its context parameter

Every target is an exported magusfile function whose FIRST parameter is a magus\Context. An exported function without it is rejected at load, because the signature is the contract magus reads - statically, without running the body - to build the dependency graph and cache footprint.

[MGS1008] target "build" must receive a magus\Context as its first parameter:
change its signature to export fun build(ctx: magus\Context, args: [str])
  see: .../MGS1008.md

Why

A target declares what it needs and what it touches through the context it is handed: ctx.needs(...), ctx.readsFiles(...), ctx.writesFiles(...), ctx.has_charm(...). Binding those to the received ctx - rather than a floating global - is what lets magus read the graph off the source text, so magus ls, magus affected, and the graph render never execute a target body. A function without the context parameter cannot declare anything that way, so magus rejects it rather than dispatch it with the wrong arguments. That context is also the first argument of every spell op the target calls (go["go-build"](ctx)), so a function without it cannot run one either.

Buzz qualifies a namespaced type with a backslash, so the type is spelled magus\Context (not magus.Context, which is not valid Buzz type syntax).

Resolution

Add ctx: magus\Context as the first parameter:

// before - rejected
export fun build(args: [str]) > void { go["go-build"](); }

// after
export fun build(ctx: magus\Context, args: [str]) > void { go["go-build"](ctx); }

Declare dependencies and footprint through the context:

export fun ci(ctx: magus\Context, args: [str]) > void {
    ctx.needs(lint, build, test);
}

A parameterized target keeps its extra parameters after the context: export fun release_build(ctx: magus\Context, goos: str, goarch: str) > void.

What this is NOT

  • Not about the second parameter. Only the first parameter is checked; the args: [str] is conventional and may be named or omitted.
  • Not a spell error. Spell contract functions (mgs_getName, mgs_listTargets, op definitions) are not targets and are not subject to this.

See also

  • targets: how targets declare dependencies and footprint.
MGS1008magusfiletargetscontextsignature
Last updated (3da15dc9)
Earlier changes on this page (2)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. See targets.

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. See targets.

Spell

A language/runtime adapter (e.g. go, md) that maps generic targets onto a toolchain's real commands. See spells.

Charm

An execution modifier attached with : (lint:rw) that changes how a target runs, not which one; the built-in rw flips a check-only target to mutate in place, and ci always strips it. See charms.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Cache

The content-addressed store magus consults before running a target, so unchanged work is skipped. See cache.

Affected

The set of projects touched by a change; magus affected <target> runs a target only over them. See affected.

CI

An ordinary magusfile-defined target you compose yourself with magus\needs - magus does not hardcode its stages. Magus.RunCI treats it specially only in that it strips the rw charm, it is the anchor magus affected ci keys off, and a selected scope with no project declaring it is a load error rather than a silent no-op. See targets.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.