Split "all" build target, add package name as a tag

This commit is contained in:
Audrius Butkevicius
2020-06-21 10:49:00 +01:00
parent a96bbff47d
commit f4dc889951
+39 -13
View File
@@ -60,7 +60,7 @@ type target struct {
debpre string
debpost string
description string
buildPkgs []string
buildPkg string
binaryName string
archiveFiles []archiveFile
systemdServices []string
@@ -74,20 +74,21 @@ type archiveFile struct {
perm os.FileMode
}
var targets = map[string]target{
var targets = map[string][]target{
"all": {
// Only valid for the "build" and "install" commands as it lacks all
// the archive creation stuff. buildPkgs gets filled out in init()
tags: []string{"purego"},
},
"syncthing": {
{
// The default target for "build", "install", "tar", "zip", "deb", etc.
name: "syncthing",
debname: "syncthing",
debdeps: []string{"libc6", "procps"},
debpost: "script/post-upgrade",
description: "Open Source Continuous File Synchronization",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/syncthing"},
buildPkg: "github.com/syncthing/syncthing/cmd/syncthing",
binaryName: "syncthing", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
@@ -125,13 +126,15 @@ var targets = map[string]target{
{src: "assets/logo-only.svg", dst: "deb/usr/share/icons/hicolor/scalable/apps/syncthing.svg", perm: 0644},
},
},
},
"stdiscosrv": {
{
name: "stdiscosrv",
debname: "syncthing-discosrv",
debdeps: []string{"libc6"},
debpre: "cmd/stdiscosrv/scripts/preinst",
description: "Syncthing Discovery Server",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stdiscosrv"},
buildPkg: "github.com/syncthing/syncthing/cmd/stdiscosrv",
binaryName: "stdiscosrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
@@ -153,13 +156,15 @@ var targets = map[string]target{
},
tags: []string{"purego"},
},
},
"strelaysrv": {
{
name: "strelaysrv",
debname: "syncthing-relaysrv",
debdeps: []string{"libc6"},
debpre: "cmd/strelaysrv/scripts/preinst",
description: "Syncthing Relay Server",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/strelaysrv"},
buildPkg: "github.com/syncthing/syncthing/cmd/strelaysrv",
binaryName: "strelaysrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
@@ -182,12 +187,14 @@ var targets = map[string]target{
{src: "cmd/strelaysrv/etc/firewall-ufw/strelaysrv", dst: "deb/etc/ufw/applications.d/strelaysrv", perm: 0644},
},
},
},
"strelaypoolsrv": {
{
name: "strelaypoolsrv",
debname: "syncthing-relaypoolsrv",
debdeps: []string{"libc6"},
description: "Syncthing Relay Pool Server",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/strelaypoolsrv"},
buildPkg: "github.com/syncthing/syncthing/cmd/strelaypoolsrv",
binaryName: "strelaypoolsrv", // .exe will be added automatically for Windows builds
archiveFiles: []archiveFile{
{src: "{{binary}}", dst: "{{binary}}", perm: 0755},
@@ -202,6 +209,7 @@ var targets = map[string]target{
{src: "AUTHORS", dst: "deb/usr/share/doc/syncthing-relaypoolsrv/AUTHORS.txt", perm: 0644},
},
},
},
}
// These are repos we need to clone to run "go generate"
@@ -225,13 +233,18 @@ func init() {
// ignore dotfiles
continue
}
all.buildPkgs = append(all.buildPkgs, fmt.Sprintf("github.com/syncthing/syncthing/cmd/%s", pkg))
all = append(all, target{
name: pkg,
buildPkg: fmt.Sprintf("github.com/syncthing/syncthing/cmd/%s", pkg),
binaryName: pkg,
tags: []string{"purego"},
})
}
targets["all"] = all
// The "syncthing" target includes a few more files found in the "etc"
// and "extra" dirs.
syncthingPkg := targets["syncthing"]
for i, syncthingPkg := range targets["syncthing"] {
for _, file := range listFiles("etc") {
syncthingPkg.archiveFiles = append(syncthingPkg.archiveFiles, archiveFile{src: file, dst: file, perm: 0644})
}
@@ -241,7 +254,8 @@ func init() {
for _, file := range listFiles("extra") {
syncthingPkg.installationFiles = append(syncthingPkg.installationFiles, archiveFile{src: file, dst: "deb/usr/share/doc/syncthing/" + filepath.Base(file), perm: 0644})
}
targets["syncthing"] = syncthingPkg
targets["syncthing"][i] = syncthingPkg
}
}
func main() {
@@ -277,7 +291,7 @@ func main() {
}
}
func runCommand(cmd string, target target) {
func runCommand(cmd string, targets []target) {
switch cmd {
case "install":
var tags []string
@@ -285,7 +299,9 @@ func runCommand(cmd string, target target) {
tags = []string{"noupgrade"}
}
tags = append(tags, strings.Fields(extraTags)...)
for _, target := range targets {
install(target, tags)
}
metalintShort()
case "build":
@@ -294,7 +310,9 @@ func runCommand(cmd string, target target) {
tags = []string{"noupgrade"}
}
tags = append(tags, strings.Fields(extraTags)...)
for _, target := range targets {
build(target, tags)
}
case "test":
test("github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/...")
@@ -321,13 +339,19 @@ func runCommand(cmd string, target target) {
transifex()
case "tar":
for _, target := range targets {
buildTar(target)
}
case "zip":
for _, target := range targets {
buildZip(target)
}
case "deb":
for _, target := range targets {
buildDeb(target)
}
case "vet":
metalintShort()
@@ -444,6 +468,7 @@ func install(target target, tags []string) {
lazyRebuildAssets()
tags = append(target.tags, tags...)
tags = append(tags, target.name)
cwd, err := os.Getwd()
if err != nil {
@@ -467,13 +492,14 @@ func install(target target, tags []string) {
}
args := []string{"install", "-v"}
args = appendParameters(args, tags, target.buildPkgs...)
args = appendParameters(args, tags, target.buildPkg)
runPrint(goCmd, args...)
}
func build(target target, tags []string) {
lazyRebuildAssets()
tags = append(target.tags, tags...)
tags = append(tags, target.name)
rmr(target.BinaryName())
@@ -497,7 +523,7 @@ func build(target target, tags []string) {
}
args := []string{"build", "-v"}
args = appendParameters(args, tags, target.buildPkgs...)
args = appendParameters(args, tags, target.buildPkg)
runPrint(goCmd, args...)
}