Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled abbreviation syntax for subrepos, ticket 386 #389

Merged
merged 4 commits into from Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/subrepos.html
Expand Up @@ -51,3 +51,17 @@ <h2>Using subrepos</h2>
<p>Subrepos also underpin <a href="cross_compiling.html">cross-compiling</a> and share the same
syntax; you can use that to reference architectures as well. There is currently some ambiguity
here and so it is best not to define subrepo names that match cross-compile architectures.</p>

<p>If the subrepo and the package names are the same, for example, <code>@unittest_cpp//:unittest_cpp</code>,
the build label reference to the target can be abbreviated, like so:</p>

<pre><code>subinclude("@pleasings//go:go_bindata")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the subinclude bit, it's not really germane to the example


cc_test(
name = "my_test",
...
deps = [
"@unittest_cpp",
],
)
</code></pre>
3 changes: 2 additions & 1 deletion src/core/build_label.go
Expand Up @@ -140,8 +140,9 @@ func parseBuildLabelParts(target, currentPath string, subrepo *Subrepo) (string,
// @subrepo//pkg:target or @subrepo:target syntax
idx := strings.Index(target, "//")
if idx == -1 {
// if subrepo and target are the same name, then @subrepo syntax will also suffice
if idx = strings.IndexRune(target, ':'); idx == -1 {
return "", "", ""
return "", target[1:], target[1:]
}
}
pkg, name, _ := parseBuildLabelParts(target[idx:], currentPath, subrepo)
Expand Down
10 changes: 10 additions & 0 deletions src/core/build_label_test.go
Expand Up @@ -94,6 +94,16 @@ func TestSubrepoLabel(t *testing.T) {
assert.EqualValues(t, BuildLabel{PackageName: "", Name: ""}, label.SubrepoLabel())
}

func TestParseBuildLabelParts(t *testing.T) {
target1 := "@unittest_cpp//:unittest_cpp"
targetNewSyntax := "@unittest_cpp"
pkg, name, subrepo := parseBuildLabelParts(target1, "/", nil)
pkg2, name2, subrepo2 := parseBuildLabelParts(targetNewSyntax, "/", nil)
assert.Equal(t, pkg, pkg2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to assert the values directly; technically you could pass this test with an implementation that always returned "" for the subrepo for example.

assert.Equal(t, name, name2)
assert.Equal(t, subrepo, subrepo2)
}

func TestMain(m *testing.M) {
// Used to support TestComplete, the function it's testing re-execs
// itself thinking that it's actually plz.
Expand Down