Skip to content

Commit

Permalink
fix: globbing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fcanovai committed Mar 29, 2024
1 parent 16318b0 commit b353d51
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions dagger/protoc-gen-go-grpc/dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
"context"
"fmt"
"path"
)

type ProtocGenGoGRPC struct {
Expand Down Expand Up @@ -54,36 +55,9 @@ func (m *ProtocGenGoGRPC) Container() *Container {
return m.Ctr
}

func getProtoFiles(
// The source directory.
source *Directory,
// The path to the proto files, relative to the source directory.
protoPath string,
) ([]string, error) {
protoDir := source.Directory(protoPath)
protos, err := protoDir.Glob(context.Background(), "*")
if err != nil {
return nil, err
}
return protos, nil
}

// List lists the proto files that would be considered during a Run
func (m *ProtocGenGoGRPC) List(
// The source directory.
source *Directory,
// The path to the proto files, relative to the source directory.
protoPath string,
) string {
protos, err := getProtoFiles(source, protoPath)
if err != nil {
return err.Error()
}
return fmt.Sprintf("The following proto files would be examined:\n%v", protos)
}

// Run runs protoc on proto files, returning the generated go files as a directory.
func (m *ProtocGenGoGRPC) Run(
ctx context.Context,
// The source directory.
source *Directory,
// The path to the proto files, relative to the source directory.
Expand All @@ -98,11 +72,15 @@ func (m *ProtocGenGoGRPC) Run(
args = append(args, fmt.Sprintf("--go_opt=%v", goOpt))
args = append(args, "--go-grpc_out=/out/")
args = append(args, fmt.Sprintf("--go-grpc_opt=%v", goGRPCOpt))
protos, err := getProtoFiles(source, protoPath)
protos, err := source.Directory(protoPath).Entries(ctx)
if err != nil {
return nil, err
}
for i := range protos {
protos[i] = path.Join(protoPath, protos[i])
}
args = append(args, protos...)

buildDir := m.Ctr.
WithMountedDirectory("/src", source).
WithExec([]string{"mkdir", "-p", "/out"}).
Expand Down

0 comments on commit b353d51

Please sign in to comment.