autobuild compares the mod time of the source files of the package, and if any of them is newer than the package object file will rebuild it.
(p *build.Package)
| 190 | // autobuild compares the mod time of the source files of the package, and if any of them is newer |
| 191 | // than the package object file will rebuild it. |
| 192 | func autobuild(p *build.Package) error { |
| 193 | if p.Dir == "" { |
| 194 | return fmt.Errorf("no files to build") |
| 195 | } |
| 196 | ps, err := os.Stat(p.PkgObj) |
| 197 | if err != nil { |
| 198 | // Assume package file does not exist and build for the first time. |
| 199 | return build_package(p) |
| 200 | } |
| 201 | pt := ps.ModTime() |
| 202 | fs, err := readdir_lstat(p.Dir) |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 | for _, f := range fs { |
| 207 | if f.IsDir() { |
| 208 | continue |
| 209 | } |
| 210 | if f.ModTime().After(pt) { |
| 211 | // Source file is newer than package file; rebuild. |
| 212 | return build_package(p) |
| 213 | } |
| 214 | } |
| 215 | return nil |
| 216 | } |
| 217 | |
| 218 | // build_package builds the package by calling `go install package/import`. If everything compiles |
| 219 | // correctly, the newly compiled package should then be in the usual place in the `$GOPATH/pkg` |
no test coverage detected