getOriginalPath looks whether this path is in the generated GOROOT and if so, replaces the path with the original path (in GOROOT or TINYGOROOT). Otherwise the input path is returned.
(path string)
| 269 | // replaces the path with the original path (in GOROOT or TINYGOROOT). Otherwise |
| 270 | // the input path is returned. |
| 271 | func (p *Program) getOriginalPath(path string) string { |
| 272 | originalPath := path |
| 273 | if strings.HasPrefix(path, p.goroot+string(filepath.Separator)) { |
| 274 | // If this file is part of the synthetic GOROOT, try to infer the |
| 275 | // original path. |
| 276 | relpath := path[len(filepath.Join(p.goroot, "src"))+1:] |
| 277 | realgorootPath := filepath.Join(goenv.Get("GOROOT"), "src", relpath) |
| 278 | if _, err := os.Stat(realgorootPath); err == nil { |
| 279 | originalPath = realgorootPath |
| 280 | } |
| 281 | maybeInTinyGoRoot := false |
| 282 | for prefix := range pathsToOverride(p.config.GoMinorVersion, needsSyscallPackage(p.config.BuildTags())) { |
| 283 | if runtime.GOOS == "windows" { |
| 284 | prefix = strings.ReplaceAll(prefix, "/", "\\") |
| 285 | } |
| 286 | if !strings.HasPrefix(relpath, prefix) { |
| 287 | continue |
| 288 | } |
| 289 | maybeInTinyGoRoot = true |
| 290 | } |
| 291 | if maybeInTinyGoRoot { |
| 292 | tinygoPath := filepath.Join(goenv.Get("TINYGOROOT"), "src", relpath) |
| 293 | if _, err := os.Stat(tinygoPath); err == nil { |
| 294 | originalPath = tinygoPath |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | return originalPath |
| 299 | } |
| 300 | |
| 301 | // Sorted returns a list of all packages, sorted in a way that no packages come |
| 302 | // before the packages they depend upon. |
no test coverage detected