From 31d975057927a674a5d9ae6a5c7fb42ecd72d1f7 Mon Sep 17 00:00:00 2001 From: Leo Arias Date: Thu, 20 Oct 2016 09:16:30 +0000 Subject: [PATCH] build: Add build method for snapcraft GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3636 --- build.go | 24 ++++++++++++++++++++++-- snapcraft.yaml.template | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 snapcraft.yaml.template diff --git a/build.go b/build.go index 25cb17deb..e790d71a5 100644 --- a/build.go +++ b/build.go @@ -28,6 +28,7 @@ import ( "strconv" "strings" "syscall" + "text/template" "time" ) @@ -275,6 +276,9 @@ func runCommand(cmd string, target target) { case "deb": buildDeb(target) + case "snap": + buildSnap(target) + case "clean": clean() @@ -481,8 +485,8 @@ func buildDeb(target target) { os.RemoveAll("deb") // "goarch" here is set to whatever the Debian packages expect. We correct - // "it to what we actually know how to build and keep the Debian variant - // "name in "debarch". + // it to what we actually know how to build and keep the Debian variant + // name in "debarch". debarch := goarch switch goarch { case "i386": @@ -520,6 +524,22 @@ func buildDeb(target target) { "--license", "MPL-2") } +func buildSnap(target target) { + tmpl, err := template.ParseFiles("snapcraft.yaml.template") + if err != nil { + log.Fatal(err) + } + f, err := os.Create("snapcraft.yaml") + defer f.Close() + if err != nil { + log.Fatal(err) + } + err = tmpl.Execute(f, map[string]string{"Version": version}) + runPrint("snapcraft", "clean") + build(target, []string{"noupgrade"}) + runPrint("snapcraft") +} + func copyFile(src, dst string, perm os.FileMode) error { dstDir := filepath.Dir(dst) os.MkdirAll(dstDir, 0755) // ignore error diff --git a/snapcraft.yaml.template b/snapcraft.yaml.template new file mode 100644 index 000000000..c92c3f950 --- /dev/null +++ b/snapcraft.yaml.template @@ -0,0 +1,25 @@ +name: syncthing +version: {{.Version}} +summary: Open Source Continuous File Synchronization +description: | + Syncthing replaces proprietary sync and cloud services with something open, + trustworthy and decentralized. Your data is your data alone and you deserve + to choose where it is stored, if it is shared with some third party and how + it's transmitted over the Internet. + +grade: devel +confinement: strict + +apps: + syncthing: + command: syncthing + plugs: [home, network, network-bind] + +parts: + syncthing: + source: . + plugin: dump + stage: + - syncthing + snap: + - syncthing