package gccgoimporter
import (
"bufio"
"go/types"
"os"
"os/exec"
"path/filepath"
"strings"
)
type GccgoInstallation struct {
GccVersion string
TargetTriple string
LibPaths []string
}
func (inst *GccgoInstallation ) InitFromDriver (gccgoPath string , args ...string ) (err error ) {
argv := append ([]string {"-###" , "-S" , "-x" , "go" , "-" }, args ...)
cmd := exec .Command (gccgoPath , argv ...)
stderr , err := cmd .StderrPipe ()
if err != nil {
return
}
err = cmd .Start ()
if err != nil {
return
}
scanner := bufio .NewScanner (stderr )
for scanner .Scan () {
line := scanner .Text ()
switch {
case strings .HasPrefix (line , "Target: " ):
inst .TargetTriple = line [8 :]
case line [0 ] == ' ' :
args := strings .Fields (line )
for _ , arg := range args [1 :] {
if strings .HasPrefix (arg , "-L" ) {
inst .LibPaths = append (inst .LibPaths , arg [2 :])
}
}
}
}
argv = append ([]string {"-dumpversion" }, args ...)
stdout , err := exec .Command (gccgoPath , argv ...).Output ()
if err != nil {
return
}
inst .GccVersion = strings .TrimSpace (string (stdout ))
return
}
func (inst *GccgoInstallation ) SearchPaths () (paths []string ) {
for _ , lpath := range inst .LibPaths {
spath := filepath .Join (lpath , "go" , inst .GccVersion )
fi , err := os .Stat (spath )
if err != nil || !fi .IsDir () {
continue
}
paths = append (paths , spath )
spath = filepath .Join (spath , inst .TargetTriple )
fi , err = os .Stat (spath )
if err != nil || !fi .IsDir () {
continue
}
paths = append (paths , spath )
}
paths = append (paths , inst .LibPaths ...)
return
}
func (inst *GccgoInstallation ) GetImporter (incpaths []string , initmap map [*types .Package ]InitData ) Importer {
return GetImporter (append (append (incpaths , inst .SearchPaths ()...), "." ), initmap )
}
The pages are generated with Golds v0.7.3 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .