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

easyjson requires GOPATH ended with "src" #353

Open
ksimka opened this issue Nov 1, 2021 · 1 comment
Open

easyjson requires GOPATH ended with "src" #353

ksimka opened this issue Nov 1, 2021 · 1 comment

Comments

@ksimka
Copy link
Contributor

ksimka commented Nov 1, 2021

Here

func getPkgPathFromGOPATH(fname string, isDir bool) (string, error) {
we have getPkgPathFromGOPATH function

func getPkgPathFromGOPATH(fname string, isDir bool) (string, error) {
	gopath := os.Getenv("GOPATH")
	if gopath == "" {
		gopath = build.Default.GOPATH
	}

	for _, p := range strings.Split(gopath, string(filepath.ListSeparator)) {
		prefix := filepath.Join(p, "src") + string(filepath.Separator)
		rel, err := filepath.Rel(prefix, fname)
		if err == nil && !strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
			if !isDir {
				return path.Dir(filePathToPackagePath(rel)), nil
			} else {
				return path.Clean(filePathToPackagePath(rel)), nil
			}
		}
	}

	return "", fmt.Errorf("file '%v' is not in GOPATH '%v'", fname, gopath)
}

As you can see, it searches for path that ends with "src". So I have one question and one notice:

  • is it kind of golang agreement that I'm not aware of that GOPATH must end with "src"?
  • if GOPATH doesn't have "src" easyjson returns an error that looks like "file '/my/go/path/some_file.go' is not in GOPATH '/my/go/path'" which is very confusing

I personally don't use GOPATH for a long time (since modules become a thing), but I faced with this issues when tried to run easyjson in some CI on autogenerated files (yes, I do easyjson autogeneration after another autogeneration).

@renich
Copy link

renich commented Apr 29, 2024

I am suffering because of this as well while trying to package nextcloud-spreed-signaling; which uses easyjson to generate some files.

It would be good if this got improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants