Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
remove Importer and importerFn
Browse files Browse the repository at this point in the history
  • Loading branch information
davecheney committed Dec 13, 2016
1 parent a36a178 commit 5b5746e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
16 changes: 3 additions & 13 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ import (
// enables sh style -e output
const eMode = false

// Importer resolves package import paths to *importer.Packages.
type Importer interface {

// Import attempts to resolve the package import path, path,
// to an *importer.Package.
Import(path string) (*build.Package, error)
}

// Context represents an execution of one or more Targets inside a Project.
type Context struct {
Project

importer Importer
importer func(string) (*build.Package, error)

pkgs map[string]*Package // map of package paths to resolved packages

Expand Down Expand Up @@ -167,13 +159,11 @@ func NewContext(p Project, opts ...func(*Context) error) (*Context, error) {
bc.ReleaseTags = releaseTags
bc.BuildTags = ctx.buildtags

i, err := buildImporter(&bc, &ctx)
ctx.importer, err = buildImporter(&bc, &ctx)
if err != nil {
return nil, err
}

ctx.importer = importerFn(i)

// C and unsafe are fake packages synthesised by the compiler.
// Insert fake packages into the package cache.
for _, name := range []string{"C", "unsafe"} {
Expand Down Expand Up @@ -252,7 +242,7 @@ func (c *Context) loadPackage(stack []string, path string) (*Package, error) {
return pkg, nil
}

p, err := c.importer.Import(path)
p, err := c.importer(path)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestContextImportPackage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = ctx.importer.Import(tt.path)
_, err = ctx.importer(tt.path)
if !reflect.DeepEqual(err, tt.err) {
t.Errorf("importPackage(%q): got %v, want %v", tt.path, err, tt.err)
}
Expand Down
6 changes: 0 additions & 6 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ func nullImporter() func(string) (*build.Package, error) {
}
}

type importerFn func(string) (*build.Package, error)

func (fn importerFn) Import(path string) (*build.Package, error) {
return fn(path)
}

func srcImporter(parent, child func(string) (*build.Package, error)) func(string) (*build.Package, error) {
return func(path string) (*build.Package, error) {
pkg, err := child(path)
Expand Down

0 comments on commit 5b5746e

Please sign in to comment.