Revert "Preserve canonical labels as such (#1863)"
This reverts commit 2b326f8102c53db93c1fb330136bc5ed428e6cf0.
diff --git a/label/label.go b/label/label.go
index faf431c..50a71d0 100644
--- a/label/label.go
+++ b/label/label.go
@@ -51,12 +51,6 @@
// Relative indicates whether the label refers to a target in the current
// package. Relative is true if and only if Repo and Pkg are both omitted.
Relative bool
-
- // Canonical indicates whether the repository name is canonical. If true,
- // then the label will be stringified with an extra "@" prefix if it is
- // absolute.
- // Note: Label does not apply any kind of repo mapping.
- Canonical bool
}
// New constructs a new label from components.
@@ -89,11 +83,10 @@
origStr := s
relative := true
- canonical := false
var repo string
+ // if target name begins @@ drop the first @
if strings.HasPrefix(s, "@@") {
s = s[len("@"):]
- canonical = true
}
if strings.HasPrefix(s, "@") {
relative = false
@@ -147,11 +140,10 @@
}
return Label{
- Repo: repo,
- Pkg: pkg,
- Name: name,
- Relative: relative,
- Canonical: canonical,
+ Repo: repo,
+ Pkg: pkg,
+ Name: name,
+ Relative: relative,
}, nil
}
@@ -168,9 +160,6 @@
// if l.Repo == "@", the label string will begin with "@//"
repo = l.Repo
}
- if l.Canonical && strings.HasPrefix(repo, "@") {
- repo = "@" + repo
- }
if path.Base(l.Pkg) == l.Name {
return fmt.Sprintf("%s//%s", repo, l.Pkg)
@@ -224,8 +213,8 @@
}
func (l Label) BzlExpr() bzl.Expr {
- return &bzl.StringExpr{
- Value: l.String(),
+ return &bzl.StringExpr {
+ Value: l.String(),
}
}
diff --git a/label/label_test.go b/label/label_test.go
index 083add8..65c5a37 100644
--- a/label/label_test.go
+++ b/label/label_test.go
@@ -87,10 +87,10 @@
{str: "@a//some/pkg/[someId]:[someId]", want: Label{Repo: "a", Pkg: "some/pkg/[someId]", Name: "[someId]"}},
{str: "@rules_python~0.0.0~pip~name_dep//:_pkg", want: Label{Repo: "rules_python~0.0.0~pip~name_dep", Name: "_pkg"}},
{str: "@rules_python~0.0.0~pip~name//:dep_pkg", want: Label{Repo: "rules_python~0.0.0~pip~name", Name: "dep_pkg"}},
- {str: "@@rules_python~0.26.0~python~python_3_10_x86_64-unknown-linux-gnu//:python_runtimes", want: Label{Repo: "rules_python~0.26.0~python~python_3_10_x86_64-unknown-linux-gnu", Name: "python_runtimes", Canonical: true}},
+ {str: "@@rules_python~0.26.0~python~python_3_10_x86_64-unknown-linux-gnu//:python_runtimes", want: Label{Repo: "rules_python~0.26.0~python~python_3_10_x86_64-unknown-linux-gnu", Name: "python_runtimes"}},
{str: "@rules_python++pip+name_dep//:_pkg", want: Label{Repo: "rules_python++pip+name_dep", Name: "_pkg"}},
{str: "@rules_python++pip+name//:dep_pkg", want: Label{Repo: "rules_python++pip+name", Name: "dep_pkg"}},
- {str: "@@rules_python++python+python_3_10_x86_64-unknown-linux-gnu//:python_runtimes", want: Label{Repo: "rules_python++python+python_3_10_x86_64-unknown-linux-gnu", Name: "python_runtimes", Canonical: true}},
+ {str: "@@rules_python++python+python_3_10_x86_64-unknown-linux-gnu//:python_runtimes", want: Label{Repo: "rules_python++python+python_3_10_x86_64-unknown-linux-gnu", Name: "python_runtimes"}},
} {
got, err := Parse(tc.str)
if err != nil && !tc.wantErr {
@@ -117,37 +117,3 @@
}
}
}
-
-func TestParseStringRoundtrip(t *testing.T) {
- for _, tc := range []struct {
- in string
- out string
- }{
- {in: "target", out: ":target"},
- {in: ":target"},
- {in: "//:target"},
- {in: "//pkg:target"},
- {in: "@repo//:target"},
- {in: "@repo//pkg:target"},
- {in: "@repo", out: "@repo//:repo"},
- {in: "@//pkg:target"},
- {in: "@@canonical~name//:target"},
- {in: "@@//:target"},
- } {
- lbl, err := Parse(tc.in)
- if err != nil {
- t.Errorf("Parse(%q) failed: %v", tc, err)
- continue
- }
- got := lbl.String()
- var want string
- if len(tc.out) == 0 {
- want = tc.in
- } else {
- want = tc.out
- }
- if got != want {
- t.Errorf("Parse(%q).String() = %q; want %q", tc.in, got, want)
- }
- }
-}