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
4 changes: 2 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5680,13 +5680,13 @@ user to trust the workspace before an action the user started.

| Command | Request | Result |
| --- | --- | --- |
| `build.detect` | `{ workspaceRoot, plugins: [{ manifest }], options?: { <buildSystemID>: { <optionID>: value } }, instanceOptions?: { <buildSystemID>: { <root>: { <optionID>: value } } }, instanceDefaults?: { <buildSystemID>: { <optionID>: value } }, emptySelections?: { <buildSystemID>: { <root>: [optionID] } }, ignoredPaths?: [pattern] }` | `detection`: `{ instances, rejected: [{ index, error }], shadowed: [{ pluginID, buildSystemID, by }] }`; each instance is `{ id, pluginID, buildSystemID, displayName, root, markers, modelSource, optionFingerprint, options, droppedOptions }` plus `model` or `modelError` for `static` and `hostIntegration` sources; a `provider` source has neither. `options` contains accepted stored values after Core scope/root merging, including explicit empty selections; `droppedOptions` names rejected stored values without rewriting the source document: a value a declared option does not accept, and a value saved for an option ID the build system no longer declares (in `options`, the root's `instanceOptions` or `instanceDefaults`), which contributes nothing to `options`, the model or the fingerprint. The scan does not enter a directory `ignoredPaths` names; omitted (or `null`), it is Core's default `[".*"]`, every directory whose name starts with a dot, and `[]` ignores nothing beyond the shared scan policy. Hosts pass `storage.ignoredPaths.patterns` from `build.resolveStoredOptions`. An unusable list rejects with `plugin.build.invalidIgnoredPath` (see `build.editIgnoredPaths`). |
| `build.detect` | `{ workspaceRoot, plugins: [{ manifest }], options?: { <buildSystemID>: { <optionID>: value } }, instanceOptions?: { <buildSystemID>: { <root>: { <optionID>: value } } }, instanceDefaults?: { <buildSystemID>: { <optionID>: value } }, emptySelections?: { <buildSystemID>: { <root>: [optionID] } }, ignoredPaths?: [pattern] }` | `detection`: `{ instances, rejected: [{ index, error }], shadowed: [{ pluginID, buildSystemID, by }], pluginIgnoredPaths: [{ pluginID, buildSystemID, displayName, patterns }] }`; each instance is `{ id, pluginID, buildSystemID, displayName, root, markers, modelSource, optionFingerprint, options, droppedOptions }` plus `model` or `modelError` for `static` and `hostIntegration` sources; a `provider` source has neither. `options` contains accepted stored values after Core scope/root merging, including explicit empty selections; `droppedOptions` names rejected stored values without rewriting the source document: a value a declared option does not accept, and a value saved for an option ID the build system no longer declares (in `options`, the root's `instanceOptions` or `instanceDefaults`), which contributes nothing to `options`, the model or the fingerprint. The scan does not enter a directory `ignoredPaths` names; omitted (or `null`), it is Core's default `[".*"]`, every directory whose name starts with a dot, and `[]` supplies no workspace rules. The shared scan policy and plugin-specific defaults still apply. `pluginIgnoredPaths` holds, in build-system ID order, one entry for every winning declaration with `detection.ignoredPaths`, even if it has no instance, and is `[]` when none has any; a shadowed declaration's rules neither apply nor appear. Each list filters only that system's candidates: a candidate is dropped when it or a directory between it and the workspace root is ignored, so under `outermost` nesting a marker below an ignored root does not become an instance; at each of those directories the workspace rules decide first, so a workspace `!pattern` brings the directory back. Manifest validation compiles these lists, so a plugin with a list Core cannot compile is reported in `rejected` under its index with `plugin.manifest.invalid` at `buildSystems[<i>].detection.ignoredPaths[<j>]` and none of its build systems is detected. See [the plugin ignore fixture](../fixtures/build/detect-plugin-ignored-paths-v1.json). Hosts display these lists separately from editable workspace patterns. Hosts pass `storage.ignoredPaths.patterns` from `build.resolveStoredOptions`. An unusable workspace `ignoredPaths` list rejects with `plugin.build.invalidIgnoredPath` (see `build.editIgnoredPaths`). |
| `build.localizeOptions` | `{ language?, plugins: [{ manifest, localizations? }] }`, without the standard manifest/build-system wrapper | `{ manifests, localizations }`: one manifest per plugin in request order, with the `buildOptions` part of the first accepted translation file applied to `buildSystems[].options[]` (`displayName`, `description`, choice `title`), else as sent; one report per plugin that declares a build option when `language` is set, `{ pluginID, language, candidates, maximumBytes, readRequired, applied, rejected }` as in `plugins.settings`. Hosts send it without `localizations`, read the named candidates from the installed package, send it again with them, and detect with the returned manifests. A file that does not fit is refused whole as `plugin.build.invalidLocalization` |
| `build.projectOptions` | `{ document }`, host-read persisted v1 Build options, without a manifest | `document`: validated storage with version 1, systems and optional `ignoredPaths`; options, instance defaults, root values, explicit empty selections and saved custom choices are retained. Missing system fields normalize to empty maps; malformed, unsupported or oversized documents reject with `plugin.build.invalidOptionsDocument`. This pure operation never reads or writes a file and does not replace declared option resolution. |
| `build.resolveStoredOptions` | `{ document, local: { version: 1, document, emptySelections?: { <systemID>: { <root>: [optionID] } } } }`, without a manifest | `storage: { document, local, emptySelections, ignoredPaths: { patterns, source } }`: checked team/local merge; local values override matching keys, unrelated systems/roots/choices stay intact. `ignoredPaths` is the list `build.detect` uses: a local list replaces the team's whole (`source: "local"`), then the team's (`"team"`), then Core's default `[".*"]` (`"default"`). No filesystem I/O. Local documents are machine/workspace preferences, not team files or plugin-native configuration. Their storage syntax is [build-local-options-v1.schema.json](build-local-options-v1.schema.json), with additional cross-field membership and byte limits checked by Core. |
| `build.resolveStoredInstanceOptions` | `{ document, local, root }` in the standard manifest/build-system envelope. The preference documents use the same shapes as `build.resolveStoredOptions`. | `options`: accepted stored values keyed by option ID, using the same merge, scope and root rules as `build.detect`. Use an empty string for the workspace root. Unavailable build systems and invalid roots are rejected. No filesystem I/O. |
| `build.editStoredOption` | `{ document, local, root, optionID, value?, selectedChoices?, modelValues?, modelDefaults?, modelExcludePrefixes?, modelSelection? }` in the standard manifest/build-system envelope | `edit: { local, options }`: changes one declared local preference. Pass exactly one of raw `value` or positive `selectedChoices` for a multi-select. Explicit `value: null` removes the local override. An `optionID` the declaration no longer has (a plugin update dropped it; `build.detect` names it in `droppedOptions`) accepts only `value: null`, which removes its local workspace value, instance default and this root's value, so a host can clear what no longer applies; anything else rejects with `plugin.build.invalidOption`. When the checked set equals the defaults, Core clears the local override only if the edited root would inherit those defaults and sibling-only selections and empty markers would survive. See [the option edit fixture](../fixtures/build/option-edit-v1.json). Invalid or partially accepted edits reject before persistence. Workspace multi-selections preserve sibling-only values; explicit per-root empty markers apply only to workspace multi-select declarations. Platforms compare both native source revisions, atomically write only the local document and read back. |
| `build.editIgnoredPaths` | `{ document, local, patterns: [pattern] \| null }`, without a manifest; `patterns` is required | `edit: { local, ignoredPaths: { patterns, source } }`: the local document with its `ignoredPaths` replaced, or removed for `null` so the team list or the default applies again; `[]` is kept as an explicit choice to ignore nothing. A pattern uses `.gitignore` syntax relative to the workspace root and names directories only: as in one ignore file the last matching pattern decides, `!pattern` keeps a directory even if Git ignores it (the shared scan policy's caches and build outputs stay pruned), a pattern with a `/` before its end is anchored at the root and any other matches a directory name at any depth. At most 256 patterns of at most 1024 bytes; an empty or whitespace-padded entry, a comment, a lone `!`, a control character or an unparsable glob rejects with `plugin.build.invalidIgnoredPath` at `ignoredPaths[<index>]`, the first entry not accepted (`ignoredPaths` when they cannot be compiled together). The team document is only read; an unusable list stored in either document makes it `plugin.build.invalidOptionsDocument`. Platforms publish the local document as for `build.editStoredOption`. |
| `build.editIgnoredPaths` | `{ document, local, patterns: [pattern] \| null }`, without a manifest; `patterns` is required | `edit: { local, ignoredPaths: { patterns, source } }`: the local document with its `ignoredPaths` replaced, or removed for `null` so the team list or the default applies again; `[]` explicitly clears the workspace rules. Plugin-specific detection defaults still apply. A pattern uses `.gitignore` syntax relative to the workspace root and names directories only: as in one ignore file the last matching pattern decides, `!pattern` keeps a directory even if Git ignores it (the shared scan policy's caches and build outputs stay pruned), a pattern with a `/` before its end is anchored at the root and any other matches a directory name at any depth. At most 256 patterns of at most 1024 bytes; an empty or whitespace-padded entry, a comment, a lone `!`, a control character or an unparsable glob rejects with `plugin.build.invalidIgnoredPath` at `ignoredPaths[<index>]`, the first entry not accepted (`ignoredPaths` when they cannot be compiled together). The team document is only read; an unusable list stored in either document makes it `plugin.build.invalidOptionsDocument`. Platforms publish the local document as for `build.editStoredOption`. |
| `build.invocationPlan` | `{ root, platform: "macos" \| "linux" \| "windows" }` | `invocation`: `{ buildSystemID, root, executables, environmentInputs, runtimeDependencies, version, minimumVersion }` with project-file paths joined to `root`; every runtime dependency with a known probe, host-managed ones included, carries `version: { arguments }` |
| `build.checkToolVersion` | `{ runtime?, output }` | `version`: `{ satisfied, version? }`; `runtime` checks that runtime dependency instead of the tool |
| `build.resolveModelInputs` | `{revision, sources: [{manifest, instances: [{buildSystemID, root, state, model?, options?}]}]}` from installed enabled current-workspace sources | `modelInputs`: version 1 public snapshot with exact optional producer slots, state, normalized projects/targets/content roots, configuration fingerprint and explicitly shared options; no tasks/run/settings/private functions; see the [plugin contract](../../shared/plugins/contract/v1/README.md#optional-read-only-model-inputs) |
Expand Down
88 changes: 81 additions & 7 deletions rust/crates/build/src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::manifest::{BuildSystemDeclaration, ModelSource, Nesting, OptionKind,
use super::options;
use super::outputs::{model_value, read_model, source_marker};
use super::BuildManifest;
use lithe_plugin_model::{PluginRejection, Validation};
use lithe_plugin_model::{invalid, PluginRejection, Validation};
use lithe_protocol::CoreError;
use serde::Deserialize;
use serde_json::{json, Value};
Expand Down Expand Up @@ -57,6 +57,10 @@ pub(crate) struct DetectPlugin {

/// The declaration that answers for one build-system ID.
struct Owner<'a> {
/// The plugin's position in the request, as `rejected` reports it.
index: usize,
/// The declaration's position in the manifest's `buildSystems`.
position: usize,
plugin_id: &'a str,
declaration: &'a BuildSystemDeclaration,
}
Expand All @@ -79,6 +83,9 @@ fn is_below(path: &str, ancestor: &str) -> bool {
fn roots(
declaration: &BuildSystemDeclaration,
directories: &[lithe_execution::DirectoryContext],
workspace_root: &Path,
workspace_rules: &lithe_execution::IgnoredPaths,
plugin_rules: Option<&lithe_execution::IgnoredPaths>,
) -> Vec<(String, Vec<String>)> {
let mut candidates: Vec<(String, Vec<String>)> = directories
.iter()
Expand All @@ -90,7 +97,27 @@ fn roots(
.filter(|marker| directory.has(marker))
.map(|marker| directory.join_relative(marker))
.collect();
(!markers.is_empty()).then(|| (directory.relative.clone(), markers))
if markers.is_empty() {
return None;
}
// A pruned ancestor also excludes its descendants. The shared walk has
// already applied workspace and Git rules, so only the plugin can add exclusions.
if let Some(plugin_rules) = plugin_rules {
let path = workspace_root.join(&directory.relative);
if path
.ancestors()
.take_while(|p| *p != workspace_root)
.any(|p| {
workspace_rules
.decides(p)
.or_else(|| plugin_rules.decides(p))
== Some(true)
})
{
return None;
}
}
Some((directory.relative.clone(), markers))
})
.collect();
candidates.sort_by(|left, right| left.0.cmp(&right.0));
Expand Down Expand Up @@ -198,16 +225,18 @@ pub(crate) fn detect<M: BuildManifest>(request: DetectRequest) -> Validation<Val
let mut manifests = Vec::new();
for (index, plugin) in request.plugins.into_iter().enumerate() {
match M::validate(plugin.manifest) {
Ok(manifest) => manifests.push(manifest),
Ok(manifest) => manifests.push((index, manifest)),
Err(error) => rejected.push(json!({ "index": index, "error": error })),
}
}

let mut owners: BTreeMap<&str, Owner<'_>> = BTreeMap::new();
let mut shadowed = Vec::new();
for manifest in &manifests {
for declaration in manifest.build_systems() {
for (index, manifest) in &manifests {
for (position, declaration) in manifest.build_systems().iter().enumerate() {
let candidate = Owner {
index: *index,
position,
plugin_id: manifest.id(),
declaration,
};
Expand Down Expand Up @@ -243,17 +272,61 @@ pub(crate) fn detect<M: BuildManifest>(request: DetectRequest) -> Validation<Val
}

if owners.is_empty() {
return Ok(json!({ "instances": [], "rejected": rejected, "shadowed": shadowed }));
return Ok(json!({
"instances": [],
"rejected": rejected,
"shadowed": shadowed,
"pluginIgnoredPaths": [],
}));
}
let directories = scan_directory_root(&workspace.path, |root| {
lithe_execution::scan_ignoring(root, &ignored)
})?;
let empty = BTreeMap::new();
let mut seen = BTreeSet::new();
let mut instances = Vec::new();
let mut plugin_ignored_paths = Vec::new();
for owner in owners.values() {
let patterns = &owner.declaration.detection.ignored_paths;
let plugin_rules = if patterns.is_empty() {
None
} else {
// Manifest validation has compiled these patterns, and compiling
// does not depend on the root. Should it fail anyway, the fault is
// this declaration's: reject it as manifest validation would, instead of
// failing every build system or blaming the workspace's own rules.
match ignored_paths::compile(&workspace.path, Some(patterns)) {
Ok(rules) => {
plugin_ignored_paths.push(json!({
"pluginID": owner.plugin_id,
"buildSystemID": owner.declaration.id,
"displayName": owner.declaration.display_name,
"patterns": patterns,
}));
Some(rules)
}
Err(error) => {
let field = format!(
"buildSystems[{}].detection.{}",
owner.position,
error.field().unwrap_or("ignoredPaths")
);
rejected.push(json!({
"index": owner.index,
"error": invalid(field, error.message),
}));
continue;
}
}
};
let stored = request.options.get(&owner.declaration.id).unwrap_or(&empty);
for (root, markers) in roots(owner.declaration, &directories) {
for (root, markers) in roots(
owner.declaration,
&directories,
&workspace.path,
&ignored,
plugin_rules.as_ref(),
) {
if seen.insert((owner.declaration.id.clone(), root.clone())) {
let local = request
.instance_options
Expand Down Expand Up @@ -309,6 +382,7 @@ pub(crate) fn detect<M: BuildManifest>(request: DetectRequest) -> Validation<Val
"instances": instances,
"rejected": rejected,
"shadowed": shadowed,
"pluginIgnoredPaths": plugin_ignored_paths,
}))
}

Expand Down
14 changes: 14 additions & 0 deletions rust/crates/build/src/manifest/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use super::*;
pub(crate) struct Detection {
/// Exact file names; a directory containing any of them is a candidate.
pub(crate) markers: Vec<String>,
/// Workspace-relative directory rules applied only to this declaration's candidates.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) ignored_paths: Vec<String>,
#[serde(default)]
pub(crate) nesting: Nesting,
/// Decides between plugins declaring the same build-system ID.
Expand Down Expand Up @@ -49,6 +52,17 @@ impl BuildSystemDeclaration {
));
}
detection.markers = sorted_unique(std::mem::take(&mut detection.markers));
if !detection.ignored_paths.is_empty() {
super::super::ignored_paths::check(&detection.ignored_paths).map_err(|error| {
invalid(
format!(
"{field}.detection.{}",
error.field.as_deref().unwrap_or("ignoredPaths")
),
error.message,
)
})?;
}
if detection.priority > MAX_PRIORITY {
return Err(invalid(
format!("{field}.detection.priority"),
Expand Down
Loading
Loading