Remove dummy mod dir (#1121)

This commit is contained in:
marpio
2019-05-03 22:52:36 +02:00
committed by GitHub
parent 2affe53ec8
commit 8e5b6981d3
3 changed files with 5 additions and 33 deletions
+2 -3
View File
@@ -7,7 +7,7 @@ pool:
vmImage: 'vs2017-win2016'
variables:
GOBIN: '$(GOPATH)\bin' # Go binaries path
GOBIN: 'C:\Go\bin' # Go binaries path
GOPATH: '$(system.defaultWorkingDirectory)\gopath' # Go workspace path
GO111MODULE: 'on'
modulePath: '$(GOPATH)\src\github.com\$(build.repository.name)' # Path to the module's code
@@ -15,7 +15,6 @@ variables:
steps:
- powershell: |
choco upgrade golang
mkdir "$env:GOBIN" | out-null
mkdir "$env:GOPATH\pkg" | out-null
mkdir "$env:modulePath" | out-null
robocopy "$env:system_defaultWorkingDirectory\" "$env:modulePath\" /E /Z /ZB /R:5 /W:5 /TBD /NP /V /XD "$env:GOPATH"
@@ -23,6 +22,6 @@ steps:
displayName: 'set up the Go workspace'
- powershell: |
go test -mod=vendor -race ./...
& "C:\\Go\\bin\\go.exe" test -mod=vendor -race ./...
workingDirectory: '$(modulePath)'
displayName: 'run tests'
+3 -7
View File
@@ -39,22 +39,18 @@ func (l *vcsLister) List(ctx context.Context, mod string) (*storage.RevInfo, []s
ctx, span := observ.StartSpan(ctx, op.String())
defer span.End()
hackyPath, err := afero.TempDir(l.fs, "", "hackymod")
if err != nil {
return nil, nil, errors.E(op, err)
}
defer l.fs.RemoveAll(hackyPath)
err = module.Dummy(l.fs, hackyPath)
tmpDir, err := afero.TempDir(l.fs, "", "go-list")
if err != nil {
return nil, nil, errors.E(op, err)
}
defer l.fs.RemoveAll(tmpDir)
cmd := exec.Command(
l.goBinPath,
"list", "-m", "-versions", "-json",
config.FmtModVer(mod, "latest"),
)
cmd.Dir = hackyPath
cmd.Dir = tmpDir
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
cmd.Stdout = stdout
-23
View File
@@ -65,12 +65,6 @@ func (g *goGetFetcher) Fetch(ctx context.Context, mod, ver string) (*storage.Ver
return nil, errors.E(op, err)
}
// setup the module with barebones stuff
if err := Dummy(g.fs, modPath); err != nil {
ClearFiles(g.fs, goPathRoot)
return nil, errors.E(op, err)
}
m, err := downloadModule(g.goBinaryName, g.fs, goPathRoot, modPath, mod, ver)
if err != nil {
ClearFiles(g.fs, goPathRoot)
@@ -104,23 +98,6 @@ func (g *goGetFetcher) Fetch(ctx context.Context, mod, ver string) (*storage.Ver
return &storageVer, nil
}
// Dummy Hacky thing makes vgo not to complain
func Dummy(fs afero.Fs, repoRoot string) error {
const op errors.Op = "module.Dummy"
// vgo expects go.mod file present with module statement or .go file with import comment
gomodPath := filepath.Join(repoRoot, "go.mod")
gomodContent := []byte("module mod")
if err := afero.WriteFile(fs, gomodPath, gomodContent, 0666); err != nil {
return errors.E(op, err)
}
sourcePath := filepath.Join(repoRoot, "mod.go")
sourceContent := []byte("package mod")
if err := afero.WriteFile(fs, sourcePath, sourceContent, 0666); err != nil {
return errors.E(op, err)
}
return nil
}
// given a filesystem, gopath, repository root, module and version, runs 'go mod download -json'
// on module@version from the repoRoot with GOPATH=gopath, and returns a non-nil error if anything went wrong.
func downloadModule(goBinaryName string, fs afero.Fs, gopath, repoRoot, module, version string) (goModule, error) {