forked from mailru/easyjson
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip the vendor'd section of the package path
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
- Loading branch information
Showing
3 changed files
with
48 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func normalizePath(path string) string { | ||
return strings.Replace(path, "\\", "/", -1) | ||
} | ||
|
||
func getPkgPath(fname string, isDir bool) (string, error) { | ||
if !path.IsAbs(fname) { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return "", err | ||
} | ||
fname = path.Join(pwd, fname) | ||
} | ||
|
||
fname = normalizePath(fname) | ||
|
||
for _, p := range strings.Split(os.Getenv("GOPATH"), ";") { | ||
prefix := path.Join(normalizePath(p), "src") + "/" | ||
if rel := strings.TrimPrefix(fname, prefix); rel != fname { | ||
if !isDir { | ||
return path.Dir(rel), nil | ||
} else { | ||
return path.Clean(rel), nil | ||
} | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("file '%v' is not in GOPATH", fname) | ||
} | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
) | ||
|
||
func normalizePath(path string) string { | ||
return strings.Replace(path, "\\", "/", -1) | ||
} | ||
|
||
func getPkgPath(fname string, isDir bool) (string, error) { | ||
if !path.IsAbs(fname) { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return "", err | ||
} | ||
fname = path.Join(pwd, fname) | ||
} | ||
|
||
fname = normalizePath(fname) | ||
|
||
for _, p := range strings.Split(os.Getenv("GOPATH"), ";") { | ||
prefix := path.Join(normalizePath(p), "src") + "/" | ||
if rel := strings.TrimPrefix(fname, prefix); rel != fname { | ||
if !isDir { | ||
return fixPkgPathVendoring(path.Dir(rel)), nil | ||
} else { | ||
return fixPkgPathVendoring(path.Clean(rel)), nil | ||
} | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("file '%v' is not in GOPATH", fname) | ||
} |