compiler: rename import path if it lies in TINYGOPATH

This allows importing (for example) both
"github.com/tinygo-org/tinygo/src/machine" and "machine" without issues.
The former is renamed to just "machine".
This commit is contained in:
Ayke van Laethem
2019-06-06 12:08:41 +02:00
committed by Ron Evans
parent ec87811420
commit 66aca428ba
2 changed files with 27 additions and 16 deletions
+12 -11
View File
@@ -16,16 +16,16 @@ import (
// Program holds all packages and some metadata about the program as a whole.
type Program struct {
Build *build.Context
OverlayBuild *build.Context
ShouldOverlay func(path string) bool
Packages map[string]*Package
sorted []*Package
fset *token.FileSet
TypeChecker types.Config
Dir string // current working directory (for error reporting)
TINYGOROOT string // root of the TinyGo installation or root of the source code
CFlags []string
Build *build.Context
OverlayBuild *build.Context
OverlayPath func(path string) string
Packages map[string]*Package
sorted []*Package
fset *token.FileSet
TypeChecker types.Config
Dir string // current working directory (for error reporting)
TINYGOROOT string // root of the TinyGo installation or root of the source code
CFlags []string
}
// Package holds a loaded package, its imports, and its parsed files.
@@ -48,8 +48,9 @@ func (p *Program) Import(path, srcDir string) (*Package, error) {
// Load this package.
ctx := p.Build
if p.ShouldOverlay(path) {
if newPath := p.OverlayPath(path); newPath != "" {
ctx = p.OverlayBuild
path = newPath
}
buildPkg, err := ctx.Import(path, srcDir, build.ImportComment)
if err != nil {