github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/imports/build.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Copied from Go distribution src/go/build/build.go, syslist.go. 6 // That package does not export the ability to process raw file data, 7 // although we could fake it with an appropriate build.Context 8 // and a lot of unwrapping. 9 // More importantly, that package does not implement the tags["*"] 10 // special case, in which both tag and !tag are considered to be true 11 // for essentially all tags (except "ignore"). 12 // 13 // If we added this API to go/build directly, we wouldn't need this 14 // file anymore, but this API is not terribly general-purpose and we 15 // don't really want to commit to any public form of it, nor do we 16 // want to move the core parts of go/build into a top-level internal package. 17 // These details change very infrequently, so the copy is fine. 18 19 package imports 20 21 import ( 22 "github.com/shogo82148/std/go/build/constraint" 23 ) 24 25 // ShouldBuild reports whether it is okay to use this file, 26 // The rule is that in the file's leading run of // comments 27 // and blank lines, which must be followed by a blank line 28 // (to avoid including a Go package clause doc comment), 29 // lines beginning with '// +build' are taken as build directives. 30 // 31 // The file is accepted only if each such line lists something 32 // matching the file. For example: 33 // 34 // // +build windows linux 35 // 36 // marks the file as applicable only on Windows and Linux. 37 // 38 // If tags["*"] is true, then ShouldBuild will consider every 39 // build tag except "ignore" to be both true and false for 40 // the purpose of satisfying build tags, in order to estimate 41 // (conservatively) whether a file could ever possibly be used 42 // in any build. 43 func ShouldBuild(content []byte, tags map[string]bool) bool 44 45 // Eval is like 46 // 47 // x.Eval(func(tag string) bool { return matchTag(tag, tags) }) 48 // 49 // except that it implements the special case for tags["*"] meaning 50 // all tags are both true and false at the same time. 51 func Eval(x constraint.Expr, tags map[string]bool, prefer bool) bool 52 53 // MatchFile returns false if the name contains a $GOOS or $GOARCH 54 // suffix which does not match the current system. 55 // The recognized name formats are: 56 // 57 // name_$(GOOS).* 58 // name_$(GOARCH).* 59 // name_$(GOOS)_$(GOARCH).* 60 // name_$(GOOS)_test.* 61 // name_$(GOARCH)_test.* 62 // name_$(GOOS)_$(GOARCH)_test.* 63 // 64 // Exceptions: 65 // 66 // if GOOS=android, then files with GOOS=linux are also matched. 67 // if GOOS=illumos, then files with GOOS=solaris are also matched. 68 // if GOOS=ios, then files with GOOS=darwin are also matched. 69 // 70 // If tags["*"] is true, then MatchFile will consider all possible 71 // GOOS and GOARCH to be available and will consequently 72 // always return true. 73 func MatchFile(name string, tags map[string]bool) bool 74 75 var KnownOS = map[string]bool{ 76 "aix": true, 77 "android": true, 78 "darwin": true, 79 "dragonfly": true, 80 "freebsd": true, 81 "hurd": true, 82 "illumos": true, 83 "ios": true, 84 "js": true, 85 "linux": true, 86 "nacl": true, 87 "netbsd": true, 88 "openbsd": true, 89 "plan9": true, 90 "solaris": true, 91 "wasip1": true, 92 "windows": true, 93 "zos": true, 94 } 95 96 var KnownArch = map[string]bool{ 97 "386": true, 98 "amd64": true, 99 "amd64p32": true, 100 "arm": true, 101 "armbe": true, 102 "arm64": true, 103 "arm64be": true, 104 "ppc64": true, 105 "ppc64le": true, 106 "mips": true, 107 "mipsle": true, 108 "mips64": true, 109 "mips64le": true, 110 "mips64p32": true, 111 "mips64p32le": true, 112 "loong64": true, 113 "ppc": true, 114 "riscv": true, 115 "riscv64": true, 116 "s390": true, 117 "s390x": true, 118 "sparc": true, 119 "sparc64": true, 120 "wasm": true, 121 }