From 5df52e3d1cf198f2e46bb96328ecf7054ea15903 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 18 May 2022 19:45:02 +0800 Subject: [PATCH] mv GopEnv => env.Gop --- env/gop.go | 23 +++++++++++++++++++++++ gopmod/module.go | 3 ++- modfetch/fetch.go | 11 ++++++----- modload/module.go | 14 ++++++-------- 4 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 env/gop.go diff --git a/env/gop.go b/env/gop.go new file mode 100644 index 0000000..e37ab8a --- /dev/null +++ b/env/gop.go @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package env + +type Gop struct { + Version string + BuildDate string + Root string // GOPROOT +} diff --git a/gopmod/module.go b/gopmod/module.go index 0d31833..a7a43bd 100644 --- a/gopmod/module.go +++ b/gopmod/module.go @@ -24,13 +24,14 @@ import ( "strings" "syscall" + "github.com/goplus/mod/env" "github.com/goplus/mod/modcache" "github.com/goplus/mod/modfetch" "github.com/goplus/mod/modload" "golang.org/x/mod/module" ) -type GopEnv = modload.GopEnv +type GopEnv = env.Gop // ----------------------------------------------------------------------------- diff --git a/modfetch/fetch.go b/modfetch/fetch.go index d7e6e17..2c8e253 100644 --- a/modfetch/fetch.go +++ b/modfetch/fetch.go @@ -26,6 +26,7 @@ import ( "strings" "syscall" + "github.com/goplus/mod/env" "github.com/goplus/mod/modcache" "github.com/goplus/mod/modload" "golang.org/x/mod/module" @@ -38,7 +39,7 @@ type ( ExecCmdError = modload.ExecCmdError ) -func Get(env *modload.GopEnv, modPath string, noCache ...bool) (mod module.Version, isClass bool, err error) { +func Get(env *env.Gop, modPath string, noCache ...bool) (mod module.Version, isClass bool, err error) { if noCache == nil || !noCache[0] { mod, isClass, err = getFromCache(modPath, env) if err != syscall.ENOENT { @@ -60,7 +61,7 @@ func Get(env *modload.GopEnv, modPath string, noCache ...bool) (mod module.Versi return getFromCache(modPath, env) } -func getResult(data string, env *modload.GopEnv) (mod module.Version, isClass bool, err error) { +func getResult(data string, env *env.Gop) (mod module.Version, isClass bool, err error) { // go: downloading github.com/xushiwei/foogop v0.1.0 const downloading = "go: downloading " if strings.HasPrefix(data, downloading) { @@ -77,7 +78,7 @@ func getResult(data string, env *modload.GopEnv) (mod module.Version, isClass bo return } -func tryConvGoMod(data string, next *string, env *modload.GopEnv) (mod module.Version, isClass bool, err error) { +func tryConvGoMod(data string, next *string, env *env.Gop) (mod module.Version, isClass bool, err error) { err = syscall.ENOENT if pos := strings.IndexByte(data, '\n'); pos > 0 { line := data[:pos] @@ -92,7 +93,7 @@ func tryConvGoMod(data string, next *string, env *modload.GopEnv) (mod module.Ve return } -func convGoMod(dir string, env *modload.GopEnv) (isClass bool, err error) { +func convGoMod(dir string, env *env.Gop) (isClass bool, err error) { var mode modload.Mode if env == nil { mode = modload.GoModOnly @@ -108,7 +109,7 @@ func convGoMod(dir string, env *modload.GopEnv) (isClass bool, err error) { // ----------------------------------------------------------------------------- -func getFromCache(modPath string, env *modload.GopEnv) (modVer module.Version, isClass bool, err error) { +func getFromCache(modPath string, env *env.Gop) (modVer module.Version, isClass bool, err error) { modRoot, modVer, err := lookupFromCache(modPath) if err != nil { return diff --git a/modload/module.go b/modload/module.go index 76a47de..aab4f81 100644 --- a/modload/module.go +++ b/modload/module.go @@ -25,11 +25,12 @@ import ( "path/filepath" "strings" - gomodfile "golang.org/x/mod/modfile" - "golang.org/x/mod/module" - "github.com/goplus/mod" + "github.com/goplus/mod/env" "github.com/goplus/mod/modfile" + "golang.org/x/mod/module" + + gomodfile "golang.org/x/mod/modfile" ) var ( @@ -37,6 +38,8 @@ var ( ErrNoModRoot = errors.New("gop.mod or go.mod file not found in current directory or any parent directory") ) +type GopEnv = env.Gop + type Module struct { *modfile.File } @@ -256,11 +259,6 @@ func (p Module) saveGoMod(gomod string, env *GopEnv) error { return err } -type GopEnv struct { - Version string - Root string // GOPROOT -} - func (p Module) convToGoMod(env *GopEnv) *gomodfile.File { copy := p.File.File copy.Syntax = cloneGoFileSyntax(copy.Syntax)