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
6 changes: 6 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 32 additions & 9 deletions desktop/internal/pluginservice/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ type BuildPlugin struct {
type BuildSystemDeclaration struct {
ID string
DisplayName string
// Provider is true when this system answers model and task requests through
// a plugin process instead of a command line.
// Provider is true when this system declares a plugin process. Each request still names
// its own source: a provider system may read its model or dependencies with a command, so
// the model's source (BuildInstance.ModelSource) and Dependencies.Source decide how a
// request runs, not this.
Provider bool
Tasks []BuildTaskDeclaration
Runs []BuildRunDeclaration
Expand All @@ -46,6 +48,9 @@ type BuildSystemDeclaration struct {
// (plugin.build.invalidSelection), so the window offers the tree only where it is declared.
type BuildDependenciesDeclaration struct {
Scopes []string
// Source is "command" or "provider": where the tree comes from. A system with a provider
// process may still read its tree with a command, so this, not Provider, picks the path.
Source string
}

// BuildTestDeclaration is one build system's declared test entry.
Expand Down Expand Up @@ -78,9 +83,30 @@ type BuildTaskDeclaration struct {
Source string
}

// EntryName is the run configuration of the run on target: the run's declared name before the
// target's, or the target's name alone when the run declares none, as the contract's run.name
// says.
func (r BuildRunDeclaration) EntryName(target string) string {
if r.Name == "" {
return target
}
return r.Name + " " + target
}

// ActionName is what a menu entry that runs the run on target says: the run's declared name, or
// the target's name when the run declares none.
func (r BuildRunDeclaration) ActionName(target string) string {
if r.Name == "" {
return target
}
return r.Name
}

// BuildRunDeclaration is one provider-owned application, service, or task run.
type BuildRunDeclaration struct {
ID string
ID string
// Name is the entry name the run declares, empty when it declares none: the contract then
// names each entry after its target (EntryName, ActionName).
Name string
Execution string
Tags []string
Expand Down Expand Up @@ -160,6 +186,7 @@ type rawBuildManifest struct {
} `json:"test"`
Dependencies *struct {
Scopes []string `json:"scopes"`
Source string `json:"source"`
} `json:"dependencies"`
} `json:"buildSystems"`
}
Expand Down Expand Up @@ -200,13 +227,9 @@ func parseBuildSystems(manifest json.RawMessage) (map[string]BuildSystemDeclarat
if run.ID == "" || run.Source != "provider" || run.FromTargets == nil {
continue
}
name := run.Name
if name == "" {
name = run.ID
}
declaration := BuildRunDeclaration{
ID: run.ID,
Name: name,
Name: run.Name,
Execution: run.Execution,
Tags: append([]string(nil), run.FromTargets.Tags...),
}
Expand All @@ -224,7 +247,7 @@ func parseBuildSystems(manifest json.RawMessage) (map[string]BuildSystemDeclarat
}
}
if deps := raw.Dependencies; deps != nil && len(deps.Scopes) > 0 {
system.Dependencies = &BuildDependenciesDeclaration{Scopes: append([]string(nil), deps.Scopes...)}
system.Dependencies = &BuildDependenciesDeclaration{Scopes: append([]string(nil), deps.Scopes...), Source: deps.Source}
}
systems[raw.ID] = system
}
Expand Down
35 changes: 34 additions & 1 deletion desktop/internal/pluginservice/builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestParseBuildSystemsKeepsTaskPresentationAndDependencyScopes(t *testing.T)
if goModules.Provider {
t.Fatal("a command model reads as a provider")
}
if goModules.Dependencies == nil || len(goModules.Dependencies.Scopes) != 1 || goModules.Dependencies.Scopes[0] != "project" {
if goModules.Dependencies == nil || len(goModules.Dependencies.Scopes) != 1 || goModules.Dependencies.Scopes[0] != "project" || goModules.Dependencies.Source != "command" {
t.Fatalf("dependencies = %+v", goModules.Dependencies)
}
if len(goModules.Tasks) != 2 {
Expand All @@ -179,3 +179,36 @@ func TestParseBuildSystemsKeepsTaskPresentationAndDependencyScopes(t *testing.T)
t.Fatal("a system without dependencies offers them")
}
}

// A provider system may read its model and dependencies with commands and use its provider only
// for runs; the dependency declaration keeps its own source. A run
// without a name is called after its target, as the contract's run.name says, not after its ID.
func TestParseBuildSystemsKeepsDependencySourceAndUnnamedRuns(t *testing.T) {
systems, err := parseBuildSystems(json.RawMessage(`{"buildSystems": [{
"id": "engine",
"provider": {"launch": {"kind": "packaged", "path": "provider"}},
"model": {"source": "command"},
"dependencies": {"source": "command", "scopes": ["workspace", "project"], "arguments": [], "output": "outputFile"},
"run": [
{"id": "service", "source": "provider", "fromTargets": {"tags": ["service"]}, "execution": "service"},
{"id": "tool", "name": "Tool", "source": "provider", "fromTargets": {"tags": ["tool"]}, "execution": "application"}
]
}]}`))
if err != nil {
t.Fatal(err)
}
engine := systems["engine"]
if !engine.Provider || engine.Dependencies == nil || engine.Dependencies.Source != "command" {
t.Fatalf("system = %+v, dependencies = %+v", engine, engine.Dependencies)
}
if len(engine.Runs) != 2 {
t.Fatalf("runs = %+v", engine.Runs)
}
unnamed, named := engine.Runs[0], engine.Runs[1]
if unnamed.Name != "" || unnamed.EntryName("ServerMain") != "ServerMain" || unnamed.ActionName("ServerMain") != "ServerMain" {
t.Fatalf("the unnamed run is %+v, entry %q, action %q", unnamed, unnamed.EntryName("ServerMain"), unnamed.ActionName("ServerMain"))
}
if named.EntryName("Main") != "Tool Main" || named.ActionName("Main") != "Tool" {
t.Fatalf("the named run's entry %q, action %q", named.EntryName("Main"), named.ActionName("Main"))
}
}
91 changes: 60 additions & 31 deletions desktop/internal/workbench/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,7 @@ func (a *App) loadBuildModelWith(p *project, index int, refresh bool) {
a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) {
ctx, cancel := feed.bind(ctx)
defer cancel()
var model core.BuildModel
var err error
// Core names where the model comes from; a static model arrived with detection.
if captured.ModelSource == "command" {
model, err = a.commandModel(ctx, p, captured, kernel, feed, a.text.Build)
} else {
model, err = a.providerModel(ctx, p, captured, kernel, feed, refresh)
}
model, err := a.buildModel(ctx, p, captured, kernel, feed, a.text.Build, refresh)
if err != nil && feed.stopRequested() {
err = errBuildModelStopped
}
Expand All @@ -643,6 +636,17 @@ func (a *App) reloadBuildModel(p *project, index int) {
a.loadBuildModelWith(p, index, true)
}

// buildModel loads instance's model from the source Core named for it at detection: a command
// the host runs, or the plugin's provider process. A system that declares a provider process may
// still read its model with a command, so the model's source decides, not the provider. resolved,
// when given, is the build executable the caller already resolved.
func (a *App) buildModel(ctx context.Context, p *project, instance buildInstance, kernel Kernel, feed *buildSyncFeed, messages i18n.BuildMessages, refresh bool, resolved ...buildExecution) (core.BuildModel, error) {
if instance.ModelSource == "command" {
return a.commandModel(ctx, p, instance, kernel, feed, messages, resolved...)
}
return a.providerModel(ctx, p, instance, kernel, feed, refresh, resolved...)
}

// commandModel runs a command-sourced model plan and decodes its output. The
// output file, when the plan uses one, is host-allocated under the plugin's
// writable state and removed after decoding. No plugin process runs the command, so the
Expand Down Expand Up @@ -1123,6 +1127,22 @@ func (a *App) runCommandTask(ctx, prepare context.Context, p *project, op *build
return nil
}

// addBuildToolHint gives a provider's run or debug preparation the build executable the host
// resolves for instance, as dependency and test requests already carry it, so a provider that
// builds with the user's tool (a Maven wrapper, the configured executable) uses the same one.
// The hint is optional in the contract: when nothing resolves, the request goes without it, the
// provider reports what it misses, and the reason is logged here.
func (a *App) addBuildToolHint(ctx context.Context, p *project, instance buildInstance, request *core.BuildPlanRequest) {
execution, err := a.resolveBuildExecutable(ctx, p, instance, a.text.Build)
if err != nil {
a.backgroundFailedIn(ctx, "build_run_tool", err)
return
}
if execution.Executable != "" {
request.Tool = &core.BuildTool{Executable: execution.Executable, Environment: execution.Environment}
}
}

// resolveBuildExecutable asks Core for the ordered candidates, checks them in
// that order, and probes the declared minimum version. It never falls back to
// a guessed tool name.
Expand Down Expand Up @@ -1464,6 +1484,7 @@ func (a *App) debugProviderTarget(p *project, index int, projectID, targetID, ru
return
}
a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) {
a.addBuildToolHint(ctx, p, captured, &request)
plan, err := kernel.PlanBuildDebug(ctx, captured.Manifest, captured.BuildSystemID, request)
if err != nil {
return fail(err)
Expand Down Expand Up @@ -1581,15 +1602,17 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build
a.background(p, buildRequestTimeout, func(ctx context.Context) func(*App) {
prepare, release := op.bind(ctx)
defer release()
plan, err := kernel.PlanBuildRun(prepare, captured.Manifest, captured.BuildSystemID, core.BuildPlanRequest{
request := core.BuildPlanRequest{
Root: captured.Root,
Options: captured.Options,
WorkspaceRoot: p.root,
Run: runID,
Project: &core.BuildSelection{Name: project.Name, Path: project.Path, Properties: project.Properties},
Target: &core.BuildSelection{Name: target.Name, Path: target.Path, Tags: target.Tags, Properties: target.Properties},
LaunchOptions: options,
})
}
a.addBuildToolHint(prepare, p, captured, &request)
plan, err := kernel.PlanBuildRun(prepare, captured.Manifest, captured.BuildSystemID, request)
if err != nil {
return func(a *App) { a.finishBuildError(p, op, err) }
}
Expand All @@ -1605,7 +1628,9 @@ func (a *App) runBuildTargetWith(p *project, op *buildOperation, instance *build
return func(a *App) { a.finishBuildError(p, op, err) }
}
a.post(func(a *App) { a.attachRequest(p, op, client, operation, false) })
result, err := operation.Wait(prepare)
// The provider builds before it answers; what it prints meanwhile, such as a compile
// error, is the run's console output, which the user reads when the preparation fails.
result, _, err := a.awaitProviderOperation(prepare, p, op, operation)
if err != nil {
return func(a *App) { a.finishBuildError(p, op, err) }
}
Expand Down Expand Up @@ -1690,15 +1715,35 @@ func (a *App) runProviderOperation(ctx, prepare context.Context, p *project, op
return
}
a.post(func(a *App) { a.attachRequest(p, op, client, operation, true) })
sawProgress := false
result, sawProgress, err := a.awaitProviderOperation(ctx, p, op, operation)
if err != nil {
a.post(func(a *App) { a.finishBuildError(p, op, err) })
return
}
if !sawProgress {
var execution struct {
Output string `json:"output"`
}
if json.Unmarshal(result, &execution) == nil && execution.Output != "" {
a.streamBuildOutput(p, op, execution.Output)
}
}
a.post(func(a *App) { a.finishBuildTask(p, op, result) })
}

// awaitProviderOperation waits for the provider's answer to operation and meanwhile shows its
// progress as op's: output in op's console, messages as the window's status. sawOutput says
// whether any progress carried output. It runs off the window thread.
func (a *App) awaitProviderOperation(ctx context.Context, p *project, op *buildOperation, operation *buildprovider.Operation) (result json.RawMessage, sawOutput bool, err error) {
for {
select {
case progress, ok := <-operation.Progress():
if !ok {
goto done
result, err = operation.Wait(ctx)
return result, sawOutput, err
}
if progress.Output != "" {
sawProgress = true
sawOutput = true
a.streamBuildOutput(p, op, progress.Output)
}
if progress.Message != "" {
Expand All @@ -1709,25 +1754,9 @@ func (a *App) runProviderOperation(ctx, prepare context.Context, p *project, op
})
}
case <-ctx.Done():
a.post(func(a *App) { a.finishBuildError(p, op, ctx.Err()) })
return
return nil, sawOutput, ctx.Err()
}
}
done:
result, err := operation.Wait(ctx)
if err != nil {
a.post(func(a *App) { a.finishBuildError(p, op, err) })
return
}
if !sawProgress {
var execution struct {
Output string `json:"output"`
}
if json.Unmarshal(result, &execution) == nil && execution.Output != "" {
a.streamBuildOutput(p, op, execution.Output)
}
}
a.post(func(a *App) { a.finishBuildTask(p, op, result) })
}

// endBuildOperation clears op as the window's operation, records how it ended in its session and
Expand Down
Loading
Loading