1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Except for this comment, this file is a verbatim copy of the file
6 // with the same name in $GOROOT/src/go/internal/gccgoimporter.
19 // Information about a specific installation of gccgo.
20 type GccgoInstallation struct {
21 // Version of gcc (e.g. 4.8.0).
24 // Target triple (e.g. x86_64-unknown-linux-gnu).
27 // Built-in library paths used by this installation.
31 // Ask the driver at the given path for information for this GccgoInstallation.
32 // The given arguments are passed directly to the call of the driver.
33 func (inst *GccgoInstallation) InitFromDriver(gccgoPath string, args ...string) (err error) {
34 argv := append([]string{"-###", "-S", "-x", "go", "-"}, args...)
35 cmd := exec.Command(gccgoPath, argv...)
36 stderr, err := cmd.StderrPipe()
46 scanner := bufio.NewScanner(stderr)
48 line := scanner.Text()
50 case strings.HasPrefix(line, "Target: "):
51 inst.TargetTriple = line[8:]
54 args := strings.Fields(line)
55 for _, arg := range args[1:] {
56 if strings.HasPrefix(arg, "-L") {
57 inst.LibPaths = append(inst.LibPaths, arg[2:])
63 argv = append([]string{"-dumpversion"}, args...)
64 stdout, err := exec.Command(gccgoPath, argv...).Output()
68 inst.GccVersion = strings.TrimSpace(string(stdout))
73 // Return the list of export search paths for this GccgoInstallation.
74 func (inst *GccgoInstallation) SearchPaths() (paths []string) {
75 for _, lpath := range inst.LibPaths {
76 spath := filepath.Join(lpath, "go", inst.GccVersion)
77 fi, err := os.Stat(spath)
78 if err != nil || !fi.IsDir() {
81 paths = append(paths, spath)
83 spath = filepath.Join(spath, inst.TargetTriple)
84 fi, err = os.Stat(spath)
85 if err != nil || !fi.IsDir() {
88 paths = append(paths, spath)
91 paths = append(paths, inst.LibPaths...)
96 // Return an importer that searches incpaths followed by the gcc installation's
97 // built-in search paths and the current directory.
98 func (inst *GccgoInstallation) GetImporter(incpaths []string, initmap map[*types.Package]InitData) Importer {
99 return GetImporter(append(append(incpaths, inst.SearchPaths()...), "."), initmap)