Skip to content

Commit

Permalink
simplify proto types
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvigee committed Jan 6, 2025
1 parent a049d9a commit 810e14b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
5 changes: 5 additions & 0 deletions plugin/pluginexec/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ managed:
enabled: true
override:
- file_option: go_package_prefix
path: heph/plugin/exec
value: github.com/hephbuild/heph/plugin/pluginexec/gen
- file_option: go_package_prefix
path: heph/plugin
value: github.com/hephbuild/heph/plugin/gen

plugins:
- remote: buf.build/protocolbuffers/go
out: gen
Expand Down
21 changes: 4 additions & 17 deletions plugin/pluginexec/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,18 @@ func (p *Plugin) Parse(ctx context.Context, req *connect.Request[pluginv1.ParseR
for name, sdeps := range targetSpec.Deps.Merge(targetSpec.HashDeps, targetSpec.RuntimeDeps) {
var execDeps execv1.Target_Deps
for _, dep := range sdeps {
sref, err := tref.ParseWithOut(dep)
ref, err := tref.ParseWithOut(dep)
if err != nil {
return nil, err
}

ref := &execv1.Target_Deps_TargetRef{
Package: sref.GetPackage(),
Name: sref.GetName(),
Output: sref.Output, //nolint:protogetter
}

meta, err := anypb.New(ref)
if err != nil {
return nil, err
}

deps = append(deps, &pluginv1.TargetDef_Dep{
Ref: sref,
Ref: ref,
Meta: meta,
})

Expand All @@ -145,25 +139,18 @@ func (p *Plugin) Parse(ctx context.Context, req *connect.Request[pluginv1.ParseR

for _, tools := range targetSpec.Tools {
for _, tool := range tools {
sref, err := tref.ParseWithOut(tool)
ref, err := tref.ParseWithOut(tool)
if err != nil {
return nil, err
}

ref := &execv1.Target_Deps_TargetRef{
Package: sref.GetPackage(),
Name: sref.GetName(),
Args: sref.GetArgs(),
Output: sref.Output, //nolint:protogetter
}

meta, err := anypb.New(ref)
if err != nil {
return nil, err
}

deps = append(deps, &pluginv1.TargetDef_Dep{
Ref: sref,
Ref: ref,
Meta: meta,
})
target.Tools = append(target.Tools, ref)
Expand Down
12 changes: 4 additions & 8 deletions plugin/pluginexec/proto/heph/plugin/exec/v1/plugin.proto
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
syntax = "proto3";
package heph.plugin.exec.v1;

import "heph/plugin/v1/plugin.proto";

message Target {
message Output {
string group = 1;
repeated string paths = 2;
}

message Deps {
message TargetRef {
string package = 1;
string name = 2;
map<string, string> args = 4;
optional string output = 3;
}
repeated string files = 1;
repeated TargetRef targets = 2;
repeated heph.plugin.v1.TargetRefWithOutput targets = 2;
}

repeated string run = 1;
map<string, Deps> deps = 2;
map<string, Deps> hash_deps = 3;
map<string, Deps> runtime_deps = 4;
repeated Deps.TargetRef tools = 10;
repeated heph.plugin.v1.TargetRefWithOutput tools = 10;
repeated Output outputs = 5;
map<string, string> env = 6;
map<string, string> runtime_env = 7;
Expand Down
4 changes: 2 additions & 2 deletions plugin/pluginexec/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (p *Plugin) inputEnv(
inputs []*pluginv1.ArtifactWithOrigin,
deps map[string]*execv1.Target_Deps,
) ([]string, error) {
getDep := func(t *execv1.Target_Deps_TargetRef) (string, bool) {
getDep := func(t *pluginv1.TargetRefWithOutput) (string, bool) {
for name, dep := range deps {
for _, target := range dep.GetTargets() {
if target.GetName() == t.GetName() && target.GetPackage() == t.GetPackage() {
Expand All @@ -280,7 +280,7 @@ func (p *Plugin) inputEnv(
continue
}

ref := &execv1.Target_Deps_TargetRef{}
ref := &pluginv1.TargetRefWithOutput{}
err := input.GetMeta().UnmarshalTo(ref)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions plugin/pluginexec/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func SetupSandbox(ctx context.Context, t *execv1.Target, results []*pluginv1.Art
return listArtifacts, nil
}

func ArtifactsForDep(inputs []*pluginv1.ArtifactWithOrigin, ref *execv1.Target_Deps_TargetRef) iter.Seq[*pluginv1.ArtifactWithOrigin] {
func ArtifactsForDep(inputs []*pluginv1.ArtifactWithOrigin, ref *pluginv1.TargetRefWithOutput) iter.Seq[*pluginv1.ArtifactWithOrigin] {
return func(yield func(origin *pluginv1.ArtifactWithOrigin) bool) {
for _, input := range inputs {
if input.GetArtifact().GetType() != pluginv1.Artifact_TYPE_OUTPUT {
continue
}

aref := &execv1.Target_Deps_TargetRef{}
aref := &pluginv1.TargetRefWithOutput{}
err := input.GetMeta().UnmarshalTo(aref)
if err != nil {
continue
Expand Down

0 comments on commit 810e14b

Please sign in to comment.