6
6
"io"
7
7
"io/ioutil"
8
8
"log"
9
+ "net/http"
9
10
"os"
10
11
"os/exec"
11
12
"os/user"
@@ -75,14 +76,41 @@ func findVendorDirs(dir string) ([]string, error) {
75
76
return vendorDirs , err
76
77
}
77
78
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
+
78
103
// upstream describes the upstream repo we are about to package.
79
104
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
86
114
}
87
115
88
116
func (u * upstream ) get (gopath , repo , rev string ) error {
@@ -101,14 +129,61 @@ func (u *upstream) get(gopath, repo, rev string) error {
101
129
return rr .VCS .Create (dir , rr .Repo )
102
130
}
103
131
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
+
104
162
func (u * upstream ) tar (gopath , repo string ) error {
105
163
f , err := ioutil .TempFile ("" , "dh-make-golang" )
106
164
if err != nil {
107
165
return err
108
166
}
109
167
u .tarPath = f .Name ()
110
168
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"
111
185
base := filepath .Base (repo )
186
+ log .Printf ("Generating temp tarball as %q\n " , u .tarPath )
112
187
dir := filepath .Dir (repo )
113
188
cmd := exec .Command (
114
189
"tar" ,
@@ -222,7 +297,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
222
297
return nil
223
298
}
224
299
225
- func makeUpstreamSourceTarball (repo , revision string ) (* upstream , error ) {
300
+ func makeUpstreamSourceTarball (repo , revision string , forcePrerelease bool ) (* upstream , error ) {
226
301
gopath , err := ioutil .TempDir ("" , "dh-make-golang" )
227
302
if err != nil {
228
303
return nil , err
@@ -266,7 +341,7 @@ func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
266
341
267
342
log .Printf ("Determining upstream version number\n " )
268
343
269
- u .version , err = pkgVersionFromGit (repoDir )
344
+ u .version , u . hasRelease , u . isRelease , err = pkgVersionFromGit (repoDir , forcePrerelease )
270
345
if err != nil {
271
346
return nil , err
272
347
}
@@ -431,10 +506,14 @@ func debianNameFromGopkg(gopkg string, t packageType, allowUnknownHoster bool) s
431
506
host = "golang"
432
507
case "google.golang.org" :
433
508
host = "google"
509
+ case "gitlab.com" :
510
+ host = "gitlab"
434
511
case "bitbucket.org" :
435
512
host = "bitbucket"
436
513
case "bazil.org" :
437
514
host = "bazil"
515
+ case "blitiri.com.ar" :
516
+ host = "blitiri"
438
517
case "pault.ag" :
439
518
host = "pault"
440
519
case "howett.net" :
@@ -611,6 +690,12 @@ func execMake(args []string, usage func()) {
611
690
"and the \" Drop pristine-tar branches\" section at\n " +
612
691
"https://go-team.pages.debian.net/workflow-changes.html" )
613
692
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
+
614
699
var pkgTypeString string
615
700
fs .StringVar (& pkgTypeString ,
616
701
"type" ,
@@ -721,7 +806,8 @@ func execMake(args []string, usage func()) {
721
806
golangBinaries , err = getGolangBinaries ()
722
807
return err
723
808
})
724
- u , err := makeUpstreamSourceTarball (gopkg , gitRevision )
809
+
810
+ u , err := makeUpstreamSourceTarball (gopkg , gitRevision , forcePrerelease )
725
811
if err != nil {
726
812
log .Fatalf ("Could not create a tarball of the upstream source: %v\n " , err )
727
813
}
@@ -749,7 +835,8 @@ func execMake(args []string, usage func()) {
749
835
debbin , debbin )
750
836
}
751
837
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 )
753
840
// We need to copy the file, merely renaming is not enough since the file
754
841
// might be on a different filesystem (/tmp often is a tmpfs).
755
842
if err := copyFile (u .tarPath , orig ); err != nil {
@@ -782,8 +869,7 @@ func execMake(args []string, usage func()) {
782
869
}
783
870
784
871
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 {
787
873
log .Fatalf ("Could not create debian/ from templates: %v\n " , err )
788
874
}
789
875
@@ -826,4 +912,5 @@ func execMake(args []string, usage func()) {
826
912
fmt .Printf ("Once you are happy with your packaging, push it to salsa using:\n " )
827
913
fmt .
Printf (
" git remote set-url origin [email protected] :go-team/packages/%s.git\n " ,
debsrc )
828
914
fmt .Printf (" gbp push\n " )
915
+ fmt .Printf ("\n " )
829
916
}
0 commit comments