build/toolbase: delete unused code

Change-Id: I25ac3e6671bb6213aa9563ee9aa2b0afc2337805
Reviewed-on: https://review.monogon.dev/c/monogon/+/4030
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/build/toolbase/BUILD.bazel b/build/toolbase/BUILD.bazel
index 2dea810..e69de29 100644
--- a/build/toolbase/BUILD.bazel
+++ b/build/toolbase/BUILD.bazel
@@ -1,19 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
-
-go_library(
-    name = "toolbase",
-    srcs = [
-        "doc.go",
-        "label.go",
-        "workspace.go",
-    ],
-    importpath = "source.monogon.dev/build/toolbase",
-    visibility = ["//visibility:public"],
-)
-
-go_test(
-    name = "toolbase_test",
-    srcs = ["label_test.go"],
-    embed = [":toolbase"],
-    deps = ["@com_github_google_go_cmp//cmp"],
-)
diff --git a/build/toolbase/doc.go b/build/toolbase/doc.go
deleted file mode 100644
index 065d96f..0000000
--- a/build/toolbase/doc.go
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-// toolbase implements common functionality for tools operating on a Monogon
-// workspace, notably CI and developer tools.
-package toolbase
diff --git a/build/toolbase/label.go b/build/toolbase/label.go
deleted file mode 100644
index a16860d..0000000
--- a/build/toolbase/label.go
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-package toolbase
-
-import (
-	"fmt"
-	"regexp"
-	"strings"
-)
-
-// BazelLabel is a label, as defined by Bazel's documentation:
-//
-// https://docs.bazel.build/versions/main/skylark/lib/Label.html
-type BazelLabel struct {
-	WorkspaceName string
-	PackagePath   []string
-	Name          string
-}
-
-func (b BazelLabel) Package() string {
-	return strings.Join(b.PackagePath, "/")
-}
-
-func (b BazelLabel) String() string {
-	return fmt.Sprintf("@%s//%s:%s", b.WorkspaceName, b.Package(), b.Name)
-}
-
-var (
-	// reLabel splits a Bazel label into a workspace name (if set) and a
-	// workspace root relative package/name.
-	reLabel = regexp.MustCompile(`^(@[^:/]+)?//(.+)$`)
-	// rePathPart matches valid label path parts.
-	rePathPart = regexp.MustCompile(`^[^:/]+$`)
-)
-
-// ParseBazelLabel converts parses a string representation of a Bazel Label. If
-// the given representation is invalid or for some other reason unparseable,
-// nil is returned.
-func ParseBazelLabel(s string) *BazelLabel {
-	res := BazelLabel{
-		WorkspaceName: "@",
-	}
-
-	// Split label into workspace name (if set) and a workspace root relative
-	// package/name.
-	m := reLabel.FindStringSubmatch(s)
-	if m == nil {
-		return nil
-	}
-	packageRel := m[2]
-	if m[1] != "" {
-		res.WorkspaceName = m[1][1:]
-	}
-
-	// Split path by ':', which is the target name delimiter. If it appears
-	// exactly once, interpret everything to its right as the target name.
-	targetSplit := strings.Split(packageRel, ":")
-	switch len(targetSplit) {
-	case 1:
-	case 2:
-		packageRel = targetSplit[0]
-		res.Name = targetSplit[1]
-		if !rePathPart.MatchString(res.Name) {
-			return nil
-		}
-	default:
-		return nil
-	}
-
-	// Split the package path by /, and if the name was not explicitly given,
-	// use the last element of the package path.
-	if packageRel == "" {
-		res.PackagePath = nil
-	} else {
-		res.PackagePath = strings.Split(packageRel, "/")
-	}
-	if res.Name == "" {
-		res.Name = res.PackagePath[len(res.PackagePath)-1]
-	}
-
-	// Ensure all parts of the package path are valid.
-	for _, p := range res.PackagePath {
-		if !rePathPart.MatchString(p) {
-			return nil
-		}
-	}
-
-	return &res
-}
diff --git a/build/toolbase/label_test.go b/build/toolbase/label_test.go
deleted file mode 100644
index 558edae..0000000
--- a/build/toolbase/label_test.go
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-package toolbase
-
-import (
-	"testing"
-
-	"github.com/google/go-cmp/cmp"
-)
-
-func TestBazelLabelParse(t *testing.T) {
-	for i, te := range []struct {
-		p string
-		t *BazelLabel
-	}{
-		{"//foo/bar", &BazelLabel{"@", []string{"foo", "bar"}, "bar"}},
-		{"//foo/bar:baz", &BazelLabel{"@", []string{"foo", "bar"}, "baz"}},
-		{"//:foo", &BazelLabel{"@", nil, "foo"}},
-
-		{"@test//foo/bar", &BazelLabel{"test", []string{"foo", "bar"}, "bar"}},
-		{"@test//foo/bar:baz", &BazelLabel{"test", []string{"foo", "bar"}, "baz"}},
-		{"@test//:foo", &BazelLabel{"test", nil, "foo"}},
-
-		{"", nil},
-		{"//", nil},
-		{"//foo:bar/foo", nil},
-		{"//foo//bar/foo", nil},
-		{"/foo/bar/foo", nil},
-		{"foo/bar/foo", nil},
-		{"@//foo/bar/foo", nil},
-		{"@foo/bar//foo/bar/foo", nil},
-		{"@foo:bar//foo/bar/foo", nil},
-		{"foo//foo/bar/foo", nil},
-	} {
-		want := te.t
-		got := ParseBazelLabel(te.p)
-		if diff := cmp.Diff(want, got); diff != "" {
-			t.Errorf("case %d (%q): %s", i, te.p, diff)
-		}
-	}
-}
-
-func TestBazelLabelString(t *testing.T) {
-	for i, te := range []struct {
-		in   string
-		want string
-	}{
-		{"//foo/bar", "@@//foo/bar:bar"},
-		{"//foo:bar", "@@//foo:bar"},
-		{"@com_github_example//:run", "@com_github_example//:run"},
-	} {
-		l := ParseBazelLabel(te.in)
-		if l == nil {
-			t.Errorf("case %d: wanted %q, got nil", i, te.want)
-			continue
-		}
-		if want, got := te.want, l.String(); want != got {
-			t.Errorf("case %d: wanted %q, got %q", i, want, got)
-		}
-	}
-}
diff --git a/build/toolbase/workspace.go b/build/toolbase/workspace.go
deleted file mode 100644
index 5213504..0000000
--- a/build/toolbase/workspace.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright The Monogon Project Authors.
-// SPDX-License-Identifier: Apache-2.0
-
-package toolbase
-
-import (
-	"fmt"
-	"os"
-	"path"
-)
-
-// isWorkspace returns whether a given string is a valid path pointing to a
-// Bazel workspace directory.
-func isWorkspace(dir string) bool {
-	w := path.Join(dir, "WORKSPACE")
-	if _, err := os.Stat(w); err == nil {
-		return true
-	}
-	return false
-}
-
-// WorkspaceDirectory returns the workspace directory from which a given
-// command line tool is running. This handles the following cases:
-//
-//  1. The command line tool was invoked via `bazel run`.
-//  2. The command line tool was started directly in a workspace directory (but
-//     not a subdirectory).
-//
-// If the workspace directory path cannot be inferred based on the above
-// assumptions, an error is returned.
-func WorkspaceDirectory() (string, error) {
-	if p := os.Getenv("BUILD_WORKSPACE_DIRECTORY"); p != "" && isWorkspace(p) {
-		return p, nil
-	}
-
-	if p, err := os.Getwd(); err == nil && isWorkspace(p) {
-		return p, nil
-	}
-
-	return "", fmt.Errorf("not invoked from `bazel run` and not running in workspace directory")
-}