mirror of
https://github.com/golang/go
synced 2024-11-21 20:54:45 -07:00
goinstall: handle $(GOOS) and $(GOARCH) in filenames
This enables goinstall to handle .go and .c files (for cgo) which are named after the following patterns: name_$(GOOS).* name_$(GOARCH).* name_$(GOOS)_$(GOARCH).* Files with those names are only included if the $(GOOS) and $(GOARCH) match the current system. R=rsc CC=golang-dev https://golang.org/cl/4172055
This commit is contained in:
parent
f9ca3b5d5b
commit
70f08b47a0
@ -37,6 +37,7 @@ src/cmd/gc/opnames.h
|
|||||||
src/cmd/gc/y.output
|
src/cmd/gc/y.output
|
||||||
src/cmd/gc/y1.tab.c
|
src/cmd/gc/y1.tab.c
|
||||||
src/cmd/gc/yerr.h
|
src/cmd/gc/yerr.h
|
||||||
|
src/cmd/goinstall/syslist.go
|
||||||
src/pkg/Make.deps
|
src/pkg/Make.deps
|
||||||
src/pkg/exp/ogle/ogle
|
src/pkg/exp/ogle/ogle
|
||||||
src/pkg/os/signal/unix.go
|
src/pkg/os/signal/unix.go
|
||||||
|
35
src/Make.inc
35
src/Make.inc
@ -29,14 +29,20 @@ ifeq ($(GOOS),)
|
|||||||
GOOS:=$(GOHOSTOS)
|
GOOS:=$(GOHOSTOS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GOOS),darwin)
|
GOOS_LIST=\
|
||||||
else ifeq ($(GOOS),freebsd)
|
darwin\
|
||||||
else ifeq ($(GOOS),linux)
|
freebsd\
|
||||||
else ifeq ($(GOOS),tiny)
|
linux\
|
||||||
else ifeq ($(GOOS),plan9)
|
plan9\
|
||||||
else ifeq ($(GOOS),windows)
|
windows\
|
||||||
else
|
|
||||||
$(error Invalid $$GOOS '$(GOOS)'; must be darwin, freebsd, linux, plan9, tiny, or windows)
|
GOARCH_LIST=\
|
||||||
|
386\
|
||||||
|
amd64\
|
||||||
|
arm\
|
||||||
|
|
||||||
|
ifeq ($(filter $(GOOS),$(GOOS_LIST)),)
|
||||||
|
$(error Invalid $$GOOS '$(GOOS)'; must be one of: $(GOOS_LIST))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GOHOSTARCH),)
|
ifeq ($(GOHOSTARCH),)
|
||||||
@ -59,24 +65,25 @@ ifeq ($(GOOS),darwin)
|
|||||||
GOHOSTARCH:=$(GOARCH)
|
GOHOSTARCH:=$(GOARCH)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(filter $(GOARCH),$(GOARCH_LIST)),)
|
||||||
|
$(error Invalid $$GOARCH '$(GOARCH)'; must be one of: $(GOARCH_LIST))
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(GOARCH),386)
|
ifeq ($(GOARCH),386)
|
||||||
O:=8
|
O:=8
|
||||||
else ifeq ($(GOARCH),amd64)
|
else ifeq ($(GOARCH),amd64)
|
||||||
O:=6
|
O:=6
|
||||||
else ifeq ($(GOARCH),arm)
|
else ifeq ($(GOARCH),arm)
|
||||||
|
|
||||||
O:=5
|
O:=5
|
||||||
ifeq ($(GOOS),linux)
|
ifneq ($(GOOS),linux)
|
||||||
else
|
|
||||||
$(error Invalid $$GOOS '$(GOOS)' for GOARCH=arm; must be linux)
|
$(error Invalid $$GOOS '$(GOOS)' for GOARCH=arm; must be linux)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
else
|
else
|
||||||
$(error Invalid $$GOARCH '$(GOARCH)'; must be 386, amd64, or arm)
|
$(error Missing $$O for '$(GOARCH)')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Save for recursive make to avoid recomputing.
|
# Save for recursive make to avoid recomputing.
|
||||||
export GOARCH GOOS GOHOSTARCH GOHOSTOS
|
export GOARCH GOOS GOHOSTARCH GOHOSTOS GOARCH_LIST GOOS_LIST
|
||||||
|
|
||||||
# ugly hack to deal with whitespaces in $GOROOT
|
# ugly hack to deal with whitespaces in $GOROOT
|
||||||
nullstring :=
|
nullstring :=
|
||||||
|
@ -10,5 +10,17 @@ GOFILES=\
|
|||||||
main.go\
|
main.go\
|
||||||
make.go\
|
make.go\
|
||||||
parse.go\
|
parse.go\
|
||||||
|
syslist.go\
|
||||||
|
|
||||||
|
CLEANFILES+=syslist.go
|
||||||
|
|
||||||
include ../../Make.cmd
|
include ../../Make.cmd
|
||||||
|
|
||||||
|
syslist.go:
|
||||||
|
echo '// Generated automatically by make.' >$@
|
||||||
|
echo 'package main' >>$@
|
||||||
|
echo 'const goosList = "$(GOOS_LIST)"' >>$@
|
||||||
|
echo 'const goarchList = "$(GOARCH_LIST)"' >>$@
|
||||||
|
|
||||||
|
test:
|
||||||
|
gotest
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -57,6 +58,9 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) {
|
|||||||
if strings.HasPrefix(d.Name, "_") || strings.Index(d.Name, ".cgo") != -1 {
|
if strings.HasPrefix(d.Name, "_") || strings.Index(d.Name, ".cgo") != -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !goodOSArch(d.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if strings.HasSuffix(d.Name, ".c") {
|
if strings.HasSuffix(d.Name, ".c") {
|
||||||
cFiles = append(cFiles, d.Name)
|
cFiles = append(cFiles, d.Name)
|
||||||
continue
|
continue
|
||||||
@ -108,3 +112,47 @@ func scanDir(dir string, allowMain bool) (info *dirInfo, err os.Error) {
|
|||||||
}
|
}
|
||||||
return &dirInfo{goFiles, cgoFiles, cFiles, imports, pkgName}, nil
|
return &dirInfo{goFiles, cgoFiles, cFiles, imports, pkgName}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// goodOSArch returns false if the filename contains a $GOOS or $GOARCH
|
||||||
|
// suffix which does not match the current system.
|
||||||
|
// The recognized filename formats are:
|
||||||
|
//
|
||||||
|
// name_$(GOOS).*
|
||||||
|
// name_$(GOARCH).*
|
||||||
|
// name_$(GOOS)_$(GOARCH).*
|
||||||
|
//
|
||||||
|
func goodOSArch(filename string) bool {
|
||||||
|
if dot := strings.Index(filename, "."); dot != -1 {
|
||||||
|
filename = filename[:dot]
|
||||||
|
}
|
||||||
|
l := strings.Split(filename, "_", -1)
|
||||||
|
n := len(l)
|
||||||
|
if n == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if good, known := goodOS[l[n-1]]; known {
|
||||||
|
return good
|
||||||
|
}
|
||||||
|
if good, known := goodArch[l[n-1]]; known {
|
||||||
|
if !good || n < 2 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
good, known = goodOS[l[n-2]]
|
||||||
|
return good || !known
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var goodOS = make(map[string]bool)
|
||||||
|
var goodArch = make(map[string]bool)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
goodOS = make(map[string]bool)
|
||||||
|
goodArch = make(map[string]bool)
|
||||||
|
for _, v := range strings.Fields(goosList) {
|
||||||
|
goodOS[v] = v == runtime.GOOS
|
||||||
|
}
|
||||||
|
for _, v := range strings.Fields(goarchList) {
|
||||||
|
goodArch[v] = v == runtime.GOARCH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
56
src/cmd/goinstall/syslist_test.go
Normal file
56
src/cmd/goinstall/syslist_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
thisOS = runtime.GOOS
|
||||||
|
thisArch = runtime.GOARCH
|
||||||
|
otherOS = "freebsd"
|
||||||
|
otherArch = "arm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if thisOS == otherOS {
|
||||||
|
otherOS = "linux"
|
||||||
|
}
|
||||||
|
if thisArch == otherArch {
|
||||||
|
otherArch = "amd64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodFileTest struct {
|
||||||
|
name string
|
||||||
|
result bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var tests = []GoodFileTest{
|
||||||
|
{"file.go", true},
|
||||||
|
{"file.c", true},
|
||||||
|
{"file_foo.go", true},
|
||||||
|
{"file_" + thisArch + ".go", true},
|
||||||
|
{"file_" + otherArch + ".go", false},
|
||||||
|
{"file_" + thisOS + ".go", true},
|
||||||
|
{"file_" + otherOS + ".go", false},
|
||||||
|
{"file_" + thisOS + "_" + thisArch + ".go", true},
|
||||||
|
{"file_" + otherOS + "_" + thisArch + ".go", false},
|
||||||
|
{"file_" + thisOS + "_" + otherArch + ".go", false},
|
||||||
|
{"file_" + otherOS + "_" + otherArch + ".go", false},
|
||||||
|
{"file_foo_" + thisArch + ".go", true},
|
||||||
|
{"file_foo_" + otherArch + ".go", false},
|
||||||
|
{"file_" + thisOS + ".c", true},
|
||||||
|
{"file_" + otherOS + ".c", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodOSArch(t *testing.T) {
|
||||||
|
for _, test := range tests {
|
||||||
|
if goodOSArch(test.name) != test.result {
|
||||||
|
t.Fatalf("goodOSArch(%q) != %v", test.name, test.result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -189,7 +189,6 @@ NOTEST=\
|
|||||||
../cmd/ebnflint\
|
../cmd/ebnflint\
|
||||||
../cmd/godoc\
|
../cmd/godoc\
|
||||||
../cmd/gofmt\
|
../cmd/gofmt\
|
||||||
../cmd/goinstall\
|
|
||||||
../cmd/govet\
|
../cmd/govet\
|
||||||
../cmd/goyacc\
|
../cmd/goyacc\
|
||||||
../cmd/hgpatch\
|
../cmd/hgpatch\
|
||||||
|
Loading…
Reference in New Issue
Block a user