-
Notifications
You must be signed in to change notification settings - Fork 9
/
target.go
98 lines (86 loc) · 2.47 KB
/
target.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 24 september 2014
package main
import (
"flag"
"runtime"
"os"
"path/filepath"
"strings"
"sort"
)
var targetOS = flag.String("os", runtime.GOOS, "select target OS; list for a list of supported OSs")
var targetArch = flag.String("arch", runtime.GOARCH, "select target architecture; list for a list of supported architectures")
func targetName() string {
pwd, err := os.Getwd()
if err != nil {
fail("Error getting current working directory to determine target name: %v", err)
}
target := filepath.Base(pwd)
if *targetOS == "windows" {
target += ".exe"
}
return target
}
var supportedOSs = strings.Fields("windows darwin linux freebsd openbsd netbsd dragonfly solaris")
var supportedArchs = strings.Fields("386 amd64")
var isNotUnix = map[string]bool{
"windows": true,
"plan9": true,
}
func init() {
sort.Strings(supportedOSs)
sort.Strings(supportedArchs)
}
var excludeSuffixes []string
var excludeFolders []string
var nounix = flag.Bool("nounix", false, "do not consider the current OS as a Unix system even if it would usually otherwise")
func computeExcludeSuffixes() {
for _, os := range supportedOSs {
if os == *targetOS {
continue
}
excludeSuffixes = append(excludeSuffixes, "_" + os)
excludeFolders = append(excludeFolders, os)
for _, arch := range supportedArchs {
excludeSuffixes = append(excludeSuffixes, "_" + os + "_" + arch)
excludeFolders = append(excludeFolders, os + "_" + arch)
}
}
for _, arch := range supportedArchs {
if arch == *targetArch {
continue
}
excludeSuffixes = append(excludeSuffixes, "_" + arch)
excludeFolders = append(excludeFolders, arch)
excludeSuffixes = append(excludeSuffixes, "_" + *targetOS + "_" + arch)
excludeFolders = append(excludeFolders, *targetOS + "_" + arch)
}
if *nounix || isNotUnix[*targetOS] {
excludeSuffixes = append(excludeSuffixes, "_unix")
excludeFolders = append(excludeFolders, "unix")
for _, arch := range supportedArchs {
excludeSuffixes = append(excludeSuffixes, "_unix_" + arch)
excludeFolders = append(excludeFolders, "unix_" + arch)
}
}
}
func excludeFile(filename string) bool {
base := filepath.Base(filename)
ext := filepath.Ext(base)
base = base[:len(base) - len(ext)]
for _, suffix := range excludeSuffixes {
if strings.HasSuffix(base, suffix) {
return true
}
}
return false
}
func excludeDir(filename string) bool {
base := filepath.Base(filename)
for _, exclude := range excludeFolders {
if base == exclude {
return true
}
}
return false
}