rules/imp/codegen/index.js
Developer reference: this page includes exported implementation details. BUILD authors should prefer the User API reference.
CODEGEN
const CODEGEN
The contract a codegen() result carries, so a consuming rule can recognize one and take every file it declares. Deliberately a plain symbol and not a goal(): nothing invokes codegen on its own. It is built because a package depends on it, and imp build on the target below builds it directly. Writing generated sources into the workspace is imp generate's job, and that is a different declaration.
dedupeGeneratedSrcs()
dedupeGeneratedSrcs(list, { rule } = {})
Collapse generated sources that share one workspace path, and reject a real conflict: two different artifacts both claiming that path, which would overwrite each other in the sandbox with the winner decided by input order. A rule that stages generated sources over a whole dependency closure (one odin build compiles every package it reaches) runs the merged list through this; a rule that stages only its own package still gets the within-list dedupe.
| Parameter | Type | Description |
|---|---|---|
| list | Array<{artifact: object, expectedPath: string}> | |
| opts | object | |
| opts.rule | string | Consuming rule name, for error messages. |
Returns: Array<{artifact: object, expectedPath: string}>
assertGeneratedSrcPath()
assertGeneratedSrcPath(rule, index, actual, expected)
The run-time half of the staging contract: a generated source's artifact must land at exactly the workspace path its entry declared, since a language compiler only discovers files that are actually inside the package directory. Called from a consuming rule's run() once the sandbox path is known.
| Parameter | Type | Description |
|---|---|---|
| rule | string | Consuming rule name, for the error message. |
| index | number | Position in the rule's generatedSrcs, for the message. |
| actual | string | The artifact's real sandbox path (exec.path(handle)). |
| expected | string | The declared workspace-relative output path. |