Skip to content

Commit

Permalink
mv GopEnv => env.Gop
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed May 18, 2022
1 parent 8a4048c commit 5df52e3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
23 changes: 23 additions & 0 deletions env/gop.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion gopmod/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

// -----------------------------------------------------------------------------

Expand Down
11 changes: 6 additions & 5 deletions modfetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions modload/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ 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 (
ErrNoModDecl = errors.New("no module declaration in gop.mod (or go.mod)")
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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5df52e3

Please sign in to comment.