Commit 69397422 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/compile: by default accept any language

The bootstrap stage 1 compiler was defaulting to the language version
used by the bootstrap compiler itself, typically 1.4. Normally this
doesn't matter since the bootstrap code has to build with 1.4 anyhow,
but it broke the boringcrypto branch which uses cgo during the
bootstrap, as cgo now generates code that uses type aliases.

Change-Id: I8a8312bb9ca4befaf65c00a8d71a78566075c2f7
Reviewed-on: https://go-review.googlesource.com/c/149459
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarFilippo Valsorda <filippo@golang.org>
parent a3c70e28
...@@ -213,7 +213,7 @@ func Main(archInit func(*Arch)) { ...@@ -213,7 +213,7 @@ func Main(archInit func(*Arch)) {
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`") flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
objabi.Flagcount("j", "debug runtime-initialized variables", &Debug['j']) objabi.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
objabi.Flagcount("l", "disable inlining", &Debug['l']) objabi.Flagcount("l", "disable inlining", &Debug['l'])
flag.StringVar(&flag_lang, "lang", defaultLang(), "release to compile for") flag.StringVar(&flag_lang, "lang", "", "release to compile for")
flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`") flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
objabi.Flagcount("live", "debug liveness analysis", &debuglive) objabi.Flagcount("live", "debug liveness analysis", &debuglive)
objabi.Flagcount("m", "print optimization decisions", &Debug['m']) objabi.Flagcount("m", "print optimization decisions", &Debug['m'])
...@@ -1407,8 +1407,8 @@ func recordFlags(flags ...string) { ...@@ -1407,8 +1407,8 @@ func recordFlags(flags ...string) {
// flag_lang is the language version we are compiling for, set by the -lang flag. // flag_lang is the language version we are compiling for, set by the -lang flag.
var flag_lang string var flag_lang string
// defaultLang returns the default value for the -lang flag. // currentLang returns the current language version.
func defaultLang() string { func currentLang() string {
tags := build.Default.ReleaseTags tags := build.Default.ReleaseTags
return tags[len(tags)-1] return tags[len(tags)-1]
} }
...@@ -1423,23 +1423,32 @@ type lang struct { ...@@ -1423,23 +1423,32 @@ type lang struct {
} }
// langWant is the desired language version set by the -lang flag. // langWant is the desired language version set by the -lang flag.
// If the -lang flag is not set, this is the zero value, meaning that
// any language version is supported.
var langWant lang var langWant lang
// langSupported reports whether language version major.minor is supported. // langSupported reports whether language version major.minor is supported.
func langSupported(major, minor int) bool { func langSupported(major, minor int) bool {
if langWant.major == 0 && langWant.minor == 0 {
return true
}
return langWant.major > major || (langWant.major == major && langWant.minor >= minor) return langWant.major > major || (langWant.major == major && langWant.minor >= minor)
} }
// checkLang verifies that the -lang flag holds a valid value, and // checkLang verifies that the -lang flag holds a valid value, and
// exits if not. It initializes data used by langSupported. // exits if not. It initializes data used by langSupported.
func checkLang() { func checkLang() {
if flag_lang == "" {
return
}
var err error var err error
langWant, err = parseLang(flag_lang) langWant, err = parseLang(flag_lang)
if err != nil { if err != nil {
log.Fatalf("invalid value %q for -lang: %v", flag_lang, err) log.Fatalf("invalid value %q for -lang: %v", flag_lang, err)
} }
if def := defaultLang(); flag_lang != def { if def := currentLang(); flag_lang != def {
defVers, err := parseLang(def) defVers, err := parseLang(def)
if err != nil { if err != nil {
log.Fatalf("internal error parsing default lang %q: %v", def, err) log.Fatalf("internal error parsing default lang %q: %v", def, err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment