aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2015-07-31 15:07:44 -0400
committerRuss Cox <rsc@golang.org>2015-08-03 20:00:07 +0000
commitb3bf38e79d71784d98a79f2c2e3af003f48c8052 (patch)
tree9a565bb76f213a2292b8ab9ad8e86153b036e454
parent961f456a1dbf6c86c033f8c9205766d3bbf228a1 (diff)
downloadgo-b3bf38e79d71784d98a79f2c2e3af003f48c8052.tar.gz
go-b3bf38e79d71784d98a79f2c2e3af003f48c8052.zip
cmd/go: clean up installHeader action
This was confusing when I was trying to fix go build -o. Perhaps due to that fix, this can now be simplified from three functions to one. Change-Id: I878a6d243b14132a631e7c62a3bb6d101bc243ea Reviewed-on: https://go-review.googlesource.com/13027 Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/cmd/go/build.go67
1 files changed, 16 insertions, 51 deletions
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index b876c51ecf..718edd2f77 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -909,7 +909,19 @@ func (b *builder) action1(mode buildMode, depMode buildMode, p *Package, looksha
a.f = (*builder).install
a.deps = []*action{b.action1(modeBuild, depMode, p, lookshared)}
a.target = a.p.target
- a = b.maybeAddHeaderAction(a, true)
+
+ // Install header for cgo in c-archive and c-shared modes.
+ if p.usesCgo() && (buildBuildmode == "c-archive" || buildBuildmode == "c-shared") {
+ ah := &action{
+ p: a.p,
+ deps: []*action{a.deps[0]},
+ f: (*builder).installHeader,
+ pkgdir: a.pkgdir,
+ objdir: a.objdir,
+ target: a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h",
+ }
+ a.deps = append(a.deps, ah)
+ }
case modeBuild:
a.f = (*builder).build
@@ -1034,49 +1046,6 @@ func (b *builder) libaction(libname string, pkgs []*Package, mode, depMode build
return a
}
-// In c-archive/c-shared mode, if the package for the action uses cgo,
-// add a dependency to install the generated export header file, if
-// there is one.
-// The isInstall parameter is whether a is an install action.
-func (b *builder) maybeAddHeaderAction(a *action, isInstall bool) *action {
- switch buildBuildmode {
- case "c-archive", "c-shared":
- default:
- return a
- }
- if !a.p.usesCgo() {
- return a
- }
-
- if isInstall {
- // For an install action, change the action function.
- // We can't add an action after the install action,
- // because it deletes the working directory.
- // Adding an action before the install action is painful,
- // because it uses deps[0] to find the source.
- a.f = (*builder).installWithHeader
- return a
- }
-
- return &action{
- p: a.p,
- deps: []*action{a},
- f: (*builder).installHeader,
- pkgdir: a.pkgdir,
- objdir: a.objdir,
- target: a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h",
- }
-}
-
-// Install the library and the cgo export header if there is one.
-func (b *builder) installWithHeader(a *action) error {
- target := a.target[:len(a.target)-len(filepath.Ext(a.target))] + ".h"
- if err := b.doInstallHeader(a, a.objdir, target); err != nil {
- return err
- }
- return b.install(a)
-}
-
// actionList returns the list of actions in the dag rooted at root
// as visited in a depth-first post-order traversal.
func actionList(root *action) []*action {
@@ -1692,25 +1661,21 @@ func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode, force b
// Install the cgo export header file, if there is one.
func (b *builder) installHeader(a *action) error {
- return b.doInstallHeader(a, a.objdir, a.target)
-}
-
-func (b *builder) doInstallHeader(a *action, objdir, target string) error {
- src := objdir + "_cgo_install.h"
+ src := a.objdir + "_cgo_install.h"
if _, err := os.Stat(src); os.IsNotExist(err) {
// If the file does not exist, there are no exported
// functions, and we do not install anything.
return nil
}
- dir, _ := filepath.Split(target)
+ dir, _ := filepath.Split(a.target)
if dir != "" {
if err := b.mkdir(dir); err != nil {
return err
}
}
- return b.moveOrCopyFile(a, target, src, 0644, true)
+ return b.moveOrCopyFile(a, a.target, src, 0644, true)
}
// cover runs, in effect,