main: add build tags for the Go stdlib version
Этот коммит содержится в:
родитель
7156afca9e
коммит
7e6a54ac62
2 изменённых файлов: 37 добавлений и 1 удалений
13
main.go
13
main.go
|
@ -80,6 +80,17 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
|
|||
if goroot == "" {
|
||||
return errors.New("cannot locate $GOROOT, please set it manually")
|
||||
}
|
||||
tags := spec.BuildTags
|
||||
major, minor := getGorootVersion(goroot)
|
||||
if major != 1 {
|
||||
if major == 0 {
|
||||
return errors.New("could not read version from GOROOT: " + goroot)
|
||||
}
|
||||
return fmt.Errorf("expected major version 1, got go%d.%d", major, minor)
|
||||
}
|
||||
for i := 1; i <= minor; i++ {
|
||||
tags = append(tags, fmt.Sprintf("go1.%d", i))
|
||||
}
|
||||
compilerConfig := compiler.Config{
|
||||
Triple: spec.Triple,
|
||||
CPU: spec.CPU,
|
||||
|
@ -94,7 +105,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
|
|||
TINYGOROOT: root,
|
||||
GOROOT: goroot,
|
||||
GOPATH: getGopath(),
|
||||
BuildTags: spec.BuildTags,
|
||||
BuildTags: tags,
|
||||
}
|
||||
c, err := compiler.NewCompiler(pkgName, compilerConfig)
|
||||
if err != nil {
|
||||
|
|
25
target.go
25
target.go
|
@ -5,11 +5,13 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -368,3 +370,26 @@ func isGoroot(goroot string) bool {
|
|||
_, err := os.Stat(filepath.Join(goroot, "src", "runtime", "internal", "sys", "zversion.go"))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// getGorootVersion returns the major and minor version for a given GOROOT path.
|
||||
// If the goroot cannot be determined, (0, 0) is returned.
|
||||
func getGorootVersion(goroot string) (major, minor int) {
|
||||
data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s := string(data)
|
||||
if s[:2] != "go" {
|
||||
return
|
||||
}
|
||||
parts := strings.Split(s[2:], ".")
|
||||
if len(parts) < 2 {
|
||||
return
|
||||
}
|
||||
|
||||
// Ignore the errors, strconv.Atoi will return 0 on most errors and we
|
||||
// don't really handle errors here anyway.
|
||||
major, _ = strconv.Atoi(parts[0])
|
||||
minor, _ = strconv.Atoi(parts[1])
|
||||
return
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче