Implement distribution-specific builds

Make more things configurable at compile time so building binaries for distributions is easier while complying with the license.
pull/141/head
Sefa Eyeoglu 3 years ago committed by GitHub
parent a0620ae92c
commit 9b651eb701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -1,3 +1,2 @@
bin/
version.go
licenses.go

@ -1,7 +1,11 @@
UPDATE_URL=https://noisetorch.epicgamer.org
UPDATE_PUBKEY=3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk=
VERSION := $(shell git describe --tags)
dev: rnnoise
mkdir -p bin/
go generate
go build -o bin/noisetorch
go build -ldflags '-X main.version=${VERSION}' -o bin/noisetorch
release: rnnoise
mkdir -p bin/
mkdir -p tmp/
@ -14,7 +18,7 @@ release: rnnoise
mkdir -p tmp/.local/bin/
go generate
CGO_ENABLED=0 GOOS=linux go build -tags release -a -ldflags '-s -w -extldflags "-static"' .
CGO_ENABLED=0 GOOS=linux go build -tags release -a -ldflags '-s -w -extldflags "-static" -X main.version=${VERSION} -X main.distribution=official -X main.updateURL=${UPDATE_URL} -X main.publicKeyString=${UPDATE_PUBKEY}' .
upx noisetorch
mv noisetorch tmp/.local/bin/
cd tmp/; \

@ -22,7 +22,6 @@ import (
"github.com/aarzilli/nucular/style"
)
//go:generate go run scripts/embedversion.go
//go:generate go run scripts/embedlicenses.go
//go:embed c/ladspa/rnnoise_ladspa.so
@ -42,6 +41,11 @@ type device struct {
const appName = "NoiseTorch"
var version = "unknown" // will be changed by build
var distribution = "custom" // ditto
var updateURL = "" // ditto
var publicKeyString = "" // ditto
func main() {
opt := parseCLIOpts()
@ -50,7 +54,7 @@ func main() {
} else {
log.SetOutput(ioutil.Discard)
}
log.Printf("Application starting. Version: %s\n", version)
log.Printf("Application starting. Version: %s (%s)\n", version, distribution)
log.Printf("CAP_SYS_RESOURCE: %t\n", hasCapSysResource(getCurrentCaps()))
initializeConfigIfNot()

@ -1,24 +0,0 @@
package main
import (
"os"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("git", "describe", "--tags")
ret, err := cmd.Output()
if err != nil {
panic("Couldn't read git tags to embed version number")
}
version := strings.TrimSpace(string(ret))
out, _ := os.Create("version.go")
defer out.Close()
out.Write([]byte("package main\n\n//THIS FILE IS AUTOMATICALLY GENERATED BY `go generate` DO NOT EDIT!\n\nvar version=\""))
out.Write([]byte(version))
out.Write([]byte("\"\n"))
}

@ -22,8 +22,8 @@ func main() {
var doSign bool
flag.BoolVar(&doSign, "s", false, "Sign the release tar")
var doVerify bool
flag.BoolVar(&doVerify, "v", false, "Verify the signature of the tar")
var publicKeyString string
flag.StringVar(&publicKeyString, "k", "", "Public key to verify against (runs verifier if set)")
flag.Parse()
@ -56,9 +56,8 @@ func main() {
os.Exit(0)
}
if doVerify {
pubStr := "3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk="
pub, err := base64.StdEncoding.DecodeString(pubStr)
if publicKeyString != "" {
pub, err := base64.StdEncoding.DecodeString(publicKeyString)
if err != nil {
panic(err)
}

@ -345,7 +345,7 @@ func versionView(ctx *ntcontext, w *nucular.Window) {
w.Row(50).Dynamic(1)
w.Label("Version", "CB")
w.Row(50).Dynamic(1)
w.Label(version, "CB")
w.Label(fmt.Sprintf("%s (%s)", version, distribution), "CB")
w.Row(50).Dynamic(1)
w.Spacing(1)
w.Row(20).Dynamic(2)

@ -1,5 +1,3 @@
// +build release
package main
import (
@ -14,9 +12,6 @@ import (
"strings"
)
var updateURL = "https://noisetorch.epicgamer.org"
var publicKeyString = "3mL+rBi4yBZ1wGimQ/oSQCjxELzgTh+673H4JdzQBOk="
type updateui struct {
serverVersion string
available bool
@ -24,7 +19,14 @@ type updateui struct {
updatingText string
}
func updateable() bool {
return updateURL != "" && publicKeyString != ""
}
func updateCheck(ctx *ntcontext) {
if !updateable() {
return
}
log.Println("Checking for updates")
bodybuf, err := fetchFile("version.txt")
if err != nil {
@ -41,6 +43,9 @@ func updateCheck(ctx *ntcontext) {
}
func update(ctx *ntcontext) {
if !updateable() {
return
}
sig, err := fetchFile("NoiseTorch_x64.tgz.sig")
if err != nil {
log.Println("Couldn't fetch signature", err)
@ -94,8 +99,9 @@ func fetchFile(file string) ([]byte, error) {
func publickey() []byte {
pub, err := base64.StdEncoding.DecodeString(publicKeyString)
if err != nil {
panic(err) // it's hardcoded, we should never hit this, panic if we do
if err != nil { // Should only happen when distributor ships an invalid public key
log.Fatalf("Error while reading public key: %s\nContact the distribution '%s' about this error.\n", err, distribution)
os.Exit(1)
}
return pub
}

@ -1,18 +0,0 @@
// +build !release
package main
type updateui struct {
serverVersion string
available bool
triggered bool
updatingText string
}
func updateCheck(ctx *ntcontext) {
// noop for non-release versions
}
func update(ctx *ntcontext) {
// noop for non-release versions
}
Loading…
Cancel
Save