Merge "Support go 1.12"
am: bb3deefa9d
Change-Id: I7dd228e6bc91632ddd59acb9b6c9329d627ef3fb
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -164,12 +166,17 @@ func checkCalledFromInit() {
|
|||||||
panic("not called from an init func")
|
panic("not called from an init func")
|
||||||
}
|
}
|
||||||
|
|
||||||
if funcName == "init" || strings.HasPrefix(funcName, "init·") {
|
if funcName == "init" || strings.HasPrefix(funcName, "init·") ||
|
||||||
|
strings.HasPrefix(funcName, "init.") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A regex to find a package path within a function name. It finds the shortest string that is
|
||||||
|
// followed by '.' and doesn't have any '/'s left.
|
||||||
|
var pkgPathRe = regexp.MustCompile(`^(.*?)\.([^/]+)$`)
|
||||||
|
|
||||||
// callerName returns the package path and function name of the calling
|
// callerName returns the package path and function name of the calling
|
||||||
// function. The skip argument has the same meaning as the skip argument of
|
// function. The skip argument has the same meaning as the skip argument of
|
||||||
// runtime.Callers.
|
// runtime.Callers.
|
||||||
@@ -180,25 +187,13 @@ func callerName(skip int) (pkgPath, funcName string, ok bool) {
|
|||||||
return "", "", false
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
f := runtime.FuncForPC(pc[0])
|
f := runtime.FuncForPC(pc[0]).Name()
|
||||||
fullName := f.Name()
|
s := pkgPathRe.FindStringSubmatch(f)
|
||||||
|
if len(s) < 3 {
|
||||||
lastDotIndex := strings.LastIndex(fullName, ".")
|
panic(fmt.Errorf("failed to extract package path and function name from %q", f))
|
||||||
if lastDotIndex == -1 {
|
|
||||||
panic("unable to distinguish function name from package")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullName[lastDotIndex-1] == ')' {
|
return s[1], s[2], true
|
||||||
// The caller is a method on some type, so it's name looks like
|
|
||||||
// "pkg/path.(type).method". We need to go back one dot farther to get
|
|
||||||
// to the package name.
|
|
||||||
lastDotIndex = strings.LastIndex(fullName[:lastDotIndex], ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgPath = fullName[:lastDotIndex]
|
|
||||||
funcName = fullName[lastDotIndex+1:]
|
|
||||||
ok = true
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNumericSdkVersion(v string) string {
|
func GetNumericSdkVersion(v string) string {
|
||||||
|
Reference in New Issue
Block a user