Skip to content

Commit

Permalink
[Feature] go.mod & go.work FilePath ReplaceDirective support
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Apr 24, 2024
1 parent 235bce2 commit 92a2a0d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
22 changes: 6 additions & 16 deletions cmd/fetch_repo/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ limitations under the License.
package main

import (
"bytes"
"fmt"
"os/exec"
"strings"
)

func moduleFromPath(from string, dest string) error {
Expand All @@ -28,20 +26,12 @@ func moduleFromPath(from string, dest string) error {
return err
}

cmd := exec.Command(findGoPath(), "mod", "download", "-json")
cmd := exec.Command(findGoPath(), "mod", "download", "-json", "-modcacherw")
cmd.Dir = dest
cmd.Args = append(cmd.Args, "-modcacherw")

buf := &bytes.Buffer{}
bufErr := &bytes.Buffer{}
cmd.Stdout = buf
cmd.Stderr = bufErr
fmt.Printf("Running: %s %s\n", cmd.Path, strings.Join(cmd.Args, " "))
// TODO: handle errors
cmd.Run()

// if _, ok := dlErr.(*exec.ExitError); !ok {
// return fmt.Errorf("error running 'go mod download': %v", dlErr)
// }

output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error running '%v': %v in %s. Output: %s", cmd.Args, err, dest, string(output))
}
return nil
}
8 changes: 2 additions & 6 deletions internal/go_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,8 @@ def _go_repository_impl(ctx):
)

if result.return_code:
fail(command)

if result.stderr:
print("mod download: %s", result.stderr)

if result.return_code:
print("stdout: %s", result.stdout)
print("stderr: %s", result.stderr)
fail(command)

if fetch_repo_args:
Expand Down
2 changes: 1 addition & 1 deletion tests/bcr/go_work/go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21.5
go 1.21

use (
./pkg
Expand Down
2 changes: 1 addition & 1 deletion tests/bcr/go_work/test_dep/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work/test_dep

go 1.21.5
go 1.21

require github.com/stretchr/testify v1.8.4

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/hello/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module example.com/hello

go 1.21.5
go 1.21

require rsc.io/quote v1.5.2

Expand Down

0 comments on commit 92a2a0d

Please sign in to comment.