| 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. |
| 4 | |
| 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. |
| 7 | |
| 8 | package gccgoimporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/ |
| 9 | |
| 10 | import ( |
| 11 | "bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/" |
| 12 | "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/" |
| 13 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 14 | "os/execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/" |
| 15 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 16 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 17 | ) |
| 18 | |
| 19 | // Information about a specific installation of gccgo. |
| 20 | type GccgoInstallationscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation# struct { |
| 21 | // Version of gcc (e.g. 4.8.0). |
| 22 | GccVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#GccVersion. string |
| 23 | |
| 24 | // Target triple (e.g. x86_64-unknown-linux-gnu). |
| 25 | TargetTriplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#TargetTriple. string |
| 26 | |
| 27 | // Built-in library paths used by this installation. |
| 28 | LibPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#LibPaths. []string |
| 29 | } |
| 30 | |
| 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 *GccgoInstallationscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#) InitFromDriverscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#InitFromDriver().(gccgoPath string, args ...string) (err error) { |
| 34 | argv := append([]string{"-###", "-S", "-x", "go", "-"}, args...) |
| 35 | cmd := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(gccgoPath, argv...) |
| 36 | stderr, err := cmd.StderrPipescip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#StderrPipe().() |
| 37 | if err != nil { |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | err = cmd.Startscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Start().() |
| 42 | if err != nil { |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | scanner := bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/NewScanner().(stderr) |
| 47 | for scanner.Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() { |
| 48 | line := scanner.Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().() |
| 49 | switch { |
| 50 | case stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(line, "Target: "): |
| 51 | inst.TargetTriplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#TargetTriple. = line[8:] |
| 52 | |
| 53 | case line[0] == ' ': |
| 54 | args := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().(line) |
| 55 | for _, arg := range args[1:] { |
| 56 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(arg, "-L") { |
| 57 | inst.LibPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#LibPaths. = append(inst.LibPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#LibPaths., arg[2:]) |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | if err := scanner.Errscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Err().(); err != nil { |
| 63 | return err |
| 64 | } |
| 65 | |
| 66 | argv = append([]string{"-dumpversion"}, args...) |
| 67 | stdout, err := execscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/.Commandscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Command().(gccgoPath, argv...).Outputscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Output().() |
| 68 | if err != nil { |
| 69 | return |
| 70 | } |
| 71 | inst.GccVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#GccVersion. = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(string(stdout)) |
| 72 | |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | // Return the list of export search paths for this GccgoInstallation. |
| 77 | func (inst *GccgoInstallationscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#) SearchPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#SearchPaths().() (paths []string) { |
| 78 | for _, lpath := range inst.LibPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#LibPaths. { |
| 79 | spath := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(lpath, "go", inst.GccVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#GccVersion.) |
| 80 | fi, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(spath) |
| 81 | if err != nil || !fi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() { |
| 82 | continue |
| 83 | } |
| 84 | paths = append(paths, spath) |
| 85 | |
| 86 | spath = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(spath, inst.TargetTriplescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#TargetTriple.) |
| 87 | fi, err = osscip-go gomod github.com/golang/go/src go1.25.0 os/.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Stat().(spath) |
| 88 | if err != nil || !fi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() { |
| 89 | continue |
| 90 | } |
| 91 | paths = append(paths, spath) |
| 92 | } |
| 93 | |
| 94 | paths = append(paths, inst.LibPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#LibPaths....) |
| 95 | |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | // Return an importer that searches incpaths followed by the gcc installation's |
| 100 | // built-in search paths and the current directory. |
| 101 | func (inst *GccgoInstallationscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#) GetImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#GetImporter().(incpaths []string, initmap map[*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Packagescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Package#]InitDatascip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/InitData#) Importerscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/Importer# { |
| 102 | return GetImporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GetImporter().(append(append(incpaths, inst.SearchPathsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/GccgoInstallation#SearchPaths().()...), "."), initmap) |
| 103 | } |