Import upstream version 0.4.0+git20210803.1.fe36d31
Debian Janitor
2 years ago
494 | 494 | } |
495 | 495 | // Beginning newline in case the file already exists and lacks a newline |
496 | 496 | // (not all editors enforce a newline at the end of the file): |
497 | if _, err := f.Write([]byte("\n.pc\n")); err != nil { | |
497 | if _, err := f.Write([]byte("\n/.pc/\n/_build/\n")); err != nil { | |
498 | 498 | return dir, err |
499 | 499 | } |
500 | 500 | if err := f.Close(); err != nil { |
506 | 506 | return dir, err |
507 | 507 | } |
508 | 508 | |
509 | if err := runGitCommandIn(dir, "commit", "-m", "Ignore quilt dir .pc via .gitignore"); err != nil { | |
509 | if err := runGitCommandIn(dir, "commit", "-m", "Ignore _build and quilt .pc dirs via .gitignore"); err != nil { | |
510 | 510 | return dir, err |
511 | 511 | } |
512 | 512 | |
513 | 513 | return dir, nil |
514 | 514 | } |
515 | 515 | |
516 | // normalize program/source name into Debian standard[1] | |
517 | // https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source | |
516 | // normalize package name into Debian standard[1] | |
517 | // https://www.debian.org/doc/debian-policy/ch-controlfields.html#source | |
518 | 518 | // Package names (both source and binary, see Package, Section 5.6.7) must |
519 | 519 | // consist only of lower case letters (a-z), digits (0-9), plus (+) and minus |
520 | 520 | // (-) signs, and periods (.). They must be at least two characters long and |
521 | 521 | // must start with an alphanumeric character. |
522 | func normalizeDebianProgramName(str string) string { | |
522 | func normalizeDebianPackageName(str string) string { | |
523 | 523 | lowerDigitPlusMinusDot := func(r rune) rune { |
524 | 524 | switch { |
525 | 525 | case r >= 'a' && r <= 'z' || '0' <= r && r <= '9': |
553 | 553 | "git.sr.ht": "sourcehut", |
554 | 554 | "github.com": "github", |
555 | 555 | "gitlab.com": "gitlab", |
556 | "go.step.sm": "step", | |
556 | 557 | "go.uber.org": "uber", |
557 | 558 | "go4.org": "go4", |
558 | 559 | "gocloud.dev": "gocloud", |
588 | 589 | parts := strings.Split(gopkg, "/") |
589 | 590 | |
590 | 591 | if t == typeProgram || t == typeProgramLibrary { |
591 | return normalizeDebianProgramName(parts[len(parts)-1]) | |
592 | return normalizeDebianPackageName(parts[len(parts)-1]) | |
592 | 593 | } |
593 | 594 | |
594 | 595 | host, err := shortHostName(gopkg, allowUnknownHoster) |
597 | 598 | } |
598 | 599 | parts[0] = host |
599 | 600 | |
600 | for i := range parts { | |
601 | if i == 0 { | |
602 | continue | |
603 | } | |
604 | ||
605 | parts[i] = normalizeDebianProgramName(parts[i]) | |
606 | } | |
607 | ||
608 | return strings.Trim("golang-"+strings.Join(parts, "-"), "-") | |
601 | return normalizeDebianPackageName("golang-" + strings.Join(parts, "-")) | |
609 | 602 | } |
610 | 603 | |
611 | 604 | func getDebianName() string { |
14 | 14 | |
15 | 15 | func TestAcceptInput(t *testing.T) { |
16 | 16 | for _, tt := range shortName { |
17 | in := normalizeDebianProgramName(tt.in) | |
17 | in := normalizeDebianPackageName(tt.in) | |
18 | 18 | if in != tt.out { |
19 | 19 | t.Errorf("userInput(%q) => %q, want %q", tt.in, in, tt.out) |
20 | 20 | } |
34 | 34 | {"7h_make*go+3*.@", "7h-makego+3."}, |
35 | 35 | } |
36 | 36 | |
37 | func TestNormalizeDebianProgramName(t *testing.T) { | |
37 | func TestNormalizeDebianPackageName(t *testing.T) { | |
38 | 38 | for _, tt := range miscName { |
39 | s := normalizeDebianProgramName(tt.in) | |
39 | s := normalizeDebianPackageName(tt.in) | |
40 | 40 | if s != tt.out { |
41 | t.Errorf("normalizeDebianProgramName(%q) => %q, want %q", tt.in, s, tt.out) | |
41 | t.Errorf("normalizeDebianPackageName(%q) => %q, want %q", tt.in, s, tt.out) | |
42 | 42 | } |
43 | 43 | } |
44 | 44 | } |
51 | 51 | {"github.com/Debian/dh-make-golang", typeProgram, "dh-make-golang"}, |
52 | 52 | {"github.com/Debian/DH-make-golang", typeGuess, "golang-github-debian-dh-make-golang"}, |
53 | 53 | {"github.com/Debian/dh_make_golang", typeGuess, "golang-github-debian-dh-make-golang"}, |
54 | {"github.com/sean-/seed", typeGuess, "golang-github-sean--seed"}, | |
55 | {"git.sr.ht/~sircmpwn/getopt", typeGuess, "golang-sourcehut-sircmpwn-getopt"}, | |
56 | {"golang.org/x/term", typeLibrary, "golang-golang-x-term"}, | |
54 | 57 | } |
55 | 58 | |
56 | 59 | func TestDebianNameFromGopkg(t *testing.T) { |
42 | 42 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
43 | 43 | See the License for the specific language governing permissions and |
44 | 44 | limitations under the License. |
45 | . | |
45 | Comment: | |
46 | 46 | On Debian systems, the complete text of the Apache version 2.0 license |
47 | 47 | can be found in "/usr/share/common-licenses/Apache-2.0". |
48 | 48 | `, |
49 | 49 | "MPL-2.0": ` This Source Code Form is subject to the terms of the Mozilla Public |
50 | 50 | License, v. 2.0. If a copy of the MPL was not distributed with this |
51 | 51 | file, You can obtain one at http://mozilla.org/MPL/2.0/. |
52 | . | |
52 | Comment: | |
53 | 53 | On Debian systems, the complete text of the MPL-2.0 license can be found |
54 | 54 | in "/usr/share/common-licenses/MPL-2.0". |
55 | 55 | `, |
157 | 157 | sort.Strings(builddeps) |
158 | 158 | fprintfControlField(f, "Build-Depends", builddeps) |
159 | 159 | |
160 | fmt.Fprintf(f, "Standards-Version: 4.5.0\n") | |
160 | fmt.Fprintf(f, "Standards-Version: 4.5.1\n") | |
161 | 161 | fmt.Fprintf(f, "Vcs-Browser: https://salsa.debian.org/go-team/packages/%s\n", debsrc) |
162 | 162 | fmt.Fprintf(f, "Vcs-Git: https://salsa.debian.org/go-team/packages/%s.git\n", debsrc) |
163 | 163 | fmt.Fprintf(f, "Homepage: %s\n", getHomepageForGopkg(gopkg)) |