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
12 changes: 10 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ or removing a command fails until the table changes in the same commit.
| `build.decodeRunPreparation` | Validate portable launch data before the native Run host starts a process |
| `build.testDiscoveryPlan` | Plan opt-in Provider test discovery for an instance |
| `build.decodeTestDiscovery` | Validate, deduplicate and order Provider test selectors |
| `build.runEntrypointsPlan` | Plan a Provider request for the run entrypoints of one source file (`buildProviders` 1) |
| `build.decodeRunEntrypoints` | Validate and deduplicate the run entrypoints a Provider named |
| `build.dependencyPlan` | Expand the command that prints a project's dependency tree, or the request a build provider answers |
| `build.decodeModel` | Decode model output or a provider result into projects, targets, tasks, content roots, option values, and run entries |
| `build.decodeTestResults` | Decode a test run's reports and output into per-case results and a summary |
Expand Down Expand Up @@ -3672,7 +3674,11 @@ and Core preserves them unchanged.

Provider applications can be explicitly saved with `runConfig.createUserConfiguration`
using `{root,scope:"local",name,type:"buildProvider",build:{pluginID,buildSystemID,
root,run,projectID,targetID,userArguments?,execution?}}`. Core upserts the existing local
root,run,projectID,targetID,userArguments?,execution?},entrypoint?}`. An entrypoint run
(`buildProviders` 1) has an empty `targetID` and names `entrypoint`, the opaque
`launchOptions.entrypoint` a provider found with `build.decodeRunEntrypoints`; Core saves it as
`extensions.build-run.entrypoint`, and the entrypoint is part of the selector identity, so each
entrypoint is its own configuration. Core upserts the existing local
reference by selector identity and retains its existing ID (new references use `user:` IDs), unrelated configurations
and project toolchain defaults. `extensions.build` in Run v2 holds the typed
reference; optional execution is application/service/task and must match the current
Expand Down Expand Up @@ -4989,7 +4995,9 @@ and the directories are absolute host paths used only as substitution text.
| `build.testPlan` | plan fields plus `project?`, `target?`, `suite?`, `case?`, `userArguments?`, `projects?` (the model's project directories) | command plan or `provider: {method: "lithe/build/test", params}`, plus `results`: `null`, `{ decoder, reports }` with workspace-relative globs (for the selected project, or for the root and every listed project when none is selected), or command-only `{ decoder: "hostIntegration" }`. Command filters that templates cannot place, such as a case without its suite when the tool only addresses `Suite#case`, are `plugin.build.invalidSelection`; Provider filters remain separate typed values and must be declared supported |
| `build.testDiscoveryPlan` | common plan fields plus `refresh?`, `tool?`; no project/output file | `plan.provider` for `lithe/build/discoverTests`, only with `test.discovery: true`, using the same effective options and effect metadata |
| `build.decodeTestDiscovery` | common plan fields plus canonical `result` | `discovery.tests` with validated `{id, suite, case, project?, target?}` selectors; bounded at 10,000 items/32 MiB, deterministic and exactly runnable; malformed replies reject in full |
| `build.prepareRunPlan` | common plan fields, `run`, required `project`/`target`, `userArguments?`, `launchOptions?`, `workspaceRoot?` (required for an explicit launch cwd); no output file | `plan.provider` for `lithe/build/prepareRun`, selected declaration/tags/paths/options validated; typed launch options must match the run's declared execution kind, and a service or task run requires them |
| `build.runEntrypointsPlan` | common plan fields plus `file` (workspace-relative, inside the instance), `refresh?`, `tool?`; no project/output file | `plan.provider` for `lithe/build/runEntrypoints` with `file`, only when a run declares `entrypoints: true`; decoder `litheRunEntrypoints` |
| `build.decodeRunEntrypoints` | common plan fields plus canonical `result` | `entrypoints.entrypoints`: `[{run, name, entrypoint, project:{name, path}}]` in the provider's order without exact duplicates; at most 64; each names an entrypoint run, a 1–256 byte name, a 1–4,096 byte entrypoint and a project inside the instance; malformed replies reject in full with `plugin.build.invalidOutput` |
| `build.prepareRunPlan` | common plan fields, `run`, required `project`, `target` (required for a target run, refused for an entrypoint run), `userArguments?`, `launchOptions?`, `workspaceRoot?` (required for an explicit launch cwd); no output file | `plan.provider` for `lithe/build/prepareRun`, selected declaration/tags/paths/options validated; typed launch options must match the run's declared execution kind, a service or task run requires them, and an entrypoint run requires `launchOptions.entrypoint` and sends no `target` |
| `build.decodeRunPreparation` | `workspaceRoot`, instance `root`, raw `result`, same optional `launchOptions` | `launch` with portable `{executable:{kind,value},arguments,workingDirectory,environment}`; bounded strings and workspace directory containment, `plugin.build.invalidOutput` on invalid result |
| `build.prepareDebugPlan` | same selected fields as `build.prepareRunPlan`; run declares same-plugin `debug.adapter` | `plan.provider` for `lithe/build/prepareDebug`; no cross-package reference, and launch options are refused: they apply only to running a target |
| `build.decodeDebugPreparation` | `workspaceRoot`, instance `root`, selected `run`, raw `result` | `preparation` with declaration-owned `adapter`, normalized `root`, `program`, `arguments`, `workingDirectory`, `environment`; program is an existing regular file contained in the instance after canonicalization |
Expand Down
28 changes: 28 additions & 0 deletions rust/crates/build/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ pub fn build_decode_test_discovery_command<M: BuildManifest>(
)
}

/// `build.runEntrypointsPlan`: asks the provider which entrypoints a file holds.
pub fn build_run_entrypoints_plan_command<M: BuildManifest>(
payload: Value,
) -> Result<Value, CoreError> {
with_build_system::<M, _>(
payload,
"build.runEntrypointsPlan",
"plan",
|build_system, request: &super::run_entrypoints::RunEntrypointsPlanRequest| {
super::run_entrypoints::plan(build_system, request)
},
)
}

/// `build.decodeRunEntrypoints`: the entrypoints the host may save and start.
pub fn build_decode_run_entrypoints_command<M: BuildManifest>(
payload: Value,
) -> Result<Value, CoreError> {
with_build_system::<M, _>(
payload,
"build.decodeRunEntrypoints",
"entrypoints",
|build_system, request: &super::run_entrypoints::DecodeRunEntrypointsRequest| {
super::run_entrypoints::decode(build_system, request)
},
)
}

/// `build.prepareRunPlan`: validates a provider-owned target launch request.
pub fn build_prepare_run_plan_command<M: BuildManifest>(
payload: Value,
Expand Down
1 change: 1 addition & 0 deletions rust/crates/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod options;
mod outputs;
mod plans;
mod project_options;
mod run_entrypoints;
mod run_preparation;
mod run_start;
mod select;
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ pub fn validate_declarations(
}

impl BuildSystemDeclaration {
/// Whether a run starts entrypoints the provider finds in files, which
/// `buildProviders` 1 introduced.
pub fn has_run_entrypoints(&self) -> bool {
self.run.iter().any(|run| run.entrypoints)
}

/// Folder names every workspace hides at any depth while the plugin is
/// enabled (`layout.hiddenDirectoryNames`), sorted and unique once validated.
pub fn hidden_directory_names(&self) -> &[String] {
Expand Down
25 changes: 25 additions & 0 deletions rust/crates/build/src/manifest/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub(crate) struct RunDeclaration {
/// Metadata stored under `extensions.<buildSystemID>` of the entry.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub(crate) extension: BTreeMap<String, String>,
/// `buildProviders` 1: the provider names entrypoints in source files
/// (`lithe/build/runEntrypoints`), and the run starts one of them in a
/// project. It applies to no target and is never listed per target.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub(crate) entrypoints: bool,
}

/// Native launch binds a local adapter; connection attach names a public registry type.
Expand Down Expand Up @@ -108,6 +113,26 @@ impl BuildSystemDeclaration {
"Debug preparation requires a provider run.",
));
}
if run.entrypoints {
if run.source != TaskSource::Provider
|| run.from_targets.is_some()
|| run.from_tasks.is_some()
|| !run.arguments.is_empty()
|| !run.extension.is_empty()
|| run.execution.unwrap_or(BuildExecution::Application)
!= BuildExecution::Application
|| run.debug.is_some()
|| run.name.as_ref().is_some_and(|name| {
name.trim().is_empty() || name.len() > MAX_TEXT || name.contains("${")
})
{
return Err(invalid(
&field,
"Entrypoint runs are provider applications without targets, templates or debug.",
));
}
continue;
}
if run.source == TaskSource::Provider {
let valid_targets = run.from_targets.as_ref().is_some_and(|from| {
!from.tags.is_empty()
Expand Down
153 changes: 153 additions & 0 deletions rust/crates/build/src/run_entrypoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//! Entrypoints a provider finds in one source file (`buildProviders` 1).
//!
//! A run declared with `entrypoints: true` starts an entrypoint the provider
//! names, such as a class with a `main` method, in one of its projects. Core
//! never reads the source: the provider answers `lithe/build/runEntrypoints`
//! for a file and Core checks that every answer is something the run can
//! start, so the host can save and start it as an ordinary provider run.

use super::decode::{invalid_output, MAX_OUTPUT_BYTES};
use super::manifest::{BuildSystemDeclaration, TaskSource};
use super::plans::{self, OutputPlanRequest, PlanBase, SelectedEntity};
use lithe_plugin_model::Validation;
use serde::Deserialize;
use serde_json::{json, Value};

/// Version of the `litheRunEntrypoints` document a provider returns.
const ENTRYPOINTS_VERSION: u64 = 0;

/// Most entrypoints one file may name.
const MAX_ENTRYPOINTS: usize = 64;

/// Longest entrypoint name, in bytes.
const MAX_NAME: usize = 256;

/// Longest opaque entrypoint, in bytes, as `launchOptions.entrypoint` allows.
const MAX_ENTRYPOINT: usize = 4096;

/// The source file whose entrypoints the host asks for.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RunEntrypointsPlanRequest {
#[serde(flatten)]
pub(crate) base: OutputPlanRequest,
/// Workspace-relative file inside the instance root.
pub(crate) file: String,
}

/// The plan's configuration and the provider's answer.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DecodeRunEntrypointsRequest {
#[serde(flatten)]
pub(crate) base: PlanBase,
pub(crate) result: Value,
}

/// One entrypoint as the provider names it.
#[derive(Deserialize)]
struct Entrypoint {
run: String,
name: String,
entrypoint: String,
project: SelectedEntity,
}

fn has_entrypoint_run(build_system: &BuildSystemDeclaration) -> bool {
build_system
.run
.iter()
.any(|run| run.entrypoints && run.source == TaskSource::Provider)
}

/// `build.runEntrypointsPlan`: asks the provider which entrypoints `file` holds.
pub(crate) fn plan(
build_system: &BuildSystemDeclaration,
request: &RunEntrypointsPlanRequest,
) -> Validation<Value> {
if !has_entrypoint_run(build_system) {
return Err(plans::unavailable(build_system, "run entrypoints"));
}
if request.base.project.is_some() || request.base.output_file.is_some() {
return Err(plans::invalid_selection(
"Run entrypoints are found by file, not by project.",
));
}
let context = plans::PlanContext::new(build_system, &request.base.base)?;
let file = super::decode::request_path(&request.file, "file")?;
if super::decode::relative_to(&context.root, &file).is_none_or(|relative| relative == ".") {
return Err(plans::invalid_selection(
"The file is outside the build-system root.",
));
}
let mut params = plans::provider_hints(&request.base)?;
params.insert("file".to_string(), json!(file));
let provider = build_system
.provider
.as_ref()
.ok_or_else(|| plans::unavailable(build_system, "a provider"))?;
Ok(context.provider_plan(
provider,
"lithe/build/runEntrypoints",
"litheRunEntrypoints",
params,
))
}

/// `build.decodeRunEntrypoints`: the entrypoints the host may save and start, in
/// the provider's order without duplicates. A malformed answer is refused whole.
pub(crate) fn decode(
build_system: &BuildSystemDeclaration,
request: &DecodeRunEntrypointsRequest,
) -> Validation<Value> {
if !has_entrypoint_run(build_system) {
return Err(plans::unavailable(build_system, "run entrypoints"));
}
let context = plans::PlanContext::new(build_system, &request.base)?;
let result = &request.result;
if serde_json::to_vec(result).map_or(usize::MAX, |bytes| bytes.len()) > MAX_OUTPUT_BYTES
|| result["format"] != "litheRunEntrypoints"
|| result["version"] != ENTRYPOINTS_VERSION
{
return Err(invalid_output("Invalid run entrypoints document."));
}
let items = result["entrypoints"]
.as_array()
.filter(|items| items.len() <= MAX_ENTRYPOINTS)
.ok_or_else(|| invalid_output("Run entrypoints hold at most 64 entries."))?;
let mut entrypoints: Vec<Value> = Vec::new();
for item in items {
let entry: Entrypoint = serde_json::from_value(item.clone())
.map_err(|_| invalid_output("Invalid run entrypoint."))?;
let runnable = build_system.run.iter().any(|run| {
run.id == entry.run && run.entrypoints && run.source == TaskSource::Provider
});
let name = entry.name.trim();
if !runnable
|| name.is_empty()
|| name.len() > MAX_NAME
|| name.chars().any(char::is_control)
|| entry.entrypoint.is_empty()
|| entry.entrypoint.len() > MAX_ENTRYPOINT
|| entry.entrypoint.contains('\0')
{
return Err(invalid_output(
"A run entrypoint names a run, a name or an entrypoint this build system cannot start.",
));
}
let project =
plans::selection(&entry.project, &context.root, None, "project").map_err(|_| {
invalid_output("A run entrypoint's project is outside the build-system root.")
})?;
let decoded = json!({
"run": entry.run,
"name": name,
"entrypoint": entry.entrypoint,
"project": {"name": project.name, "path": project.path},
});
if !entrypoints.contains(&decoded) {
entrypoints.push(decoded);
}
}
Ok(json!({ "entrypoints": entrypoints }))
}
53 changes: 36 additions & 17 deletions rust/crates/build/src/run_preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ pub(crate) struct PrepareRunRequest {
#[serde(flatten)]
pub(crate) base: OutputPlanRequest,
pub(crate) run: String,
pub(crate) target: SelectedEntity,
/// The target of a target run; an entrypoint run has none.
#[serde(default)]
pub(crate) target: Option<SelectedEntity>,
#[serde(default)]
pub(crate) user_arguments: Vec<String>,
#[serde(default)]
Expand Down Expand Up @@ -219,29 +221,46 @@ pub(crate) fn plan(
.as_ref()
.ok_or_else(|| plans::invalid_selection("A run target needs its project."))?;
let project = plans::selection(project, &context.root, None, "project")?;
let target = plans::selection(
&request.target,
&context.root,
Some(&project.path),
"target",
)?;
if !declaration
.from_targets
.as_ref()
.is_some_and(|from| target.tags.iter().any(|tag| from.tags.contains(tag)))
{
return Err(plans::invalid_selection(
"This run does not apply to the selected target.",
));
}
let target = if declaration.entrypoints {
// An entrypoint run starts the provider's entrypoint in the project; it
// has no target, and without an entrypoint there is nothing to start.
if request.target.is_some()
|| !request
.launch_options
.as_ref()
.is_some_and(|options| options.entrypoint.is_some())
{
return Err(plans::invalid_selection(
"An entrypoint run needs an entrypoint and no target.",
));
}
None
} else {
let target = request
.target
.as_ref()
.ok_or_else(|| plans::invalid_selection("A target run needs its target."))?;
let target = plans::selection(target, &context.root, Some(&project.path), "target")?;
if !declaration
.from_targets
.as_ref()
.is_some_and(|from| target.tags.iter().any(|tag| from.tags.contains(tag)))
{
return Err(plans::invalid_selection(
"This run does not apply to the selected target.",
));
}
Some(target)
};
plans::check_argument_limits(&request.user_arguments)?;
let mut params = plans::provider_hints(&request.base)?;
params.insert("run".to_string(), json!(declaration.id));
params.insert("userArguments".to_string(), json!(request.user_arguments));
if let Some(options) = &request.launch_options {
params.insert("launchOptions".to_string(), json!(options));
}
for (name, selected) in [("project", project), ("target", target)] {
for (name, selected) in [("project", Some(project)), ("target", target)] {
let Some(selected) = selected else { continue };
params.insert(
name.to_string(),
json!({"name":selected.name,"path":selected.path,
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ pub enum BuildCommand {
TestDiscoveryPlan,
/// Validates provider-owned test selectors (`build.decodeTestDiscovery`).
DecodeTestDiscovery,
/// Asks a provider for the entrypoints of a file (`build.runEntrypointsPlan`).
RunEntrypointsPlan,
/// Validates the entrypoints a provider found (`build.decodeRunEntrypoints`).
DecodeRunEntrypoints,
/// Expands the command that prints a project's dependencies (`build.dependencyPlan`).
DependencyPlan,
/// Normalizes a build model and derives its run entries (`build.decodeModel`).
Expand Down Expand Up @@ -1177,6 +1181,8 @@ impl CoreCommand {
"build.decodeRunPreparation" => Some(Self::Build(BuildCommand::DecodeRunPreparation)),
"build.testDiscoveryPlan" => Some(Self::Build(BuildCommand::TestDiscoveryPlan)),
"build.decodeTestDiscovery" => Some(Self::Build(BuildCommand::DecodeTestDiscovery)),
"build.runEntrypointsPlan" => Some(Self::Build(BuildCommand::RunEntrypointsPlan)),
"build.decodeRunEntrypoints" => Some(Self::Build(BuildCommand::DecodeRunEntrypoints)),
"build.dependencyPlan" => Some(Self::Build(BuildCommand::DependencyPlan)),
"build.decodeModel" => Some(Self::Build(BuildCommand::DecodeModel)),
"build.decodeTestResults" => Some(Self::Build(BuildCommand::DecodeTestResults)),
Expand Down
Loading
Loading