Skip to content

Commit faa6421

Browse files
committed
New upstream version 0.6.0
1 parent 1c793f9 commit faa6421

16 files changed

+744
-240
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
99
strategy:
1010
matrix:
11-
go-version: ['1.15.x', '1.16.x', '1.17.x']
11+
go-version: ['1.16.x', '1.17.x']
1212
env:
1313
GO111MODULE: on # Needed for github.com/google/go-github/v38
1414

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dh-make-golang
22
_build/
33
*~
44
*.sw[op]
5+
.idea

check_depends.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"golang.org/x/mod/modfile"
6+
"golang.org/x/tools/go/vcs"
7+
"io/ioutil"
8+
"log"
9+
"os"
10+
"path/filepath"
11+
"pault.ag/go/debian/control"
12+
"strings"
13+
)
14+
15+
type dependency struct {
16+
importPath string
17+
packageName string
18+
// todo version?
19+
}
20+
21+
func execCheckDepends(args []string) {
22+
cwd, err := os.Getwd()
23+
if err != nil {
24+
log.Fatalf("error while getting current directory: %s", err)
25+
}
26+
27+
// Load the already packaged Go modules
28+
golangBinaries, err := getGolangBinaries()
29+
if err != nil {
30+
log.Fatalf("error while getting packaged Go modules: %s", err)
31+
}
32+
33+
// Load the dependencies defined in the Go module (go.mod)
34+
goModDepds, err := parseGoModDependencies(cwd, golangBinaries)
35+
if err != nil {
36+
log.Fatalf("error while parsing go.mod: %s", err)
37+
}
38+
39+
// Load the dependencies defined in the Debian packaging (d/control)
40+
packageDeps, err := parseDebianControlDependencies(cwd)
41+
if err != nil {
42+
log.Fatalf("error while parsing d/control: %s", err)
43+
}
44+
45+
hasChanged := false
46+
47+
// Check for newly introduced dependencies (defined in go.mod but not in d/control)
48+
for _, goModDep := range goModDepds {
49+
found := false
50+
51+
if goModDep.packageName == "" {
52+
fmt.Printf("NEW dependency %s is NOT yet packaged in Debian\n", goModDep.importPath)
53+
continue
54+
}
55+
56+
for _, packageDep := range packageDeps {
57+
if packageDep.packageName == goModDep.packageName {
58+
found = true
59+
break
60+
}
61+
}
62+
63+
if !found {
64+
hasChanged = true
65+
fmt.Printf("NEW dependency %s (%s)\n", goModDep.importPath, goModDep.packageName)
66+
}
67+
}
68+
69+
// Check for now unused dependencies (defined in d/control but not in go.mod)
70+
for _, packageDep := range packageDeps {
71+
found := false
72+
73+
for _, goModDep := range goModDepds {
74+
if goModDep.packageName == packageDep.packageName {
75+
found = true
76+
break
77+
}
78+
}
79+
80+
if !found {
81+
hasChanged = true
82+
fmt.Printf("RM dependency %s (%s)\n", packageDep.importPath, packageDep.packageName)
83+
}
84+
}
85+
86+
if !hasChanged {
87+
fmt.Printf("go.mod and d/control are in sync\n")
88+
}
89+
}
90+
91+
// parseGoModDependencies parse ALL dependencies listed in go.mod
92+
// i.e. it returns the one defined in go.mod as well as the transitively ones
93+
// TODO: this may not be the best way of doing thing since it requires the package to be converted to go module
94+
func parseGoModDependencies(directory string, goBinaries map[string]string) ([]dependency, error) {
95+
b, err := ioutil.ReadFile(filepath.Join(directory, "go.mod"))
96+
if err != nil {
97+
return nil, err
98+
}
99+
100+
modFile, err := modfile.Parse("go.mod", b, nil)
101+
if err != nil {
102+
return nil, err
103+
}
104+
105+
var dependencies []dependency
106+
for _, require := range modFile.Require {
107+
if !require.Indirect {
108+
packageName := ""
109+
110+
// Translate all packages to the root of their repository
111+
rr, err := vcs.RepoRootForImportPath(require.Mod.Path, false)
112+
if err != nil {
113+
log.Printf("Could not determine repo path for import path %q: %v\n", require.Mod.Path, err)
114+
continue
115+
}
116+
117+
if val, exists := goBinaries[rr.Root]; exists {
118+
packageName = val
119+
}
120+
121+
dependencies = append(dependencies, dependency{
122+
importPath: rr.Root,
123+
packageName: packageName,
124+
})
125+
}
126+
}
127+
128+
return dependencies, nil
129+
}
130+
131+
// parseDebianControlDependencies parse the Build-Depends defined in d/control
132+
func parseDebianControlDependencies(directory string) ([]dependency, error) {
133+
ctrl, err := control.ParseControlFile(filepath.Join(directory, "debian", "control"))
134+
if err != nil {
135+
return nil, err
136+
}
137+
138+
var dependencies []dependency
139+
140+
for _, bp := range ctrl.Source.BuildDepends.GetAllPossibilities() {
141+
packageName := strings.Trim(bp.Name, "\n")
142+
143+
// Ignore non -dev dependencies (i.e, debhelper-compat, git, cmake, etc...)
144+
if !strings.HasSuffix(packageName, "-dev") {
145+
continue
146+
}
147+
148+
dependencies = append(dependencies, dependency{
149+
importPath: "", // TODO XS-Go-Import-Path?
150+
packageName: packageName,
151+
})
152+
}
153+
154+
return dependencies, nil
155+
}

check_depends_test.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
7+
"reflect"
8+
"testing"
9+
)
10+
11+
func TestParseDebianControlDependencies(t *testing.T) {
12+
f := `Source: terminews
13+
Maintainer: Debian Go Packaging Team <[email protected]>
14+
Uploaders:
15+
Aloïs Micard <[email protected]>,
16+
Section: news
17+
Testsuite: autopkgtest-pkg-go
18+
Priority: optional
19+
Build-Depends:
20+
debhelper-compat (= 13),
21+
dh-golang,
22+
golang-any,
23+
golang-github-advancedlogic-goose-dev,
24+
golang-github-fatih-color-dev,
25+
golang-github-jroimartin-gocui-dev,
26+
golang-github-mattn-go-sqlite3-dev,
27+
golang-github-mmcdole-gofeed-dev,
28+
Standards-Version: 4.5.1
29+
Vcs-Browser: https://salsa.debian.org/go-team/packages/terminews
30+
Vcs-Git: https://salsa.debian.org/go-team/packages/terminews.git
31+
Homepage: https://github.com/antavelos/terminews
32+
Rules-Requires-Root: no
33+
XS-Go-Import-Path: github.com/antavelos/terminews
34+
35+
Package: terminews
36+
Architecture: any
37+
Depends:
38+
${misc:Depends},
39+
${shlibs:Depends},
40+
Built-Using:
41+
${misc:Built-Using},
42+
Description: read your RSS feeds from your terminal
43+
Terminews is a terminal based application (TUI)
44+
that allows you to manage RSS resources and display their news feeds.
45+
`
46+
tmpDir, err := ioutil.TempDir("", "dh-make-golang")
47+
if err != nil {
48+
t.Fatalf("Could not create temp dir: %v", err)
49+
}
50+
defer os.RemoveAll(tmpDir)
51+
52+
if err := os.MkdirAll(filepath.Join(tmpDir, "dummy-package", "debian"), 0750); err != nil {
53+
t.Fatalf("Could not create dummy Debian package: %v", err)
54+
}
55+
if err := ioutil.WriteFile(filepath.Join(tmpDir, "dummy-package", "debian", "control"), []byte(f), 0640); err != nil {
56+
t.Fatalf("Could not create dummy Debian package: %v", err)
57+
}
58+
59+
deps, err := parseDebianControlDependencies(filepath.Join(tmpDir, "dummy-package"))
60+
if err != nil {
61+
t.Fatalf("Could not parse Debian package dependencies: %v", err)
62+
63+
}
64+
65+
want := []dependency{
66+
{
67+
importPath: "",
68+
packageName: "golang-github-advancedlogic-goose-dev",
69+
},
70+
{
71+
importPath: "",
72+
packageName: "golang-github-fatih-color-dev",
73+
}, {
74+
importPath: "",
75+
packageName: "golang-github-jroimartin-gocui-dev",
76+
},
77+
{
78+
importPath: "",
79+
packageName: "golang-github-mattn-go-sqlite3-dev",
80+
},
81+
{
82+
importPath: "",
83+
packageName: "golang-github-mmcdole-gofeed-dev",
84+
},
85+
}
86+
87+
if !reflect.DeepEqual(deps, want) {
88+
t.Fatalf("Wrong dependencies returned (got %v want %v)", deps, want)
89+
}
90+
}
91+
92+
func TestParseGoModDependencies(t *testing.T) {
93+
f := `module github.com/Debian/dh-make-golang
94+
95+
go 1.16
96+
97+
require (
98+
github.com/charmbracelet/glamour v0.3.0
99+
github.com/google/go-github/v38 v38.1.0
100+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
101+
)`
102+
tmpDir, err := ioutil.TempDir("", "dh-make-golang")
103+
if err != nil {
104+
t.Fatalf("Could not create temp dir: %v", err)
105+
}
106+
defer os.RemoveAll(tmpDir)
107+
108+
if err := os.MkdirAll(filepath.Join(tmpDir, "dummy-package"), 0750); err != nil {
109+
t.Fatalf("Could not create dummy Debian package: %v", err)
110+
}
111+
if err := ioutil.WriteFile(filepath.Join(tmpDir, "dummy-package", "go.mod"), []byte(f), 0640); err != nil {
112+
t.Fatalf("Could not create dummy Debian package: %v", err)
113+
}
114+
115+
deps, err := parseGoModDependencies(filepath.Join(tmpDir, "dummy-package"), map[string]string{
116+
"github.com/charmbracelet/glamour": "golang-github-charmbracelet-glamour-dev",
117+
"github.com/google/go-github": "golang-github-google-go-github-dev",
118+
"github.com/gregjones/httpcache": "golang-github-gregjones-httpcache-dev",
119+
})
120+
if err != nil {
121+
t.Fatalf("Could not parse go.mod dependencies: %v", err)
122+
123+
}
124+
125+
want := []dependency{
126+
{
127+
importPath: "github.com/charmbracelet/glamour",
128+
packageName: "golang-github-charmbracelet-glamour-dev",
129+
},
130+
{
131+
importPath: "github.com/google/go-github",
132+
packageName: "golang-github-google-go-github-dev",
133+
}, {
134+
importPath: "github.com/gregjones/httpcache",
135+
packageName: "golang-github-gregjones-httpcache-dev",
136+
},
137+
}
138+
139+
if !reflect.DeepEqual(deps, want) {
140+
t.Fatalf("Wrong dependencies returned (got %v want %v)", deps, want)
141+
}
142+
}

clone.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"os"
8+
"os/exec"
9+
)
10+
11+
func execClone(args []string) {
12+
fs := flag.NewFlagSet("clone", flag.ExitOnError)
13+
14+
fs.Usage = func() {
15+
fmt.Fprintf(os.Stderr, "Usage: %s clone <package-name>\n", os.Args[0])
16+
fmt.Fprintf(os.Stderr, "Clone a Go package from Salsa\n"+
17+
"and download the appropriate tarball.\n")
18+
fmt.Fprintf(os.Stderr, "Example: %s clone golang-github-mmcdole-goxpp\n", os.Args[0])
19+
}
20+
21+
err := fs.Parse(args)
22+
if err != nil {
23+
log.Fatalf("parse args: %s", err)
24+
}
25+
26+
if fs.NArg() != 1 {
27+
fs.Usage()
28+
os.Exit(1)
29+
}
30+
31+
cmd := exec.Command("gbp", "clone", fmt.Sprintf("vcsgit:%s", fs.Arg(0)), "--postclone=origtargz")
32+
cmd.Stderr = os.Stderr
33+
if err := cmd.Run(); err != nil {
34+
log.Fatalf("Could not run %v: %v", cmd.Args, err)
35+
}
36+
37+
fmt.Printf("Successfully cloned %s\n", fs.Arg(0))
38+
}

create_salsa_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func execCreateSalsaProject(args []string) {
3030
projectName := fs.Arg(0)
3131

3232
// The source code of the corresponding server can be found at:
33-
// https://github.com/Debian/pkg-go-tools/tree/master/cmd/pgt-api-server
33+
// https://salsa.debian.org/go-team/infra/pkg-go-tools/-/tree/master/cmd/pgt-api-server
3434
u, _ := url.Parse("https://pgt-api-server.debian.net/v1/createrepo")
3535
q := u.Query()
3636
q.Set("repo", projectName)

0 commit comments

Comments
 (0)