vendor/google.golang.org/appengine/internal/main_vm.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
--- a/vendor/google.golang.org/appengine/internal/main_vm.go	Wed Sep 18 19:17:42 2019 +0200
+++ b/vendor/google.golang.org/appengine/internal/main_vm.go	Sun Feb 16 18:54:01 2020 +0100
@@ -12,9 +12,12 @@
 	"net/http"
 	"net/url"
 	"os"
+	"path/filepath"
+	"runtime"
 )
 
 func Main() {
+	MainPath = filepath.Dir(findMainPath())
 	installHealthChecker(http.DefaultServeMux)
 
 	port := "8080"
@@ -31,6 +34,24 @@
 	}
 }
 
+// Find the path to package main by looking at the root Caller.
+func findMainPath() string {
+	pc := make([]uintptr, 100)
+	n := runtime.Callers(2, pc)
+	frames := runtime.CallersFrames(pc[:n])
+	for {
+		frame, more := frames.Next()
+		// Tests won't have package main, instead they have testing.tRunner
+		if frame.Function == "main.main" || frame.Function == "testing.tRunner" {
+			return frame.File
+		}
+		if !more {
+			break
+		}
+	}
+	return ""
+}
+
 func installHealthChecker(mux *http.ServeMux) {
 	// If no health check handler has been installed by this point, add a trivial one.
 	const healthPath = "/_ah/health"