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
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 {
// 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,