Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails when built with -trimpath #910

Open
tv42 opened this issue Oct 25, 2019 · 7 comments
Open

Fails when built with -trimpath #910

tv42 opened this issue Oct 25, 2019 · 7 comments
Labels
accepted bug Something isn't working

Comments

@tv42
Copy link

tv42 commented Oct 25, 2019

What happened?

$ GOFLAGS='-trimpath' go build github.com/99designs/gqlgen && ./gqlgen
modelgen: locating templates: lstat github.com/99designs/gqlgen@v0.10.1/plugin/modelgen: no such file or directory
[EXIT:3] $ 

What did you expect?

Success, like without -trimpath:

$ GOFLAGS=' ' go build github.com/99designs/gqlgen  && ./gqlgen
$ 

Minimal graphql.schema and models to reproduce

Just about anything, really.

versions

  • gqlgen version?
  • go version?
  • dep or go modules?
$ go list -m github.com/99designs/gqlgen
github.com/99designs/gqlgen v0.10.1
$ go version
go version go1.13.3 linux/amd64

And obviously modules.

It seems gqlgen is using build-time paths to try to locate its template files, and trimpath confuses that. Perhaps the templates should be bundled into the executable.

@stale
Copy link

stale bot commented Dec 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 24, 2019
@tv42
Copy link
Author

tv42 commented Dec 24, 2019

Bugs don't disappear just because time passes!

@stale stale bot removed the stale label Dec 24, 2019
@vvakame vvakame added bug Something isn't working help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Dec 25, 2019
@vektah
Copy link
Collaborator

vektah commented Feb 5, 2020

So don't use trimpath? gqlgen doesnt get shipped to your servers, its a tool used in your ci/dev environment.

We might start inlining templates again, but its trading off a lot of developer experience to fix your build environment.

@tv42
Copy link
Author

tv42 commented Feb 5, 2020

Trimpath is a very nice default.

@stale
Copy link

stale bot commented Apr 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 5, 2020
@vektah vektah added accepted and removed stale labels Apr 6, 2020
@sateeshpnv
Copy link
Contributor

sateeshpnv commented Jul 3, 2020

bazel uses trimpath to achieve reproducible builds. We use gqlgen/api to generate code. And modelgen fails in locating templates. The following patch works for us.

diff -urN a/codegen/templates/templates.go b/codegen/templates/templates.go
--- a/codegen/templates/templates.go 2020-05-26 15:48:27.000000000 -0700
+++ b/codegen/templates/templates.go 2020-05-26 15:48:28.000000000 -0700
@@ -75,6 +75,12 @@
 		roots = append(roots, "template.gotpl")
 	} else {
 		// load all the templates in the directory
+		// In a bazel environment, that uses trimpath to achieve reproducible builds, template files are under ${runfiles}/__main__/${rootDir} and not {rootDir} during runtime
+		// Hence prefix RUN_PATH if set.
+		// Ex: bazel-out/host/bin/src/code/generate.runfiles/__main__/external/com_github_99designs_gqlgen/codegen
+		if runFilesPath := os.Getenv("RUN_PATH"); runFilesPath != "" {
+			rootDir = filepath.Join(runFilesPath, rootDir)
+		}
 		err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
 			if err != nil {
 				return err

Update:

Instead of patching gqlgen code, changing directory to the runtime path helped. No patch required in gqlgen.

@sagikazarmark
Copy link

but its trading off a lot of developer experience to fix your build environment.

How about using the embed feature introduced in Go 1.16?

sagikazarmark added a commit to sagikazarmark/go-flake that referenced this issue Nov 20, 2021
See 99designs/gqlgen#910

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants