code-generator: Remove now unused helper function

This commit is contained in:
Tim Hockin 2024-01-01 16:31:06 -08:00
parent 10c32b3e2f
commit 7f5982e708
No known key found for this signature in database

View File

@ -17,40 +17,9 @@ limitations under the License.
package util package util
import ( import (
gobuild "go/build"
"path/filepath"
"strings" "strings"
) )
// CurrentPackage returns the go package of the current directory, or "" if it cannot
// be derived from the GOPATH.
func CurrentPackage() string {
for _, root := range gobuild.Default.SrcDirs() {
if pkg, ok := hasSubdir(root, "."); ok {
return pkg
}
}
return ""
}
func hasSubdir(root, dir string) (rel string, ok bool) {
// ensure a tailing separator to properly compare on word-boundaries
const sep = string(filepath.Separator)
root = filepath.Clean(root)
if !strings.HasSuffix(root, sep) {
root += sep
}
// check whether root dir starts with root
dir = filepath.Clean(dir)
if !strings.HasPrefix(dir, root) {
return "", false
}
// cut off root
return filepath.ToSlash(dir[len(root):]), true
}
// Vendorless trims vendor prefix from a package path to make it canonical // Vendorless trims vendor prefix from a package path to make it canonical
func Vendorless(p string) string { func Vendorless(p string) string {
if pos := strings.LastIndex(p, "/vendor/"); pos != -1 { if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {