1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Use the new Go workspace paths when building qualified symbol names

This commit is contained in:
Achilleas Anagnostopoulos 2017-07-01 20:39:47 +01:00
parent 00fdf79888
commit f961270904

View File

@ -15,6 +15,8 @@ import (
"strings" "strings"
) )
const pathToKernel = "src/gopheros/"
type redirect struct { type redirect struct {
src string src string
dst string dst string
@ -28,16 +30,6 @@ func exit(err error) {
os.Exit(1) os.Exit(1)
} }
func pkgPrefix() (string, error) {
goPath := os.Getenv("GOPATH") + "/src/"
cwd, err := os.Getwd()
if err != nil {
return "", err
}
return strings.TrimPrefix(cwd, goPath), nil
}
func collectGoFiles(root string) ([]string, error) { func collectGoFiles(root string) ([]string, error) {
var goFiles []string var goFiles []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
@ -61,11 +53,6 @@ func collectGoFiles(root string) ([]string, error) {
func findRedirects(goFiles []string) ([]*redirect, error) { func findRedirects(goFiles []string) ([]*redirect, error) {
var redirects []*redirect var redirects []*redirect
prefix, err := pkgPrefix()
if err != nil {
return nil, err
}
for _, goFile := range goFiles { for _, goFile := range goFiles {
fset := token.NewFileSet() fset := token.NewFileSet()
@ -88,9 +75,8 @@ func findRedirects(goFiles []string) ([]*redirect, error) {
} }
// build qualified name to fn // build qualified name to fn
fqName := fmt.Sprintf("%s/%s.%s", fqName := fmt.Sprintf("%s.%s",
prefix, goFile[strings.Index(goFile, "gopheros"):strings.LastIndexByte(goFile, '/')],
goFile[:strings.LastIndexByte(goFile, '/')],
fnDecl.Name, fnDecl.Name,
) )
@ -185,8 +171,8 @@ func elfResolveRedirectSymbols(redirects []*redirect, imgFile string) error {
func main() { func main() {
flag.Parse() flag.Parse()
if matches, _ := filepath.Glob("kernel/"); len(matches) != 1 { if matches, _ := filepath.Glob(pathToKernel); len(matches) != 1 {
exit(errors.New("this tool must be run from the kernel root folder")) exit(errors.New("this tool must be run from the gopher-os root folder"))
} }
if len(flag.Args()) == 0 { if len(flag.Args()) == 0 {
@ -206,7 +192,7 @@ func main() {
exit(fmt.Errorf("unknown command %q", cmd)) exit(fmt.Errorf("unknown command %q", cmd))
} }
goFiles, err := collectGoFiles("kernel/") goFiles, err := collectGoFiles(pathToKernel)
if err != nil { if err != nil {
exit(err) exit(err)
} }