1 Star 3 Fork 1

GNUOS/dragonfly

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
magefile.go 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
GNUOS 提交于 2018-05-03 10:51 +08:00 . 初始化项目
// +build mage
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
"github.com/magefile/mage/sh"
)
const packageName = "dragonfly"
var goexe = "go"
func init() {
if exe := os.Getenv("GOEXE"); exe != "" {
goexe = exe
}
}
func flagEnv() map[string]string {
return map[string]string{
"HTTP_PROXY": "192.168.80.1:1080",
"HTTPS_PROXY": "192.168.80.1:1080",
}
}
func getDep() error {
return sh.Run(goexe, "get", "-u", "github.com/golang/dep/cmd/dep")
}
// Build dragonfly binary
func Build() error {
mg.Deps(Vendor)
fmt.Println("Building...")
cmd := exec.Command("go", "build", "-o", "dragonfly", ".")
return cmd.Run()
}
// Install dragonfly product
func Install() error {
mg.Deps(Build)
fmt.Println("Installing...")
return os.Rename("./dragonfly", "/usr/local/bin/dragonfly")
}
// Install Go Dep and sync vendored dependencies
func Vendor() error {
mg.Deps(getDep)
fmt.Println("Installing Deps...")
return sh.RunWith(flagEnv(), "dep", "ensure", "-v", "-update")
}
// Remove built product
func Clean() {
fmt.Println("Cleaning...")
cmd := exec.Command("go", "clean", "./...")
cmd.Run()
}
// Run gofmt linter
func Fmt() error {
if !isGoLatest() {
return nil
}
pkgs, err := dragonflyPkgs()
if err != nil {
return err
}
failed := false
first := true
for _, pkg := range pkgs {
files, err := filepath.Glob(filepath.Join(pkg, "*.go"))
if err != nil {
return nil
}
for _, f := range files {
// gofmt doesn't exit with non-zero when it finds unformatted code
// so we have to explicitly look for output, and if we find any, we
// should fail this target.
s, err := sh.Output("gofmt", "-l", f)
if err != nil {
fmt.Printf("ERROR: running gofmt on %q: %v\n", f, err)
failed = true
}
if s != "" {
if first {
fmt.Println("The following files are not gofmt'ed:")
first = false
}
failed = true
fmt.Println(s)
}
}
}
if failed {
return errors.New("improperly formatted go files")
}
return nil
}
func dragonflyPkgs() ([]string, error) {
mg.Deps(getDep)
s, err := sh.Output(goexe, "list", "./...")
if err != nil {
return nil, err
}
pkgs := strings.Split(s, "\n")
pkgPrefixLen := len(packageName)
for i := range pkgs {
pkgs[i] = "." + pkgs[i][pkgPrefixLen:]
}
return pkgs, nil
}
func isGoLatest() bool {
return strings.Contains(runtime.Version(), "1.10")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/gnuos/dragonfly.git
git@gitee.com:gnuos/dragonfly.git
gnuos
dragonfly
dragonfly
master

搜索帮助