mirror of
https://github.com/magefile/mage.git
synced 2026-10-24 06:19:18 +03:00
move checkdupes into parse (#138)
by putting checkdeps into parse, it gets checked by the parse tests and it just a cleaner place to put it.
This commit is contained in:
29
mage/main.go
29
mage/main.go
@@ -293,17 +293,6 @@ func Invoke(inv Invocation) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
hasDupes, names := CheckDupes(info)
|
||||
if hasDupes {
|
||||
log.Println("Build targets must be case insensitive, thus the follow targets conflict:")
|
||||
for _, v := range names {
|
||||
if len(v) > 1 {
|
||||
log.Println(" " + strings.Join(v, ", "))
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
main := filepath.Join(inv.Dir, mainfile)
|
||||
if err := GenerateMainfile(main, info); err != nil {
|
||||
log.Println("Error:", err)
|
||||
@@ -331,24 +320,6 @@ func Invoke(inv Invocation) int {
|
||||
return RunCompiled(inv, exePath)
|
||||
}
|
||||
|
||||
// CheckDupes checks a package for duplicate target names.
|
||||
func CheckDupes(info *parse.PkgInfo) (hasDupes bool, names map[string][]string) {
|
||||
names = map[string][]string{}
|
||||
lowers := map[string]bool{}
|
||||
for _, f := range info.Funcs {
|
||||
low := strings.ToLower(f.Name)
|
||||
if f.Receiver != "" {
|
||||
low = strings.ToLower(f.Receiver) + ":" + low
|
||||
}
|
||||
if lowers[low] {
|
||||
hasDupes = true
|
||||
}
|
||||
lowers[low] = true
|
||||
names[low] = append(names[low], f.Name)
|
||||
}
|
||||
return hasDupes, names
|
||||
}
|
||||
|
||||
type data struct {
|
||||
Description string
|
||||
Funcs []parse.Function
|
||||
|
||||
@@ -119,7 +119,10 @@ func checkFns(fns []interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// Deps runs the given functions with the default runtime context
|
||||
// Deps runs the given functions in parallel, exactly once. This is a way to
|
||||
// build up a tree of dependencies with each dependency defining its own
|
||||
// dependencies. Functions must have the same signature as a Mage target, i.e.
|
||||
// optional context argument, optional error return.
|
||||
func Deps(fns ...interface{}) {
|
||||
CtxDeps(context.Background(), fns...)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
@@ -16,6 +17,8 @@ import (
|
||||
mgTypes "github.com/magefile/mage/types"
|
||||
)
|
||||
|
||||
// PkgInfo contains inforamtion about a package of files according to mage's
|
||||
// parsing rules.
|
||||
type PkgInfo struct {
|
||||
Description string
|
||||
Funcs []Function
|
||||
@@ -156,12 +159,41 @@ typeloop:
|
||||
}
|
||||
}
|
||||
|
||||
hasDupes, names := checkDupes(pi)
|
||||
if hasDupes {
|
||||
msg := "Build targets must be case insensitive, thus the following targets conflict:\n"
|
||||
for _, v := range names {
|
||||
if len(v) > 1 {
|
||||
msg += " " + strings.Join(v, ", ") + "\n"
|
||||
}
|
||||
}
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
|
||||
setDefault(p, pi, info)
|
||||
setAliases(p, pi, info)
|
||||
|
||||
return pi, nil
|
||||
}
|
||||
|
||||
// checkDupes checks a package for duplicate target names.
|
||||
func checkDupes(info *PkgInfo) (hasDupes bool, names map[string][]string) {
|
||||
names = map[string][]string{}
|
||||
lowers := map[string]bool{}
|
||||
for _, f := range info.Funcs {
|
||||
low := strings.ToLower(f.Name)
|
||||
if f.Receiver != "" {
|
||||
low = strings.ToLower(f.Receiver) + ":" + low
|
||||
}
|
||||
if lowers[low] {
|
||||
hasDupes = true
|
||||
}
|
||||
lowers[low] = true
|
||||
names[low] = append(names[low], f.Name)
|
||||
}
|
||||
return hasDupes, names
|
||||
}
|
||||
|
||||
// sanitizeSynopsis sanitizes function Doc to create a summary.
|
||||
func sanitizeSynopsis(f *doc.Func) string {
|
||||
synopsis := doc.Synopsis(f.Doc)
|
||||
|
||||
Reference in New Issue
Block a user