@imp/rules/imp/generate

Module: @imp/rules/imp/generate.

generated_file_is_stale(path, before, digest)

Report whether the generated content at digest differs from the workspace content at path. before is the CAS digest of the workspace files, as a generated_files() result gives it. A missing file is stale.

Source: rules/imp/generate/index.luau:218.

generated_files(options)

Declare a graph-native generated-files root.

The result is a task handle for the GENERATE slot of @imp/rules/workflows/generate. The task has one artifact output for each output path, and a before value: the CAS digest of the same paths in the workspace when the goal ran. The goal reads the path of each file from its artifact. The generator stays hermetic and cacheable: it runs in a sandbox, keeps its outputs in CAS, and does not know about the check flag. Thus imp generate and imp generate --check share one cache entry. The workflow compares the outputs with the workspace and writes them at the goal boundary.

A separate task captures the current workspace files of output_paths. Thus a change to a generated file in the workspace does not change the cache key of the generator. The capture uses the workspace file walk, so a gitignored output path is always reported as stale. The capture reads each output path as a glob pattern, so an output path must not contain *, ?, [, ], {, or }.

Options: display Optional action label. tools Optional table of named tool handles. Each tool is on PATH when the generator runs. inputs Optional table of named source handles that the generator reads. output_paths Workspace-relative paths that the generator writes. argv function(exec, resolved) that returns the generator command line.

Example (ci/BUILD.luau):

local generate = require("@imp/rules/imp/generate") local workflow = require("@imp/rules/workflows/generate")

return { docs_workflow = { [workflow.GENERATE] = generate.generated_files({ display = "generate GitHub workflows", tools = { python3 = core.native_tool("python3") }, inputs = { script = core.files({ include = { SCRIPT } }) }, output_paths = { ".github/workflows/docs.yml" }, argv = function(_exec, _resolved) return { "python3", SCRIPT, ".github/workflows/docs.yml" } end, }), }, }

Source: rules/imp/generate/index.luau:153.

generated_root_files(result)

Return the generated files of a resolved generator root, sorted by path: an array of { path, digest }. A goal receives each artifact as a { type = "artifact", digest, path } table, and path is the declared output path. A root with one output resolves to that artifact.

Source: rules/imp/generate/index.luau:192.

generator_task(api, options)

Declare a task that runs the generator and returns one artifact for each output path. This function is internal to the generator entrypoints.

Source: rules/imp/generate/index.luau:60.

plan_generated_outputs(api, options)

Validate the options that generated_files() and the codegen() of @imp/rules/imp/codegen have in common, and name one action output slot for each output path.

The two functions differ only in where their outputs go: the workspace, or the graph. Thus they share one set of rules about what a caller can declare. This function is internal to the two generator entrypoints. It is not part of the public rule API.

Returns { tool_names, input_names, slots }.

Source: rules/imp/generate/index.luau:24.