-
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* go_repository: add importpath and vcs flags (#313) This change allows fetch_repo to fetch repositories without attempting to determine the repo root if the user supplies the information themselves. This allows users to be able to fetch repositories that the vcs package would otherwise not be able to recognize. This change also changes the behavior of the --remote flag to match the git_repository rule. * Respond to jayconrod@ comments in #319. * Add BUILD rule for fetch_repo_test.go * Stub out vcs.RepoRootForImportPath * Make remote and vcs flags not being set in fetch_repo a hard error. * Verify VCS is not nil before returning it in a RepoRoot. * Fix go_repository rule for #319. Since the vcs field in go_repository was always set to "git", fetch_repo was always failing if the user passed in only the importpath.
- Loading branch information
Showing
5 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
load("//go:def.bzl", "go_binary") | ||
load("//go:def.bzl", "go_binary", "go_library", "go_test") | ||
|
||
go_binary( | ||
name = "fetch_repo", | ||
library = ":go_default_library", | ||
) | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["main.go"], | ||
visibility = ["//visibility:private"], | ||
deps = ["@org_golang_x_tools//go/vcs:go_default_library"], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = ["fetch_repo_test.go"], | ||
library = ":go_default_library", | ||
deps = ["@org_golang_x_tools//go/vcs:go_default_library"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/vcs" | ||
) | ||
|
||
var ( | ||
root = &vcs.RepoRoot{ | ||
VCS: vcs.ByCmd("git"), | ||
Repo: "https://github.com/bazeltest/rules_go", | ||
Root: "github.com/bazeltest/rules_go", | ||
} | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// Replace vcs.RepoRootForImportPath to disable any network calls. | ||
repoRootForImportPath = func(_ string, _ bool) (*vcs.RepoRoot, error) { | ||
return root, nil | ||
} | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestGetRepoRoot(t *testing.T) { | ||
for _, tc := range []struct { | ||
label string | ||
remote string | ||
cmd string | ||
importpath string | ||
r *vcs.RepoRoot | ||
}{ | ||
{ | ||
label: "all", | ||
remote: "https://github.com/bazeltest/rules_go", | ||
cmd: "git", | ||
importpath: "github.com/bazeltest/rules_go", | ||
r: root, | ||
}, | ||
{ | ||
label: "different remote", | ||
remote: "https://example.com/rules_go", | ||
cmd: "git", | ||
importpath: "github.com/bazeltest/rules_go", | ||
r: &vcs.RepoRoot{ | ||
VCS: vcs.ByCmd("git"), | ||
Repo: "https://example.com/rules_go", | ||
Root: "github.com/bazeltest/rules_go", | ||
}, | ||
}, | ||
{ | ||
label: "only importpath", | ||
importpath: "github.com/bazeltest/rules_go", | ||
r: root, | ||
}, | ||
} { | ||
r, err := getRepoRoot(tc.remote, tc.cmd, tc.importpath) | ||
if err != nil { | ||
t.Errorf("[%s] %v", tc.label, err) | ||
} | ||
if !reflect.DeepEqual(r, tc.r) { | ||
t.Errorf("[%s] Expected %+v, got %+v", tc.label, tc.r, r) | ||
} | ||
} | ||
} | ||
|
||
func TestGetRepoRoot_error(t *testing.T) { | ||
for _, tc := range []struct { | ||
label string | ||
remote string | ||
cmd string | ||
importpath string | ||
}{ | ||
{ | ||
label: "importpath as remote", | ||
remote: "github.com/bazeltest/rules_go", | ||
}, | ||
{ | ||
label: "missing vcs", | ||
remote: "https://github.com/bazeltest/rules_go", | ||
importpath: "github.com/bazeltest/rules_go", | ||
}, | ||
{ | ||
label: "missing remote", | ||
cmd: "git", | ||
importpath: "github.com/bazeltest/rules_go", | ||
}, | ||
} { | ||
r, err := getRepoRoot(tc.remote, tc.cmd, tc.importpath) | ||
if err == nil { | ||
t.Errorf("[%s] expected error. Got %+v", tc.label, r) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters