@@ -485,16 +485,11 @@ func normalizeDebianProgramName(str string) string {
485
485
return safe
486
486
}
487
487
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 ) {
490
489
parts := strings .Split (gopkg , "/" )
490
+ fqdn := parts [0 ]
491
491
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 {
498
493
case "github.com" :
499
494
host = "github"
500
495
case "code.google.com" :
@@ -527,12 +522,30 @@ func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) s
527
522
if allowUnknownHoster {
528
523
suffix , _ := publicsuffix .PublicSuffix (host )
529
524
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 ])
531
526
} 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 )
533
528
}
534
529
}
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
+ }
535
547
parts [0 ] = host
548
+
536
549
return strings .Trim ("golang-" + strings .ToLower (strings .Replace (strings .Join (parts , "-" ), "_" , "-" , - 1 )), "-" )
537
550
}
538
551
0 commit comments