make-files / makefiles

A library of opinionated Makefiles for popular programming languages.
https://makefiles.dev
MIT License
4 stars 5 forks source link

gRPC "Tried to write the same file twice." error. #83

Closed jmalloc closed 2 years ago

jmalloc commented 2 years ago
/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/run-protoc \
        $(cat artifacts/protobuf/args/common artifacts/protobuf/args/go artifacts/protobuf/args/go-grpc) \
        /Users/nate/Developer/nomad-sdk-ios-api/./*.proto
api_grpc.pb.go: Tried to write the same file twice.
make: *** [api_grpc.pb.go] Error 1

/cc @danilvpetrov, @natesmith-bsecure

jmalloc commented 2 years ago

https://github.com/make-files/makefiles/blob/v1/pkg/protobuf/v2/Makefile#L75

This line might be the culprit? It's including the options for both go and go-grpc. Though I actually can't reproduce this on my machine yet.

danilvpetrov commented 2 years ago

Line 75 in this file is a comment line, is this the line you're referring to?

jmalloc commented 2 years ago

Sorry, I should have used a permalink. Try https://github.com/make-files/makefiles/blob/f872c5bd730fed3efba2428e6cfeb3a415caf708/pkg/protobuf/v2/Makefile#L96

danilvpetrov commented 2 years ago

This stackoverflow suggests that the input file is included at least twice in the command. I assume that input file would be api.proto in the original case. However, I cannot understand how would api.proto be repeated at least twice. Honestly I don't think (and this stackoverflow issue suggests the same) that this is due to duplication (if any) of the import paths.

jmalloc commented 2 years ago

No worries. Thanks for looking. I might have to get Nate to see if he can reproduce on his machine with a new repo.

jmalloc commented 2 years ago

That said, should both those arg files be included there?

danilvpetrov commented 2 years ago

For this particular target, yes. As this target compiles *_grpc.pb.go files, it needs to include options both from artifacts/protobuf/args/go and artifacts/protobuf/args/go-grpc.

If we look at the target that generates artifacts/protobuf/args/go-grpc we can see that it adds only three options there and all three are grpc-specific. All import paths and main golang options are placed in artifacts/protobuf/args/go

ghost commented 2 years ago
❯ make --debug                                        
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
Reading makefiles...
Updating goal targets....
 File `test' does not exist.
Target `test' is double-colon and has no prerequisites.
Must remake target `test'.
Successfully remade target file `test'.
 File `test' does not exist.
   Prerequisite `artifacts/protobuf/bin/run-protoc' is newer than target `api.pb.go'.
  Must remake target `api.pb.go'.
/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/run-protoc \
        $(cat artifacts/protobuf/args/common artifacts/protobuf/args/go) \
        /Users/nate/Developer/nomad-sdk-ios-api/./*.proto
+ PATH=/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin:/Users/nate/Developer/nomad-sdk-ios-api/.makefiles/lib/core/bin:/opt/homebrew/opt/kubernetes-cli@1.22/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/nate/.fig/bin:/Users/nate/.local/bin
+ /Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/protoc --proto_path=/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/../include --go_opt=module=github.com/betsecure/nomad-sdk-ios-api --go_out=:. --proto_path=github.com/betsecure/nomad-sdk-ios-api=/Users/nate/Developer/nomad-sdk-ios-api --proto_path=cloud.google.com/go=/Users/nate/go/pkg/mod/cloud.google.com/go@v0.34.0 --proto_path=github.com/census-instrumentation/opencensus-proto=/Users/nate/go/pkg/mod/github.com/census-instrumentation/opencensus-proto@v0.2.1 --proto_path=github.com/envoyproxy/protoc-gen-validate=/Users/nate/go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 --proto_path=github.com/golang/protobuf=/Users/nate/go/pkg/mod/github.com/golang/protobuf@v1.5.2 --proto_path=github.com/grpc-ecosystem/grpc-gateway=/Users/nate/go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.16.0 --proto_path=github.com/prometheus/client_model=/Users/nate/go/pkg/mod/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4 --proto_path=google.golang.org/appengine=/Users/nate/go/pkg/mod/google.golang.org/appengine@v1.4.0 --proto_path=google.golang.org/grpc=/Users/nate/go/pkg/mod/google.golang.org/grpc@v1.47.0 --proto_path=google.golang.org/protobuf=/Users/nate/go/pkg/mod/google.golang.org/protobuf@v1.28.0 /Users/nate/Developer/nomad-sdk-ios-api/./api.proto
  Successfully remade target file `api.pb.go'.
   Prerequisite `api.proto' is newer than target `api_grpc.pb.go'.
   Prerequisite `artifacts/protobuf/bin/go.mod' is newer than target `api_grpc.pb.go'.
   Prerequisite `artifacts/protobuf/bin/run-protoc' is newer than target `api_grpc.pb.go'.
   Prerequisite `artifacts/protobuf/args/go' is newer than target `api_grpc.pb.go'.
   Prerequisite `artifacts/protobuf/args/go-grpc' is newer than target `api_grpc.pb.go'.
  Must remake target `api_grpc.pb.go'.
/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/run-protoc \
        $(cat artifacts/protobuf/args/common artifacts/protobuf/args/go artifacts/protobuf/args/go-grpc) \
        /Users/nate/Developer/nomad-sdk-ios-api/./*.proto
+ PATH=/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin:/Users/nate/Developer/nomad-sdk-ios-api/.makefiles/lib/core/bin:/opt/homebrew/opt/kubernetes-cli@1.22/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/nate/.fig/bin:/Users/nate/.local/bin
+ /Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/protoc --proto_path=/Users/nate/Developer/nomad-sdk-ios-api/artifacts/protobuf/bin/../include --go_opt=module=github.com/betsecure/nomad-sdk-ios-api --go_out=:. --proto_path=github.com/betsecure/nomad-sdk-ios-api=/Users/nate/Developer/nomad-sdk-ios-api --proto_path=cloud.google.com/go=/Users/nate/go/pkg/mod/cloud.google.com/go@v0.34.0 --proto_path=github.com/census-instrumentation/opencensus-proto=/Users/nate/go/pkg/mod/github.com/census-instrumentation/opencensus-proto@v0.2.1 --proto_path=github.com/envoyproxy/protoc-gen-validate=/Users/nate/go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.1.0 --proto_path=github.com/golang/protobuf=/Users/nate/go/pkg/mod/github.com/golang/protobuf@v1.5.2 --proto_path=github.com/grpc-ecosystem/grpc-gateway=/Users/nate/go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.16.0 --proto_path=github.com/prometheus/client_model=/Users/nate/go/pkg/mod/github.com/prometheus/client_model@v0.0.0-20190812154241-14fe0d1b01d4 --proto_path=google.golang.org/appengine=/Users/nate/go/pkg/mod/google.golang.org/appengine@v1.4.0 --proto_path=google.golang.org/grpc=/Users/nate/go/pkg/mod/google.golang.org/grpc@v1.47.0 --proto_path=google.golang.org/protobuf=/Users/nate/go/pkg/mod/google.golang.org/protobuf@v1.28.0 --go-grpc_opt=module=github.com/betsecure/nomad-sdk-ios-api --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false --go-grpc_opt=module=github.com/betsecure/nomad-sdk-ios-api --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false /Users/nate/Developer/nomad-sdk-ios-api/./api.proto
api_grpc.pb.go: Tried to write the same file twice.
make: *** [api_grpc.pb.go] Error 1
jmalloc commented 2 years ago

Closing for now as we were unable to reproduce it after pulling new makefiles.

jmalloc commented 2 years ago

Likely solved in 92d9b29