diff options
author | Ayke van Laethem <[email protected]> | 2019-06-06 12:08:41 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-06-06 16:01:25 +0200 |
commit | 66aca428babdeee367bfe0a64293117528ad5837 (patch) | |
tree | d4ea556ae694e8bc5db9ca6214fc085ea5ce7477 /loader | |
parent | ec878114208b62dd14c8f6bc5e15a1217d7b6293 (diff) | |
download | tinygo-66aca428babdeee367bfe0a64293117528ad5837.tar.gz tinygo-66aca428babdeee367bfe0a64293117528ad5837.zip |
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".
Diffstat (limited to 'loader')
-rw-r--r-- | loader/loader.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/loader/loader.go b/loader/loader.go index cf7cf2c75..7b20a925a 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -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 { |