Skip to content

Commit

Permalink
Support vendoring
Browse files Browse the repository at this point in the history
Fixes #127
  • Loading branch information
dvyukov committed May 10, 2016
1 parent 46cbf8f commit 6174d61
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions go-fuzz-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,30 @@ type Importer struct {
pkgs map[string]*types.Package
}

func (i *Importer) Import(path string) (*types.Package, error) {
func (imp *Importer) Import(path string) (*types.Package, error) {
panic("must not be called")
}

func (i *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
if i.pkgs[path] == nil {
failf("can't find imported package %v", path)
func (imp *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
if pkg := imp.pkgs[path]; pkg != nil {
return pkg, nil
}
return i.pkgs[path], nil

// Vendor hackery.
prefix := filepath.Join(workdir, "src") + string(os.PathSeparator)
if strings.HasPrefix(srcDir, prefix) {
srcDir = srcDir[len(prefix):]
}
parts := strings.Split(srcDir, string(os.PathSeparator))
for i := 0; i <= len(parts); i++ {
vendorPath := strings.Join(parts[:len(parts)-i], string(os.PathSeparator))
vendorPath = filepath.Join(vendorPath, "vendor", path)
if pkg := imp.pkgs[vendorPath]; pkg != nil {
return pkg, nil
}
}
failf("can't find imported package %v", path)
return nil, nil
}

func instrumentPackages(workdir string, deps map[string]bool, lits map[Literal]struct{}, blocks *[]CoverBlock, sonar *[]CoverBlock) {
Expand Down

0 comments on commit 6174d61

Please sign in to comment.