Skip to content

Commit b845199

Browse files
committed
New upstream version 0.2.0
2 parents ae50191 + b737b16 commit b845199

File tree

6 files changed

+218
-62
lines changed

6 files changed

+218
-62
lines changed

description.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"context"
6-
"fmt"
76
"os/exec"
87
"strings"
98

@@ -18,15 +17,13 @@ func reformatForControl(raw string) string {
1817
return strings.Replace(raw, "\n", "\n ", -1)
1918
}
2019

20+
// getDescriptionForGopkg reads from README.md (or equivalent) from GitHub,
21+
// intended for the extended description in debian/control.
2122
func getLongDescriptionForGopkg(gopkg string) (string, error) {
22-
if !strings.HasPrefix(gopkg, "github.com/") {
23-
return "", nil
24-
}
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)
23+
owner, repo, err := findGitHubRepo(gopkg)
24+
if err != nil {
25+
return "", err
2826
}
29-
owner, repo := parts[0], parts[1]
3027

3128
rr, _, err := gitHub.Repositories.GetReadme(context.TODO(), owner, repo, nil)
3229
if err != nil {

make.go

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"io/ioutil"
88
"log"
9+
"net/http"
910
"os"
1011
"os/exec"
1112
"os/user"
@@ -75,14 +76,41 @@ func findVendorDirs(dir string) ([]string, error) {
7576
return vendorDirs, err
7677
}
7778

79+
func downloadFile(filename, url string) error {
80+
dst, err := os.Create(filename)
81+
if err != nil {
82+
return err
83+
}
84+
defer dst.Close()
85+
86+
resp, err := http.Get(url)
87+
if err != nil {
88+
return err
89+
}
90+
defer resp.Body.Close()
91+
if resp.StatusCode != 200 {
92+
return fmt.Errorf(resp.Status)
93+
}
94+
95+
_, err = io.Copy(dst, resp.Body)
96+
if err != nil {
97+
return err
98+
}
99+
100+
return nil
101+
}
102+
78103
// upstream describes the upstream repo we are about to package.
79104
type upstream struct {
80-
tarPath string // path to the generated orig tarball tempfile
81-
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
82-
firstMain string // import path of the first main package within repo, if any
83-
vendorDirs []string // all vendor sub directories, relative to the repo directory
84-
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
85-
hasGodeps bool // whether the Godeps/_workspace directory exists
105+
tarPath string // path to the downloaded or generated orig tarball tempfile
106+
compression string // compression method, either "gz" or "xz"
107+
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
108+
firstMain string // import path of the first main package within repo, if any
109+
vendorDirs []string // all vendor sub directories, relative to the repo directory
110+
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
111+
hasGodeps bool // whether the Godeps/_workspace directory exists
112+
hasRelease bool // whether any release tags exist, for debian/watch
113+
isRelease bool // whether we are packaging a tagged version or not
86114
}
87115

88116
func (u *upstream) get(gopath, repo, rev string) error {
@@ -101,14 +129,61 @@ func (u *upstream) get(gopath, repo, rev string) error {
101129
return rr.VCS.Create(dir, rr.Repo)
102130
}
103131

132+
func (u *upstream) tarballFromHoster(repo string) error {
133+
var url string
134+
parts := strings.Split(repo, "/")
135+
if len(parts) < 3 {
136+
return fmt.Errorf("Unsupported hoster")
137+
}
138+
host, owner, project := parts[0], parts[1], parts[2]
139+
140+
switch host {
141+
case "github.com":
142+
url = fmt.Sprintf("https://%s/%s/%s/archive/v%s.tar.%s",
143+
host, owner, project, u.version, u.compression)
144+
case "gitlab.com":
145+
url = fmt.Sprintf("https://%s/%s/%s/-/archive/v%s/%s-%s.tar.%s",
146+
host, owner, project, u.version, project, u.version, u.compression)
147+
default:
148+
return fmt.Errorf("Unsupported hoster")
149+
}
150+
151+
done := make(chan struct{})
152+
go progressSize("Download", u.tarPath, done)
153+
154+
log.Printf("Downloading %s", url)
155+
err := downloadFile(u.tarPath, url)
156+
157+
close(done)
158+
159+
return err
160+
}
161+
104162
func (u *upstream) tar(gopath, repo string) error {
105163
f, err := ioutil.TempFile("", "dh-make-golang")
106164
if err != nil {
107165
return err
108166
}
109167
u.tarPath = f.Name()
110168
f.Close()
169+
170+
if u.isRelease {
171+
if u.hasGodeps {
172+
log.Printf("Godeps/_workspace exists, not downloading tarball from hoster.")
173+
} else {
174+
u.compression = "gz"
175+
err := u.tarballFromHoster(repo)
176+
if err != nil && err.Error() == "Unsupported hoster" {
177+
log.Printf("INFO: Hoster does not provide release tarball\n")
178+
} else {
179+
return err
180+
}
181+
}
182+
}
183+
184+
u.compression = "xz"
111185
base := filepath.Base(repo)
186+
log.Printf("Generating temp tarball as %q\n", u.tarPath)
112187
dir := filepath.Dir(repo)
113188
cmd := exec.Command(
114189
"tar",
@@ -222,7 +297,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
222297
return nil
223298
}
224299

225-
func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
300+
func makeUpstreamSourceTarball(repo, revision string, forcePrerelease bool) (*upstream, error) {
226301
gopath, err := ioutil.TempDir("", "dh-make-golang")
227302
if err != nil {
228303
return nil, err
@@ -266,7 +341,7 @@ func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
266341

267342
log.Printf("Determining upstream version number\n")
268343

269-
u.version, err = pkgVersionFromGit(repoDir)
344+
u.version, u.hasRelease, u.isRelease, err = pkgVersionFromGit(repoDir, forcePrerelease)
270345
if err != nil {
271346
return nil, err
272347
}
@@ -431,10 +506,14 @@ func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) s
431506
host = "golang"
432507
case "google.golang.org":
433508
host = "google"
509+
case "gitlab.com":
510+
host = "gitlab"
434511
case "bitbucket.org":
435512
host = "bitbucket"
436513
case "bazil.org":
437514
host = "bazil"
515+
case "blitiri.com.ar":
516+
host = "blitiri"
438517
case "pault.ag":
439518
host = "pault"
440519
case "howett.net":
@@ -611,6 +690,12 @@ func execMake(args []string, usage func()) {
611690
"and the \"Drop pristine-tar branches\" section at\n"+
612691
"https://go-team.pages.debian.net/workflow-changes.html")
613692

693+
var forcePrerelease bool
694+
fs.BoolVar(&forcePrerelease,
695+
"force-prerelease",
696+
false,
697+
"Package @master or @tip instead of the latest tagged version")
698+
614699
var pkgTypeString string
615700
fs.StringVar(&pkgTypeString,
616701
"type",
@@ -721,7 +806,8 @@ func execMake(args []string, usage func()) {
721806
golangBinaries, err = getGolangBinaries()
722807
return err
723808
})
724-
u, err := makeUpstreamSourceTarball(gopkg, gitRevision)
809+
810+
u, err := makeUpstreamSourceTarball(gopkg, gitRevision, forcePrerelease)
725811
if err != nil {
726812
log.Fatalf("Could not create a tarball of the upstream source: %v\n", err)
727813
}
@@ -749,7 +835,8 @@ func execMake(args []string, usage func()) {
749835
debbin, debbin)
750836
}
751837

752-
orig := fmt.Sprintf("%s_%s.orig.tar.xz", debsrc, u.version)
838+
orig := fmt.Sprintf("%s_%s.orig.tar.%s", debsrc, u.version, u.compression)
839+
log.Printf("Moving tempfile to %q\n", orig)
753840
// We need to copy the file, merely renaming is not enough since the file
754841
// might be on a different filesystem (/tmp often is a tmpfs).
755842
if err := copyFile(u.tarPath, orig); err != nil {
@@ -782,8 +869,7 @@ func execMake(args []string, usage func()) {
782869
}
783870

784871
if err := writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion,
785-
pkgType, debdependencies, u.vendorDirs, u.hasGodeps,
786-
dep14, pristineTar); err != nil {
872+
pkgType, debdependencies, u, dep14, pristineTar); err != nil {
787873
log.Fatalf("Could not create debian/ from templates: %v\n", err)
788874
}
789875

@@ -826,4 +912,5 @@ func execMake(args []string, usage func()) {
826912
fmt.Printf("Once you are happy with your packaging, push it to salsa using:\n")
827913
fmt.Printf(" git remote set-url origin [email protected]:go-team/packages/%s.git\n", debsrc)
828914
fmt.Printf(" gbp push\n")
915+
fmt.Printf("\n")
829916
}

metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ func getAuthorAndCopyrightForGopkg(gopkg string) (string, string, error) {
173173
return ur.GetName(), copyright, nil
174174
}
175175

176+
// getDescriptionForGopkg gets the package description from GitHub,
177+
// intended for the synopsis or the short description in debian/control.
176178
func getDescriptionForGopkg(gopkg string) (string, error) {
177179
owner, repo, err := findGitHubRepo(gopkg)
178180
if err != nil {

template.go

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
)
1212

1313
func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
14-
pkgType packageType, dependencies []string, vendorDirs []string,
15-
hasGodeps bool, dep14, pristineTar bool) error {
14+
pkgType packageType, dependencies []string, u *upstream, dep14, pristineTar bool) error {
1615
if err := os.Mkdir(filepath.Join(dir, "debian"), 0755); err != nil {
1716
return err
1817
}
@@ -26,7 +25,7 @@ func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
2625
if err := writeDebianControl(dir, gopkg, debsrc, debLib, debProg, pkgType, dependencies); err != nil {
2726
return err
2827
}
29-
if err := writeDebianCopyright(dir, gopkg, vendorDirs, hasGodeps); err != nil {
28+
if err := writeDebianCopyright(dir, gopkg, u.vendorDirs, u.hasGodeps); err != nil {
3029
return err
3130
}
3231
if err := writeDebianRules(dir, pkgType); err != nil {
@@ -38,7 +37,7 @@ func writeTemplates(dir, gopkg, debsrc, debLib, debProg, debversion string,
3837
if err := writeDebianGbpConf(dir, dep14, pristineTar); err != nil {
3938
return err
4039
}
41-
if err := writeDebianWatch(dir, gopkg, debsrc); err != nil {
40+
if err := writeDebianWatch(dir, gopkg, debsrc, u.hasRelease); err != nil {
4241
return err
4342
}
4443
if err := writeDebianPackageInstall(dir, debLib, debProg, pkgType); err != nil {
@@ -90,6 +89,7 @@ func addDescription(f *os.File, gopkg, comment string) {
9089
description = "TODO: short description"
9190
}
9291
fmt.Fprintf(f, "Description: %s %s\n", description, comment)
92+
9393
longdescription, err := getLongDescriptionForGopkg(gopkg)
9494
if err != nil {
9595
log.Printf("Could not determine long description for %q: %v\n", gopkg, err)
@@ -295,19 +295,48 @@ func writeDebianGbpConf(dir string, dep14, pristineTar bool) error {
295295
return nil
296296
}
297297

298-
func writeDebianWatch(dir, gopkg, debsrc string) error {
299-
if strings.HasPrefix(gopkg, "github.com/") {
300-
f, err := os.Create(filepath.Join(dir, "debian", "watch"))
301-
if err != nil {
302-
return err
303-
}
304-
defer f.Close()
298+
func writeDebianWatch(dir, gopkg, debsrc string, hasRelease bool) error {
299+
// TODO: Support other hosters too
300+
host := "github.com"
301+
302+
owner, repo, err := findGitHubRepo(gopkg)
303+
if err != nil {
304+
log.Printf("debian/watch: Unable to resolve %s to github.com, skipping\n", gopkg)
305+
return nil
306+
}
307+
if !strings.HasPrefix(gopkg, "github.com/") {
308+
log.Printf("debian/watch: %s resolves to %s/%s/%s\n", gopkg, host, owner, repo)
309+
}
305310

311+
f, err := os.Create(filepath.Join(dir, "debian", "watch"))
312+
if err != nil {
313+
return err
314+
}
315+
defer f.Close()
316+
317+
if hasRelease {
318+
log.Printf("Setting debian/watch to track release tarball")
306319
fmt.Fprintf(f, "version=4\n")
307-
fmt.Fprintf(f, `opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/,\`+"\n", debsrc)
308-
fmt.Fprintf(f, `uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \`+"\n")
309-
fmt.Fprintf(f, ` https://%s/tags .*/v?(\d\S*)\.tar\.gz`+"\n", gopkg)
320+
fmt.Fprintf(f, `opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/, \`+"\n", debsrc)
321+
fmt.Fprintf(f, ` uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/" \`+"\n")
322+
fmt.Fprintf(f, ` https://%s/%s/%s/tags .*/v?(\d\S*)\.tar\.gz debian`+"\n", host, owner, repo)
323+
} else {
324+
log.Printf("Setting debian/watch to track git HEAD")
325+
fmt.Fprintf(f, "version=4\n")
326+
fmt.Fprintf(f, `opts="mode=git, pgpmode=none" \`+"\n")
327+
fmt.Fprintf(f, ` https://%s/%s/%s.git \`+"\n", host, owner, repo)
328+
fmt.Fprintf(f, " HEAD debian\n")
329+
330+
// Anticipate that upstream would eventually switch to tagged releases
331+
fmt.Fprintf(f, "\n")
332+
fmt.Fprintf(f, "# Use the following when upstream starts to tag releases:\n")
333+
fmt.Fprintf(f, "#\n")
334+
fmt.Fprintf(f, "#version=4\n")
335+
fmt.Fprintf(f, `#opts="filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/%s-\$1\.tar\.gz/, \`+"\n", debsrc)
336+
fmt.Fprintf(f, `# uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/" \`+"\n")
337+
fmt.Fprintf(f, `# https://%s/%s/%s/tags .*/v?(\d\S*)\.tar\.gz debian`+"\n", host, owner, repo)
310338
}
339+
311340
return nil
312341
}
313342

0 commit comments

Comments
 (0)