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 is not so vendor friendly #29

Closed
garukun opened this issue May 26, 2016 · 1 comment
Closed

easyjson is not so vendor friendly #29

garukun opened this issue May 26, 2016 · 1 comment

Comments

@garukun
Copy link
Contributor

garukun commented May 26, 2016

Consider the following code:

import "github.com/repo1/package2"

//easyjson:json
type Gen1 struct {
  A package2.Type1 `json:"a"`
}

Given that github.com/repo1/package2 is already vendored, e.g. there is a vendor/github.com/repo1/package2 directory along with the go source code above. Running the easyjson binary will create an import line that looks somelike:

import package2 "github.com/foo/bar/vendor/github.com/repo1/package2"

Instead, it should just be:

import package2 "github.com/repo1/package2"

My go env just FYI:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/stevejiang/developments/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.6.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.6.2/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
@luma
Copy link

luma commented Feb 13, 2017

I see a partial fix was applied in #65 but you'll also need to do the same on the path returned by parser.getPkgPath. See the pgk below for the kind of output I get when running easyjson on vendor'd go code.

I'm happy to prepare a PR if the above sounds like the right fix.

package main

import (
  "fmt"
  "os"

  "github.com/mailru/easyjson/gen"

  pkg "github.com/foo/bar/vendor/github.com/foo/baz"
)

func main() {
  g := gen.NewGenerator("banks.pb_easyjson.go")
  g.SetPkg("protocol", "github.com/foo/bar/vendor/github.com/foo/baz")
  g.Add(pkg.EasyJSON_exporter_Thing(nil))
  if err := g.Run(os.Stdout); err != nil {
    fmt.Fprintln(os.Stderr, err)
    os.Exit(1)
  }
}

luma added a commit to autopilothq/easyjson that referenced this issue Feb 13, 2017
If the package that easyjson is being used on is vendor'd
then we need to strip off the vendor'd bit of the pkg path

Fixes: mailru#29
See: golang/go#12739
rubensayshi pushed a commit to btccom/easyjson that referenced this issue Dec 29, 2017
If the package that easyjson is being used on is vendor'd
then we need to strip off the vendor'd bit of the pkg path

Fixes: mailru#29
See: golang/go#12739
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

3 participants