mirror of
https://github.com/golang/go
synced 2024-10-04 23:21:20 -06:00
cmd/go: force-overwrite destination files when installing cgo headers
Fixes #11131 When running 'go install -buildmode=c-shared', under the circumstances described in issue #11131, the install command would fail trying to install cgo headers if they have already been installed (by a previous call to 'go install -buildmode=c-shared'). Since it's safe to overwrite said headers (according to iant@), this CL introduces a parameter to builder's 'copy' and 'move' functions that, if set to 'true', would force the overwriting of already installed files. This parameter value is set to 'true' only when installing cgo headers, for now. Change-Id: I5bda17ee757066a8e5d2b39f2e8f3a389eb1e4a2 Reviewed-on: https://go-review.googlesource.com/10870 Run-TryBot: Srdjan Petrovic <spetrovic@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
1f9026c0bd
commit
85b333dbf8
@ -1368,17 +1368,17 @@ func (b *builder) build(a *action) (err error) {
|
|||||||
switch {
|
switch {
|
||||||
case strings.HasSuffix(name, _goos_goarch):
|
case strings.HasSuffix(name, _goos_goarch):
|
||||||
targ := file[:len(name)-len(_goos_goarch)] + "_GOOS_GOARCH." + ext
|
targ := file[:len(name)-len(_goos_goarch)] + "_GOOS_GOARCH." + ext
|
||||||
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644); err != nil {
|
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case strings.HasSuffix(name, _goarch):
|
case strings.HasSuffix(name, _goarch):
|
||||||
targ := file[:len(name)-len(_goarch)] + "_GOARCH." + ext
|
targ := file[:len(name)-len(_goarch)] + "_GOARCH." + ext
|
||||||
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644); err != nil {
|
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case strings.HasSuffix(name, _goos):
|
case strings.HasSuffix(name, _goos):
|
||||||
targ := file[:len(name)-len(_goos)] + "_GOOS." + ext
|
targ := file[:len(name)-len(_goos)] + "_GOOS." + ext
|
||||||
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644); err != nil {
|
if err := b.copyFile(a, obj+targ, filepath.Join(a.p.Dir, file), 0644, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1575,7 +1575,7 @@ func (b *builder) install(a *action) (err error) {
|
|||||||
defer os.Remove(a1.target)
|
defer os.Remove(a1.target)
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.moveOrCopyFile(a, a.target, a1.target, perm)
|
return b.moveOrCopyFile(a, a.target, a1.target, perm, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// includeArgs returns the -I or -L directory list for access
|
// includeArgs returns the -I or -L directory list for access
|
||||||
@ -1620,7 +1620,7 @@ func (b *builder) includeArgs(flag string, all []*action) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// moveOrCopyFile is like 'mv src dst' or 'cp src dst'.
|
// moveOrCopyFile is like 'mv src dst' or 'cp src dst'.
|
||||||
func (b *builder) moveOrCopyFile(a *action, dst, src string, perm os.FileMode) error {
|
func (b *builder) moveOrCopyFile(a *action, dst, src string, perm os.FileMode, force bool) error {
|
||||||
if buildN {
|
if buildN {
|
||||||
b.showcmd("", "mv %s %s", src, dst)
|
b.showcmd("", "mv %s %s", src, dst)
|
||||||
return nil
|
return nil
|
||||||
@ -1637,11 +1637,11 @@ func (b *builder) moveOrCopyFile(a *action, dst, src string, perm os.FileMode) e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.copyFile(a, dst, src, perm)
|
return b.copyFile(a, dst, src, perm, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyFile is like 'cp src dst'.
|
// copyFile is like 'cp src dst'.
|
||||||
func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode) error {
|
func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode, force bool) error {
|
||||||
if buildN || buildX {
|
if buildN || buildX {
|
||||||
b.showcmd("", "cp %s %s", src, dst)
|
b.showcmd("", "cp %s %s", src, dst)
|
||||||
if buildN {
|
if buildN {
|
||||||
@ -1662,7 +1662,7 @@ func (b *builder) copyFile(a *action, dst, src string, perm os.FileMode) error {
|
|||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
return fmt.Errorf("build output %q already exists and is a directory", dst)
|
return fmt.Errorf("build output %q already exists and is a directory", dst)
|
||||||
}
|
}
|
||||||
if !isObject(dst) {
|
if !force && !isObject(dst) {
|
||||||
return fmt.Errorf("build output %q already exists and is not an object file", dst)
|
return fmt.Errorf("build output %q already exists and is not an object file", dst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1719,7 +1719,7 @@ func (b *builder) doInstallHeader(a *action, objdir, target string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.moveOrCopyFile(a, target, src, 0644)
|
return b.moveOrCopyFile(a, target, src, 0644, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cover runs, in effect,
|
// cover runs, in effect,
|
||||||
|
Loading…
Reference in New Issue
Block a user