go/gccgoexportdata: plumb additional arguments to gccgo compiler

Allow extra arguments to be passed to the specified gccgo compiler
when it is called in GccgoInstallation.InitFromDriver. This allows
the call to gccgo to be adjusted depending on the build environment.

For example, some build environments require the
'no-canonical-prefixes' option to prevent gccgo from resolving
symlinks when generating relative prefixes.

Change-Id: I0ecf338ee7a3780f1f65b30e214e69c1698041bb
Reviewed-on: https://go-review.googlesource.com/32874
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Samuel Tan 2016-11-07 11:42:23 -08:00 committed by Alan Donovan
parent 46c63f3841
commit 09079c88dc
2 changed files with 10 additions and 6 deletions

View File

@ -30,10 +30,11 @@ import (
// CompilerInfo executes the specified gccgo compiler and returns // CompilerInfo executes the specified gccgo compiler and returns
// information about it: its version (e.g. "4.8.0"), its target triple // information about it: its version (e.g. "4.8.0"), its target triple
// (e.g. "x86_64-unknown-linux-gnu"), and the list of directories it // (e.g. "x86_64-unknown-linux-gnu"), and the list of directories it
// searches to find standard packages. // searches to find standard packages. The given arguments are passed
func CompilerInfo(gccgo string) (version, triple string, dirs []string, err error) { // directly to calls to the specified gccgo compiler.
func CompilerInfo(gccgo string, args ...string) (version, triple string, dirs []string, err error) {
var inst gccgoimporter.GccgoInstallation var inst gccgoimporter.GccgoInstallation
err = inst.InitFromDriver(gccgo) err = inst.InitFromDriver(gccgo, args...)
if err == nil { if err == nil {
version = inst.GccVersion version = inst.GccVersion
triple = inst.TargetTriple triple = inst.TargetTriple

View File

@ -28,8 +28,10 @@ type GccgoInstallation struct {
} }
// Ask the driver at the given path for information for this GccgoInstallation. // Ask the driver at the given path for information for this GccgoInstallation.
func (inst *GccgoInstallation) InitFromDriver(gccgoPath string) (err error) { // The given arguments are passed directly to the call to the driver.
cmd := exec.Command(gccgoPath, "-###", "-S", "-x", "go", "-") 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() stderr, err := cmd.StderrPipe()
if err != nil { if err != nil {
return return
@ -57,7 +59,8 @@ func (inst *GccgoInstallation) InitFromDriver(gccgoPath string) (err error) {
} }
} }
stdout, err := exec.Command(gccgoPath, "-dumpversion").Output() argv = append([]string{"-dumpversion"}, args...)
stdout, err := exec.Command(gccgoPath, argv...).Output()
if err != nil { if err != nil {
return return
} }