Skip to content

Commit 49a6733

Browse files
debugging ImportResolverFor
1 parent 8d83d5e commit 49a6733

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

build/build.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
10181018

10191019
importContext := &compiler.ImportContext{
10201020
Packages: s.Types,
1021-
Import: s.ImportResolverFor(pkg.Dir),
1021+
Import: s.ImportResolverFor(pkg, pkg.Dir),
10221022
}
10231023
archive, err := compiler.Compile(pkg.ImportPath, files, fileSet, importContext, s.options.Minify)
10241024
if err != nil {
@@ -1043,12 +1043,16 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
10431043

10441044
// ImportResolverFor returns a function which returns a compiled package archive
10451045
// given an import path.
1046-
func (s *Session) ImportResolverFor(srcDir string) func(string) (*compiler.Archive, error) {
1046+
func (s *Session) ImportResolverFor(pkg *PackageData, srcDir string) func(string) (*compiler.Archive, error) {
10471047
return func(path string) (*compiler.Archive, error) {
10481048
if archive, ok := s.UpToDateArchives[path]; ok {
10491049
return archive, nil
10501050
}
1051-
_, archive, err := s.buildImportPathWithSrcDir(path, srcDir)
1051+
if pkg.Dir != srcDir { // TODO(gn): REMOVE
1052+
panic("import resolver called with different srcDir: " + srcDir + " != " + pkg.Dir)
1053+
}
1054+
1055+
_, archive, err := s.buildImportPathWithSrcDir(path, pkg.Dir)
10521056
return archive, err
10531057
}
10541058
}
@@ -1087,7 +1091,13 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
10871091
sourceMapFilter.MappingCallback = s.SourceMappingCallback(m)
10881092
}
10891093

1090-
deps, err := compiler.ImportDependencies(archive, s.ImportResolverFor(""))
1094+
deps, err := compiler.ImportDependencies(archive, func(path string) (*compiler.Archive, error) {
1095+
if archive, ok := s.UpToDateArchives[path]; ok {
1096+
return archive, nil
1097+
}
1098+
_, archive, err := s.buildImportPathWithSrcDir(path, "")
1099+
return archive, err
1100+
})
10911101
if err != nil {
10921102
return err
10931103
}

tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func main() {
389389
}
390390
importContext := &compiler.ImportContext{
391391
Packages: s.Types,
392-
Import: s.ImportResolverFor(mainPkg.Dir),
392+
Import: s.ImportResolverFor(mainPkg, mainPkg.Dir),
393393
}
394394
mainPkgArchive, err := compiler.Compile(mainPkg.ImportPath, []*ast.File{mainFile}, fset, importContext, options.Minify)
395395
if err != nil {

0 commit comments

Comments
 (0)