forked from vikunja/vikunja
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// +build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/magefile/mage/mg"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
PACKAGE = `code.vikunja.io/api`
|
|
EXECUTABLE = `vikunja`
|
|
)
|
|
|
|
var (
|
|
Goflags = []string{
|
|
"-v",
|
|
}
|
|
Ldflags = ""
|
|
Tags = ""
|
|
Version = "dev"
|
|
)
|
|
|
|
func setVersion() {
|
|
versionCmd := exec.Command("git", "describe", "--tags", "--always", "--abbrev=10")
|
|
version, err := versionCmd.Output()
|
|
if err != nil {
|
|
fmt.Printf("Error getting version: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
Version = strings.Trim(string(version), "\n")
|
|
Version = strings.Replace(Version, "-", "+", 1)
|
|
Version = strings.Replace(Version, "-g", "-", 1)
|
|
}
|
|
|
|
func init() {
|
|
Tags = os.Getenv("TAGS")
|
|
setVersion()
|
|
Ldflags = `-X "` + PACKAGE + `/pkg/version.Version=` + Version + `" -X "main.Tags=` + Tags + `"`
|
|
}
|
|
|
|
// Generates static content into the final binary
|
|
func Generate() error {
|
|
return exec.Command("go", "generate", PACKAGE+"/pkg/static").Run()
|
|
}
|
|
|
|
func Build() error {
|
|
mg.Deps(Generate)
|
|
out, err := exec.Command("go", "build", Goflags[0], "-tags", Tags, "-ldflags", "-s -w "+Ldflags, "-o", EXECUTABLE).CombinedOutput()
|
|
fmt.Print(string(out))
|
|
return err
|
|
}
|