-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsbuild.go
More file actions
105 lines (98 loc) · 2.79 KB
/
sbuild.go
File metadata and controls
105 lines (98 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"pault.ag/go/debian/version"
)
type sbuild struct {
dist string
logDir string
dryRun bool
keepBuildLog bool
extraDebs []string
extraExperimental bool
extraPockets bool
pocketsCodename string
}
func (s *sbuild) buildCommandLine(sourcePackage string, version *version.Version) []string {
target := fmt.Sprintf("%s_%s", sourcePackage, version)
// TODO: discard resulting package immediately?
cmd := []string{
"sbuild",
"--arch-all",
"--dist=" + s.dist,
}
switch {
case s.extraPockets && s.pocketsCodename != "":
cmd = append(cmd,
"--extra-repository='deb-src http://deb.debian.org/debian "+s.pocketsCodename+" main'",
"--extra-repository='deb-src http://deb.debian.org/debian "+s.pocketsCodename+"-updates main'",
"--extra-repository='deb-src http://deb.debian.org/debian-security "+s.pocketsCodename+"-security main'",
)
case s.extraExperimental:
cmd = append(cmd,
"--extra-repository='deb-src http://deb.debian.org/debian unstable main'",
"--extra-repository='deb http://deb.debian.org/debian experimental main'",
"--extra-repository='deb-src http://deb.debian.org/debian experimental main'",
"--build-dep-resolver=aspcud",
"--aspcud-criteria='-count(down),-count(changed,APT-Release:=/experimental/),-removed,-changed,-new'",
)
// force installation of provided extra packages by adding them as build-deps
for _, filename := range s.extraDebs {
base := filepath.Base(filename)
if strings.HasSuffix(base, ".deb") {
base = strings.TrimSuffix(base, ".deb")
}
parts := strings.Split(base, "_")
if len(parts) >= 2 {
pkgName := parts[0]
pkgVer := parts[1]
arg := fmt.Sprintf("--add-depends='%s (= %s)'", pkgName, pkgVer)
cmd = append(cmd, arg)
}
}
}
if !s.keepBuildLog {
cmd = append(cmd, "--nolog")
}
cmd = append(cmd, target)
for _, filename := range s.extraDebs {
cmd = append(cmd, fmt.Sprintf("--extra-package=%s", filename))
}
return cmd
}
func (s *sbuild) build(sourcePackage string, version *version.Version) *buildResult {
result := &buildResult{
src: sourcePackage,
version: version,
}
commandLine := s.buildCommandLine(sourcePackage, version)
if s.dryRun {
log.Printf(" commandline: %v\n", commandLine)
return result
}
cmd := exec.Command(commandLine[0], commandLine[1:]...)
target := fmt.Sprintf("%s_%s", sourcePackage, version)
if !s.keepBuildLog {
buildlog, err := os.Create(filepath.Join(s.logDir, target))
if err != nil {
result.err = err
return result
}
defer buildlog.Close()
cmd.Stdout = buildlog
cmd.Stderr = buildlog
} else {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
result.err = cmd.Run()
if !s.keepBuildLog {
result.logFile = filepath.Join(s.logDir, target)
}
return result
}