MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / getOriginalPath

Method getOriginalPath

loader/loader.go:271–299  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

269// replaces the path with the original path (in GOROOT or TINYGOROOT). Otherwise
270// the input path is returned.
271func (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.

Callers 3

LoadFunction · 0.95
OriginalDirMethod · 0.80
parseFileMethod · 0.80

Calls 5

GetFunction · 0.92
pathsToOverrideFunction · 0.85
needsSyscallPackageFunction · 0.85
BuildTagsMethod · 0.80
StatMethod · 0.45

Tested by

no test coverage detected