1
0
mirror of https://github.com/magefile/mage.git synced 2026-10-24 06:19:18 +03:00
Files
mage/parse/srcimporter/sizes.go
Nate Finch 8b6c4f7a9d fixes and a test (#15)
fixes #13 

The bug was that non-stdlib imports were failing to be found by the parser.

The problem is that the default importer only imports from compiled files.  But we specifically want to import from source files. For go 1.9 this is easy, go/importer has an importer.For that takes "source".  However, previous to go 1.9, this doesn't exist.  To keep the code working in previous versions, we just grab the code from 1.9's srcimporter and include it in the build, and then conditionally compile in that code if we're not running on go 1.9 or greater (if we are running on go 1.9, we can use the stdlib version, which is better because it'll get fixes etc automatically).

Also added a bunch of tests to ensure that this code won't break again without a test failing.
2017-09-29 09:38:37 -04:00

41 lines
955 B
Go

// +build !go1.9
package srcimporter
import "go/types"
// common architecture word sizes and alignments
var gcArchSizes = map[string]*types.StdSizes{
"386": {4, 4},
"arm": {4, 4},
"arm64": {8, 8},
"amd64": {8, 8},
"amd64p32": {4, 8},
"mips": {4, 4},
"mipsle": {4, 4},
"mips64": {8, 8},
"mips64le": {8, 8},
"ppc64": {8, 8},
"ppc64le": {8, 8},
"s390x": {8, 8},
// When adding more architectures here,
// update the doc string of SizesFor below.
}
// SizesFor returns the Sizes used by a compiler for an architecture.
// The result is nil if a compiler/architecture pair is not known.
//
// Supported architectures for compiler "gc":
// "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle",
// "mips64", "mips64le", "ppc64", "ppc64le", "s390x".
func SizesFor(compiler, arch string) types.Sizes {
if compiler != "gc" {
return nil
}
s, ok := gcArchSizes[arch]
if !ok {
return nil
}
return s
}