mirror of
https://github.com/golang/go
synced 2024-11-18 06:54:49 -07:00
cmd/dist: do not rewrite files that already have the correct content
In particular, this avoids moving the mtime on runtime/zversion.go forward unless the file is out of date. In turn, this makes cross compiles that run dist multiple times coexist nicely. (It's no longer necessary to run dist multiple times to set up cross compiles, but people still might, and it's easy to fix regardless.) Fixes #4749. Change-Id: Id430525f168f106bc4b821ca74b2ca498a748f14 Reviewed-on: https://go-review.googlesource.com/9152 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
85069e9e9b
commit
e346adf568
4
src/cmd/dist/build.go
vendored
4
src/cmd/dist/build.go
vendored
@ -809,11 +809,11 @@ func shouldbuild(file, dir string) bool {
|
||||
}
|
||||
|
||||
// copy copies the file src to dst, via memory (so only good for small files).
|
||||
func copyfile(dst, src string, exec int) {
|
||||
func copyfile(dst, src string, flag int) {
|
||||
if vflag > 1 {
|
||||
errprintf("cp %s %s\n", src, dst)
|
||||
}
|
||||
writefile(readfile(src), dst, exec)
|
||||
writefile(readfile(src), dst, flag)
|
||||
}
|
||||
|
||||
// dopack copies the package src to dst,
|
||||
|
4
src/cmd/dist/buildruntime.go
vendored
4
src/cmd/dist/buildruntime.go
vendored
@ -35,7 +35,7 @@ func mkzversion(dir, file string) {
|
||||
"const stackGuardMultiplier = %d\n"+
|
||||
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
|
||||
|
||||
writefile(out, file, 0)
|
||||
writefile(out, file, writeSkipSame)
|
||||
}
|
||||
|
||||
// mkzbootstrap writes cmd/internal/obj/zbootstrap.go:
|
||||
@ -80,7 +80,7 @@ func mkzbootstrap(file string) {
|
||||
"const goexperiment = `%s`\n",
|
||||
goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))
|
||||
|
||||
writefile(out, file, 0)
|
||||
writefile(out, file, writeSkipSame)
|
||||
}
|
||||
|
||||
// stackGuardMultiplier returns a multiplier to apply to the default
|
||||
|
2
src/cmd/dist/buildtool.go
vendored
2
src/cmd/dist/buildtool.go
vendored
@ -118,7 +118,7 @@ func bootstrapBuildTools() {
|
||||
// Copy binaries into tool binary directory.
|
||||
for _, name := range bootstrapDirs {
|
||||
if !strings.Contains(name, "/") {
|
||||
copyfile(pathf("%s/%s%s", tooldir, name, exe), pathf("%s/bin/%s%s", workspace, name, exe), 1)
|
||||
copyfile(pathf("%s/%s%s", tooldir, name, exe), pathf("%s/bin/%s%s", workspace, name, exe), writeExec)
|
||||
}
|
||||
}
|
||||
|
||||
|
25
src/cmd/dist/util.go
vendored
25
src/cmd/dist/util.go
vendored
@ -5,6 +5,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -245,14 +246,28 @@ func readfile(file string) string {
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// writefile writes b to the named file, creating it if needed. if
|
||||
// exec is non-zero, marks the file as executable.
|
||||
func writefile(b, file string, exec int) {
|
||||
const (
|
||||
writeExec = 1 << iota
|
||||
writeSkipSame
|
||||
)
|
||||
|
||||
// writefile writes b to the named file, creating it if needed.
|
||||
// if exec is non-zero, marks the file as executable.
|
||||
// If the file already exists and has the expected content,
|
||||
// it is not rewritten, to avoid changing the time stamp.
|
||||
func writefile(b, file string, flag int) {
|
||||
new := []byte(b)
|
||||
if flag&writeSkipSame != 0 {
|
||||
old, err := ioutil.ReadFile(file)
|
||||
if err == nil && bytes.Equal(old, new) {
|
||||
return
|
||||
}
|
||||
}
|
||||
mode := os.FileMode(0666)
|
||||
if exec != 0 {
|
||||
if flag&writeExec != 0 {
|
||||
mode = 0777
|
||||
}
|
||||
err := ioutil.WriteFile(file, []byte(b), mode)
|
||||
err := ioutil.WriteFile(file, new, mode)
|
||||
if err != nil {
|
||||
fatal("%v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user