From b0996334c1cd2c14e07fb4f17c924cdf698ae48d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 7 Mar 2012 22:03:18 -0500 Subject: [PATCH] go/build, cmd/go: add support for .syso files .syso files are system objects copied directly into the package archive. Fixes #1552. R=alex.brainman, iant, r, minux.ma, remyoudompheng CC=golang-dev https://golang.org/cl/5778043 --- src/cmd/go/build.go | 5 +++++ src/cmd/go/list.go | 11 ++++++----- src/cmd/go/pkg.go | 14 ++++++++------ src/pkg/go/build/build.go | 18 ++++++++++++------ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index fad353f1e7..0b51a22d4f 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -727,6 +727,11 @@ func (b *builder) build(a *action) error { // http://golang.org/issue/2601 objects = append(objects, cgoObjects...) + // Add system object files. + for _, syso := range a.p.SysoFiles { + objects = append(objects, filepath.Join(a.p.Dir, syso)) + } + // Pack into archive in obj directory if err := buildToolchain.pack(b, a.p, obj, a.objpkg, objects); err != nil { return err diff --git a/src/cmd/go/list.go b/src/cmd/go/list.go index 446e2304be..edb59aa792 100644 --- a/src/cmd/go/list.go +++ b/src/cmd/go/list.go @@ -41,11 +41,12 @@ being passed to the template is: Root string // Go root or Go path dir containing this package // Source files - GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) - CgoFiles []string // .go sources files that import "C" - CFiles []string // .c source files - HFiles []string // .h source files - SFiles []string // .s source files + GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) + CgoFiles []string // .go sources files that import "C" + CFiles []string // .c source files + HFiles []string // .h source files + SFiles []string // .s source files + SysoFiles []string // .syso object files to add to archive // Cgo directives CgoCFLAGS []string // cgo: flags for C compiler diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index 09d84e5f27..9bdd56240b 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -35,11 +35,12 @@ type Package struct { Root string `json:",omitempty"` // Go root or Go path dir containing this package // Source files - GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) - CgoFiles []string `json:",omitempty"` // .go sources files that import "C" - CFiles []string `json:",omitempty"` // .c source files - HFiles []string `json:",omitempty"` // .h source files - SFiles []string `json:",omitempty"` // .s source files + GoFiles []string `json:",omitempty"` // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) + CgoFiles []string `json:",omitempty"` // .go sources files that import "C" + CFiles []string `json:",omitempty"` // .c source files + HFiles []string `json:",omitempty"` // .h source files + SFiles []string `json:",omitempty"` // .s source files + SysoFiles []string `json:",omitempty"` // .syso system object files added to package // Cgo directives CgoCFLAGS []string `json:",omitempty"` // cgo: flags for C compiler @@ -90,6 +91,7 @@ func (p *Package) copyBuild(pp *build.Package) { p.CFiles = pp.CFiles p.HFiles = pp.HFiles p.SFiles = pp.SFiles + p.SysoFiles = pp.SysoFiles p.CgoCFLAGS = pp.CgoCFLAGS p.CgoLDFLAGS = pp.CgoLDFLAGS p.CgoPkgConfig = pp.CgoPkgConfig @@ -487,7 +489,7 @@ func isStale(p *Package, topRoot map[string]bool) bool { return false } - srcs := stringList(p.GoFiles, p.CFiles, p.HFiles, p.SFiles, p.CgoFiles) + srcs := stringList(p.GoFiles, p.CFiles, p.HFiles, p.SFiles, p.CgoFiles, p.SysoFiles) for _, src := range srcs { if olderThan(filepath.Join(p.Dir, src)) { return true diff --git a/src/pkg/go/build/build.go b/src/pkg/go/build/build.go index 7f7bd18547..9a04c4636c 100644 --- a/src/pkg/go/build/build.go +++ b/src/pkg/go/build/build.go @@ -279,11 +279,12 @@ type Package struct { PkgObj string // installed .a file // Source files - GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) - CgoFiles []string // .go source files that import "C" - CFiles []string // .c source files - HFiles []string // .h source files - SFiles []string // .s source files + GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) + CgoFiles []string // .go source files that import "C" + CFiles []string // .c source files + HFiles []string // .h source files + SFiles []string // .s source files + SysoFiles []string // .syso system object files to add to archive // Cgo directives CgoPkgConfig []string // Cgo pkg-config directives @@ -476,7 +477,12 @@ Found: ext := name[i:] switch ext { case ".go", ".c", ".s", ".h", ".S": - // tentatively okay + // tentatively okay - read to make sure + case ".syso": + // binary objects to add to package archive + // Likely of the form foo_windows.syso, but + // the name was vetted above with goodOSArchFile. + p.SysoFiles = append(p.SysoFiles, name) default: // skip continue