Navigation Menu

Skip to content

Commit

Permalink
Remove dummy mod dir (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
marpio committed May 3, 2019
1 parent 2affe53 commit 8e5b698
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
5 changes: 2 additions & 3 deletions azure-pipelines.yml
Expand Up @@ -7,22 +7,21 @@ 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

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"
exit ($LastExitCode -band 24)
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'
10 changes: 3 additions & 7 deletions pkg/download/upstream_lister.go
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions pkg/module/go_get_fetcher.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8e5b698

Please sign in to comment.