OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package build | 5 package build |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 // Line is | 870 // Line is |
871 // #cgo [GOOS/GOARCH...] LDFLAGS: stuff | 871 // #cgo [GOOS/GOARCH...] LDFLAGS: stuff |
872 // | 872 // |
873 line = strings.TrimSpace(line) | 873 line = strings.TrimSpace(line) |
874 if len(line) < 5 || line[:4] != "#cgo" || (line[4] != ' ' && lin
e[4] != '\t') { | 874 if len(line) < 5 || line[:4] != "#cgo" || (line[4] != ' ' && lin
e[4] != '\t') { |
875 continue | 875 continue |
876 } | 876 } |
877 | 877 |
878 // Split at colon. | 878 // Split at colon. |
879 line = strings.TrimSpace(line[4:]) | 879 line = strings.TrimSpace(line[4:]) |
880 » » i := strings.IndexByte(line, ':') | 880 » » i := strings.Index(line, ":") |
881 if i < 0 { | 881 if i < 0 { |
882 return fmt.Errorf("%s: invalid #cgo line: %s", filename,
orig) | 882 return fmt.Errorf("%s: invalid #cgo line: %s", filename,
orig) |
883 } | 883 } |
884 line, argstr := line[:i], line[i+1:] | 884 line, argstr := line[:i], line[i+1:] |
885 | 885 |
886 // Parse GOOS/GOARCH stuff. | 886 // Parse GOOS/GOARCH stuff. |
887 f := strings.Fields(line) | 887 f := strings.Fields(line) |
888 if len(f) < 1 { | 888 if len(f) < 1 { |
889 return fmt.Errorf("%s: invalid #cgo line: %s", filename,
orig) | 889 return fmt.Errorf("%s: invalid #cgo line: %s", filename,
orig) |
890 } | 890 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 // ctxt.Compiler | 1015 // ctxt.Compiler |
1016 // !ctxt.Compiler | 1016 // !ctxt.Compiler |
1017 // tag (if tag is listed in ctxt.BuildTags or ctxt.ReleaseTags) | 1017 // tag (if tag is listed in ctxt.BuildTags or ctxt.ReleaseTags) |
1018 // !tag (if tag is not listed in ctxt.BuildTags or ctxt.ReleaseTags) | 1018 // !tag (if tag is not listed in ctxt.BuildTags or ctxt.ReleaseTags) |
1019 // a comma-separated list of any of these | 1019 // a comma-separated list of any of these |
1020 // | 1020 // |
1021 func (ctxt *Context) match(name string) bool { | 1021 func (ctxt *Context) match(name string) bool { |
1022 if name == "" { | 1022 if name == "" { |
1023 return false | 1023 return false |
1024 } | 1024 } |
1025 » if i := strings.IndexByte(name, ','); i >= 0 { | 1025 » if i := strings.Index(name, ","); i >= 0 { |
1026 // comma-separated list | 1026 // comma-separated list |
1027 return ctxt.match(name[:i]) && ctxt.match(name[i+1:]) | 1027 return ctxt.match(name[:i]) && ctxt.match(name[i+1:]) |
1028 } | 1028 } |
1029 if strings.HasPrefix(name, "!!") { // bad syntax, reject always | 1029 if strings.HasPrefix(name, "!!") { // bad syntax, reject always |
1030 return false | 1030 return false |
1031 } | 1031 } |
1032 if strings.HasPrefix(name, "!") { // negation | 1032 if strings.HasPrefix(name, "!") { // negation |
1033 return len(name) > 1 && !ctxt.match(name[1:]) | 1033 return len(name) > 1 && !ctxt.match(name[1:]) |
1034 } | 1034 } |
1035 | 1035 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 // The recognized name formats are: | 1069 // The recognized name formats are: |
1070 // | 1070 // |
1071 // name_$(GOOS).* | 1071 // name_$(GOOS).* |
1072 // name_$(GOARCH).* | 1072 // name_$(GOARCH).* |
1073 // name_$(GOOS)_$(GOARCH).* | 1073 // name_$(GOOS)_$(GOARCH).* |
1074 // name_$(GOOS)_test.* | 1074 // name_$(GOOS)_test.* |
1075 // name_$(GOARCH)_test.* | 1075 // name_$(GOARCH)_test.* |
1076 // name_$(GOOS)_$(GOARCH)_test.* | 1076 // name_$(GOOS)_$(GOARCH)_test.* |
1077 // | 1077 // |
1078 func (ctxt *Context) goodOSArchFile(name string) bool { | 1078 func (ctxt *Context) goodOSArchFile(name string) bool { |
1079 » if dot := strings.IndexByte(name, '.'); dot != -1 { | 1079 » if dot := strings.Index(name, "."); dot != -1 { |
1080 name = name[:dot] | 1080 name = name[:dot] |
1081 } | 1081 } |
1082 l := strings.Split(name, "_") | 1082 l := strings.Split(name, "_") |
1083 if n := len(l); n > 0 && l[n-1] == "test" { | 1083 if n := len(l); n > 0 && l[n-1] == "test" { |
1084 l = l[:n-1] | 1084 l = l[:n-1] |
1085 } | 1085 } |
1086 n := len(l) | 1086 n := len(l) |
1087 if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] { | 1087 if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] { |
1088 return l[n-2] == ctxt.GOOS && l[n-1] == ctxt.GOARCH | 1088 return l[n-2] == ctxt.GOOS && l[n-1] == ctxt.GOARCH |
1089 } | 1089 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 switch goarch { | 1124 switch goarch { |
1125 case "386": | 1125 case "386": |
1126 return "8", nil | 1126 return "8", nil |
1127 case "amd64": | 1127 case "amd64": |
1128 return "6", nil | 1128 return "6", nil |
1129 case "arm": | 1129 case "arm": |
1130 return "5", nil | 1130 return "5", nil |
1131 } | 1131 } |
1132 return "", errors.New("unsupported GOARCH " + goarch) | 1132 return "", errors.New("unsupported GOARCH " + goarch) |
1133 } | 1133 } |
OLD | NEW |