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 all 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
13 changes: 13 additions & 0 deletions docs/subrepos.html
Expand Up @@ -51,3 +51,16 @@ <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>
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
13 changes: 13 additions & 0 deletions src/core/build_label_test.go
Expand Up @@ -94,6 +94,19 @@ 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, "")
assert.Equal(t, pkg2, "")
assert.Equal(t, name, "unittest_cpp")
assert.Equal(t, name2, "unittest_cpp")
assert.Equal(t, subrepo, "unittest_cpp")
assert.Equal(t, subrepo2, "unittest_cpp")
}

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