Skip to content

Commit 946f4e6

Browse files
committed
New upstream version 0.0~git20180827.d94f0cb
1 parent e858b89 commit 946f4e6

File tree

7 files changed

+144
-160
lines changed

7 files changed

+144
-160
lines changed

description.go

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ package main
22

33
import (
44
"bytes"
5-
"encoding/base64"
6-
"encoding/json"
5+
"context"
76
"fmt"
8-
"net/http"
97
"os/exec"
108
"strings"
119

1210
"github.com/russross/blackfriday"
1311
)
1412

15-
type readmeReply struct {
16-
Content string `json:"content"`
17-
Encoding string `json:"encoding"`
18-
Name string `json:"name"`
19-
}
20-
2113
func reformatForControl(raw string) string {
2214
// Reformat the wrapped description to conform to Debian’s control format.
2315
for strings.Contains(raw, "\n\n") {
@@ -30,26 +22,18 @@ func getLongDescriptionForGopkg(gopkg string) (string, error) {
3022
if !strings.HasPrefix(gopkg, "github.com/") {
3123
return "", nil
3224
}
33-
resp, err := http.Get("https://api.github.com/repos/" + gopkg[len("github.com/"):] + "/readme")
34-
if err != nil {
35-
return "", err
25+
parts := strings.Split(strings.TrimPrefix(gopkg, "github.com/"), "/")
26+
if got, want := len(parts), 2; got != want {
27+
return "", fmt.Errorf("invalid GitHub repo: %q does not follow github.com/owner/repo", gopkg)
3628
}
37-
defer resp.Body.Close()
29+
owner, repo := parts[0], parts[1]
3830

39-
if resp.StatusCode != http.StatusOK {
40-
return "", fmt.Errorf("unexpected HTTP status: got %d, want %d", resp.StatusCode, http.StatusOK)
41-
}
42-
43-
var rr readmeReply
44-
if err := json.NewDecoder(resp.Body).Decode(&rr); err != nil {
31+
rr, _, err := gitHub.Repositories.GetReadme(context.TODO(), owner, repo, nil)
32+
if err != nil {
4533
return "", err
4634
}
4735

48-
if rr.Encoding != "base64" {
49-
return "", fmt.Errorf("unexpected encoding: got %q, want %q", rr.Encoding, "base64")
50-
}
51-
52-
content, err := base64.StdEncoding.DecodeString(rr.Content)
36+
content, err := rr.GetContent()
5337
if err != nil {
5438
return "", err
5539
}
@@ -61,14 +45,14 @@ func getLongDescriptionForGopkg(gopkg string) (string, error) {
6145
// fairly involved, but it’d be the most correct solution to the problem at
6246
// hand. Our current code just knows markdown, which is good enough since
6347
// most (Go?) projects in fact use markdown for their README files.
64-
if !strings.HasSuffix(rr.Name, "md") &&
65-
!strings.HasSuffix(rr.Name, "markdown") &&
66-
!strings.HasSuffix(rr.Name, "mdown") &&
67-
!strings.HasSuffix(rr.Name, "mkdn") {
48+
if !strings.HasSuffix(rr.GetName(), "md") &&
49+
!strings.HasSuffix(rr.GetName(), "markdown") &&
50+
!strings.HasSuffix(rr.GetName(), "mdown") &&
51+
!strings.HasSuffix(rr.GetName(), "mkdn") {
6852
return reformatForControl(strings.TrimSpace(string(content))), nil
6953
}
7054

71-
output := blackfriday.Markdown(content, &TextRenderer{}, 0)
55+
output := blackfriday.Markdown([]byte(content), &TextRenderer{}, 0)
7256
// Shell out to fmt(1) to line-wrap the output.
7357
cmd := exec.Command("fmt")
7458
cmd.Stdin = bytes.NewBuffer(output)

estimate.go

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"go/build"
67
"io/ioutil"
78
"log"
89
"os"
910
"os/exec"
1011
"path/filepath"
12+
"sort"
1113
"strings"
1214

1315
"golang.org/x/tools/go/vcs"
16+
"golang.org/x/tools/refactor/importgraph"
1417
)
1518

1619
func get(gopath, repo string) error {
@@ -77,72 +80,94 @@ func estimate(importpath string) error {
7780
}
7881
}
7982

80-
// Use digraph(1) to obtain the forward transitive closure of the repo in
81-
// question.
82-
cmd := exec.Command("/bin/sh", "-c", "go list -f '{{.ImportPath}}{{.Imports}}{{.TestImports}}{{.XTestImports}}' ... | tr '[]' ' ' | digraph forward $(go list "+importpath+"/...)")
83+
// Remove standard lib packages
84+
cmd := exec.Command("go", "list", "std")
8385
cmd.Stderr = os.Stderr
8486
cmd.Env = append([]string{
8587
fmt.Sprintf("GOPATH=%s", gopath),
8688
}, passthroughEnv()...)
89+
8790
out, err := cmd.Output()
8891
if err != nil {
8992
return fmt.Errorf("%v: %v", cmd.Args, err)
9093
}
91-
92-
closure := make(map[string]bool)
94+
stdlib := make(map[string]bool)
9395
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
94-
closure[line] = true
96+
stdlib[line] = true
9597
}
9698

97-
// Remove standard lib packages
98-
cmd = exec.Command("go", "list", "std")
99-
cmd.Stderr = os.Stderr
100-
cmd.Env = append([]string{
101-
fmt.Sprintf("GOPATH=%s", gopath),
102-
}, passthroughEnv()...)
99+
stdlib["C"] = true // would fail resolving anyway
103100

104-
out, err = cmd.Output()
101+
// Filter out all already-packaged ones:
102+
golangBinaries, err := getGolangBinaries()
105103
if err != nil {
106-
return fmt.Errorf("%v: %v", cmd.Args, err)
107-
}
108-
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
109-
delete(closure, line)
104+
return nil
110105
}
111106

112-
delete(closure, "C") // would fail resolving anyway
107+
build.Default.GOPATH = gopath
108+
forward, _, errors := importgraph.Build(&build.Default)
109+
if len(errors) > 0 {
110+
lines := make([]string, 0, len(errors))
111+
for importPath, err := range errors {
112+
lines = append(lines, fmt.Sprintf("%s: %v", importPath, err))
113+
}
114+
return fmt.Errorf("could not load packages: %v", strings.Join(lines, "\n"))
115+
}
113116

114-
// Resolve all packages to the root of their repository.
115-
roots := make(map[string]bool)
116-
for dep := range closure {
117-
rr, err := vcs.RepoRootForImportPath(dep, false)
117+
var lines []string
118+
seen := make(map[string]bool)
119+
rrseen := make(map[string]bool)
120+
node := func(importPath string, indent int) {
121+
rr, err := vcs.RepoRootForImportPath(importPath, false)
118122
if err != nil {
119-
log.Printf("Could not determine repo path for import path %q: %v\n", dep, err)
120-
continue
123+
log.Printf("Could not determine repo path for import path %q: %v\n", importPath, err)
124+
return
121125
}
122-
123-
roots[rr.Root] = true
126+
if rrseen[rr.Root] {
127+
return
128+
}
129+
rrseen[rr.Root] = true
130+
if _, ok := golangBinaries[rr.Root]; ok {
131+
return // already packaged in Debian
132+
}
133+
lines = append(lines, fmt.Sprintf("%s%s", strings.Repeat(" ", indent), rr.Root))
124134
}
125-
126-
// Filter out all already-packaged ones:
127-
golangBinaries, err := getGolangBinaries()
128-
if err != nil {
129-
return nil
135+
var visit func(x string, indent int)
136+
visit = func(x string, indent int) {
137+
if seen[x] {
138+
return
139+
}
140+
seen[x] = true
141+
if !stdlib[x] {
142+
node(x, indent)
143+
}
144+
for y := range forward[x] {
145+
visit(y, indent+1)
146+
}
130147
}
131148

132-
for importpath, binary := range golangBinaries {
133-
if roots[importpath] {
134-
log.Printf("found %s in Debian package %s", importpath, binary)
135-
delete(roots, importpath)
149+
keys := make([]string, 0, len(forward))
150+
for key := range forward {
151+
keys = append(keys, key)
152+
}
153+
sort.Strings(keys)
154+
for _, key := range keys {
155+
if !strings.HasPrefix(key, importpath) {
156+
continue
157+
}
158+
if seen[key] {
159+
continue // already covered in a previous visit call
136160
}
161+
visit(key, 0)
137162
}
138163

139-
if len(roots) == 0 {
164+
if len(lines) == 0 {
140165
log.Printf("%s is already fully packaged in Debian", importpath)
141166
return nil
142167
}
143168
log.Printf("Bringing %s to Debian requires packaging the following Go packages:", importpath)
144-
for importpath := range roots {
145-
fmt.Println(importpath)
169+
for _, line := range lines {
170+
fmt.Println(line)
146171
}
147172

148173
return nil

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ package main
33
import (
44
"fmt"
55
"os"
6+
7+
"github.com/google/go-github/github"
8+
"github.com/gregjones/httpcache"
9+
)
10+
11+
var (
12+
gitHub *github.Client
613
)
714

815
func usage() {
@@ -19,6 +26,14 @@ func usage() {
1926
}
2027

2128
func main() {
29+
transport := github.BasicAuthTransport{
30+
Username: os.Getenv("GITHUB_USERNAME"),
31+
Password: os.Getenv("GITHUB_PASSWORD"),
32+
OTP: os.Getenv("GITHUB_OTP"),
33+
Transport: httpcache.NewMemoryCacheTransport(),
34+
}
35+
gitHub = github.NewClient(transport.Client())
36+
2237
// Retrieve args and Shift binary name off argument list.
2338
args := os.Args[1:]
2439

make.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ func debianNameFromGopkg(gopkg, t string, allowUnknownHoster bool) string {
410410
host = "howett"
411411
} else if host == "go4.org" {
412412
host = "go4"
413+
} else if host == "salsa.debian.org" {
414+
host = "debian"
413415
} else {
414416
if allowUnknownHoster {
415417
suffix, _ := publicsuffix.PublicSuffix(host)
@@ -489,12 +491,12 @@ func writeTemplates(dir, gopkg, debsrc, debbin, debversion, pkgType string, depe
489491
// TODO: change this once we have a “golang” section.
490492
fmt.Fprintf(f, "Section: devel\n")
491493
fmt.Fprintf(f, "Priority: optional\n")
492-
fmt.Fprintf(f, "Maintainer: Debian Go Packaging Team <pkg-go[email protected].debian.org>\n")
494+
fmt.Fprintf(f, "Maintainer: Debian Go Packaging Team <team+pkg-go@tracker.debian.org>\n")
493495
fmt.Fprintf(f, "Uploaders: %s <%s>\n", getDebianName(), getDebianEmail())
494496
sort.Strings(dependencies)
495497
builddeps := append([]string{"debhelper (>= 11)", "dh-golang", "golang-any"}, dependencies...)
496498
fmt.Fprintf(f, "Build-Depends: %s\n", strings.Join(builddeps, ",\n "))
497-
fmt.Fprintf(f, "Standards-Version: 4.1.4\n")
499+
fmt.Fprintf(f, "Standards-Version: 4.2.1\n")
498500
fmt.Fprintf(f, "Homepage: %s\n", getHomepageForGopkg(gopkg))
499501
fmt.Fprintf(f, "Vcs-Browser: https://salsa.debian.org/go-team/packages/%s\n", debsrc)
500502
fmt.Fprintf(f, "Vcs-Git: https://salsa.debian.org/go-team/packages/%s.git\n", debsrc)
@@ -572,6 +574,7 @@ func writeTemplates(dir, gopkg, debsrc, debbin, debversion, pkgType string, depe
572574
if pkgType == "program" {
573575
fmt.Fprintf(f, "override_dh_auto_install:\n")
574576
fmt.Fprintf(f, "\tdh_auto_install -- --no-source\n")
577+
fmt.Fprintf(f, "\n")
575578
}
576579
fmt.Fprintf(f, "%%:\n")
577580
fmt.Fprintf(f, "\tdh $@ --buildsystem=golang --with=golang\n")
@@ -601,7 +604,7 @@ func writeTemplates(dir, gopkg, debsrc, debbin, debversion, pkgType string, depe
601604
return err
602605
}
603606
defer f.Close()
604-
fmt.Fprintf(f, "version=3\n")
607+
fmt.Fprintf(f, "version=4\n")
605608
fmt.Fprintf(f, `opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/,\`+"\n", debsrc)
606609
fmt.Fprintf(f, `uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \`+"\n")
607610
fmt.Fprintf(f, ` https://%s/tags .*/v?(\d\S*)\.tar\.gz`+"\n", gopkg)
@@ -642,7 +645,7 @@ func writeITP(gopkg, debsrc, debversion string) (string, error) {
642645
fmt.Fprintf(f, "Subject: ITP: %s -- %s\n", debsrc, description)
643646
fmt.Fprintf(f, "Content-Type: text/plain; charset=utf-8\n")
644647
fmt.Fprintf(f, "Content-Transfer-Encoding: 8bit\n")
645-
fmt.Fprintf(f, "X-Debbugs-CC: [email protected], pkg-go-maintainers@lists.alioth.debian.org\n")
648+
fmt.Fprintf(f, "X-Debbugs-CC: [email protected], debian[email protected]\n")
646649
fmt.Fprintf(f, "\n")
647650
fmt.Fprintf(f, "Package: wnpp\n")
648651
fmt.Fprintf(f, "Severity: wishlist\n")
@@ -713,7 +716,7 @@ func execMake(args []string, usage func()) {
713716
fs.BoolVar(&allowUnknownHoster,
714717
"allow_unknown_hoster",
715718
false,
716-
"The pkg-go naming conventions (see https://pkg-go.alioth.debian.org/packaging.html) use a canonical identifier for the hostname, and the mapping is hardcoded into dh-make-golang. In case you want to package a Go package living on an unknown hoster, you may set this flag to true and double-check that the resulting package name is sane. Contact pkg-go if unsure.")
719+
"The pkg-go naming conventions (see https://go-team.pages.debian.net/packaging.html) use a canonical identifier for the hostname, and the mapping is hardcoded into dh-make-golang. In case you want to package a Go package living on an unknown hoster, you may set this flag to true and double-check that the resulting package name is sane. Contact pkg-go if unsure.")
717720

718721
var pkgType string
719722
fs.StringVar(&pkgType,

make_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestAcceptInput(t *testing.T) {
1717
for _, tt := range shortName {
1818
in := normalizeDebianProgramName(tt.in)
1919
if in != tt.out {
20-
t.Errorf("userInput(%q) => %q, want %q", tt.in, tt.out)
20+
t.Errorf("userInput(%q) => %q, want %q", tt.in, in, tt.out)
2121
}
2222
}
2323
}
@@ -39,7 +39,7 @@ func TestNormalizeDebianProgramName(t *testing.T) {
3939
for _, tt := range miscName {
4040
s := normalizeDebianProgramName(tt.in)
4141
if s != tt.out {
42-
t.Errorf("normalizeDebianProgramName(%q) => %q, want %q", tt.in, tt.out)
42+
t.Errorf("normalizeDebianProgramName(%q) => %q, want %q", tt.in, s, tt.out)
4343
}
4444
}
4545
}

0 commit comments

Comments
 (0)