Skip to content

Commit da75630

Browse files
committed
Split debianNameFromGopkg() into shortHostName()
so that we can use the short hostname elsewhere too.
1 parent 6242fc2 commit da75630

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

make.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,11 @@ func normalizeDebianProgramName(str string) string {
485485
return safe
486486
}
487487

488-
// This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
489-
func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) string {
488+
func shortHostName(gopkg string, allowUnknownHoster bool) (host string, err error) {
490489
parts := strings.Split(gopkg, "/")
490+
fqdn := parts[0]
491491

492-
if t == typeProgram || t == typeProgramLibrary {
493-
return normalizeDebianProgramName(parts[len(parts)-1])
494-
}
495-
496-
host := parts[0]
497-
switch host {
492+
switch fqdn {
498493
case "github.com":
499494
host = "github"
500495
case "code.google.com":
@@ -527,12 +522,30 @@ func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) s
527522
if allowUnknownHoster {
528523
suffix, _ := publicsuffix.PublicSuffix(host)
529524
host = host[:len(host)-len(suffix)-len(".")]
530-
log.Printf("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n", host, parts[0], os.Args[0])
525+
log.Printf("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n", host, fqdn, os.Args[0])
531526
} else {
532-
log.Fatalf("Cannot derive Debian package name: unknown hoster %q. See -help output for -allow_unknown_hoster\n", host)
527+
err = fmt.Errorf("unknown hoster %q", fqdn)
533528
}
534529
}
530+
return host, err
531+
}
532+
533+
// debianNameFromGopkg converts a Go package repo path to a Debian package name,
534+
// e.g. "golang.org/x/text" → "golang-golang-x-text".
535+
// This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
536+
func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) string {
537+
parts := strings.Split(gopkg, "/")
538+
539+
if t == typeProgram || t == typeProgramLibrary {
540+
return normalizeDebianProgramName(parts[len(parts)-1])
541+
}
542+
543+
host, err := shortHostName(gopkg, allowUnknownHoster)
544+
if err != nil {
545+
log.Fatalf("Cannot derive Debian package name: %v. See -help output for -allow_unknown_hoster\n", err)
546+
}
535547
parts[0] = host
548+
536549
return strings.Trim("golang-"+strings.ToLower(strings.Replace(strings.Join(parts, "-"), "_", "-", -1)), "-")
537550
}
538551

0 commit comments

Comments
 (0)