Skip to content

add internal/reflectlite for support Go1.13 #959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/neelance/sourcemap"
"github.com/shurcooL/httpfs/vfsutil"
"golang.org/x/tools/go/buildutil"

"github.com/visualfc/fastmod"
)

type ImportCError struct {
Expand Down Expand Up @@ -125,10 +127,10 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags
wd = ""
}
bctx := NewBuildContext(installSuffix, buildTags)
return importWithSrcDir(*bctx, path, wd, mode, installSuffix)
return importWithSrcDir(*bctx, path, wd, mode, installSuffix, nil)
}

func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build.ImportMode, installSuffix string) (*PackageData, error) {
func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build.ImportMode, installSuffix string, mod *fastmod.Package) (*PackageData, error) {
// bctx is passed by value, so it can be modified here.
var isVirtual bool
switch path {
Expand All @@ -154,7 +156,20 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
mode |= build.IgnoreVendor
isVirtual = true
}
pkg, err := bctx.Import(path, srcDir, mode)
var pkg *build.Package
var err error
if mod != nil {
if _, dir, typ := mod.Lookup(path); typ != fastmod.PkgTypeNil {
srcDir = dir
pkg, err = bctx.ImportDir(srcDir, mode)
if err == nil {
pkg.ImportPath = path
}
}
}
if pkg == nil {
pkg, err = bctx.Import(path, srcDir, mode) //bctx.Import(path, srcDir, mode)
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -471,11 +486,17 @@ type PackageData struct {
type Session struct {
options *Options
bctx *build.Context
Mod *fastmod.Package
Archives map[string]*compiler.Archive
Types map[string]*types.Package
Watcher *fsnotify.Watcher
}

func (s *Session) LoadMod(dir string) (err error) {
s.Mod, err = fastmod.LoadPackage(dir, s.bctx)
return
}

func NewSession(options *Options) *Session {
if options.GOROOT == "" {
options.GOROOT = build.Default.GOROOT
Expand Down Expand Up @@ -579,7 +600,7 @@ func (s *Session) BuildImportPath(path string) (*compiler.Archive, error) {
}

func (s *Session) buildImportPathWithSrcDir(path string, srcDir string) (*PackageData, *compiler.Archive, error) {
pkg, err := importWithSrcDir(*s.bctx, path, srcDir, 0, s.InstallSuffix())
pkg, err := importWithSrcDir(*s.bctx, path, srcDir, 0, s.InstallSuffix(), s.Mod)
if s.Watcher != nil && pkg != nil { // add watch even on error
s.Watcher.Add(pkg.Dir)
}
Expand Down Expand Up @@ -715,7 +736,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
}

if s.options.Verbose {
fmt.Println(pkg.ImportPath)
fmt.Println(pkg.Dir)
}

s.Archives[pkg.ImportPath] = archive
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- checkout
- run: git clone https://github.com/creationix/nvm $HOME/.nvm && cd $HOME/.nvm && git checkout v0.33.9 && echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV && echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- run: nvm install 10.0.0 && nvm alias default 10.0.0
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.13beta1.linux-amd64.tar.gz | sudo tar -xz
- run: cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.13.6.linux-amd64.tar.gz | sudo tar -xz
- run: echo 'export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"' >> $BASH_ENV
- run: go get -t -d -v ./...
- run: go install -v
Expand Down
Loading