From 09079c88dc57ba9f9c46c4864af014a9e536f1b4 Mon Sep 17 00:00:00 2001 From: Samuel Tan Date: Mon, 7 Nov 2016 11:42:23 -0800 Subject: [PATCH] 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 --- go/gccgoexportdata/gccgoexportdata.go | 7 ++++--- go/internal/gccgoimporter/gccgoinstallation.go | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/go/gccgoexportdata/gccgoexportdata.go b/go/gccgoexportdata/gccgoexportdata.go index 7d276c75..ca5f75f0 100644 --- a/go/gccgoexportdata/gccgoexportdata.go +++ b/go/gccgoexportdata/gccgoexportdata.go @@ -30,10 +30,11 @@ import ( // CompilerInfo executes the specified gccgo compiler and returns // 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 -// searches to find standard packages. -func CompilerInfo(gccgo string) (version, triple string, dirs []string, err error) { +// searches to find standard packages. The given arguments are passed +// 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 - err = inst.InitFromDriver(gccgo) + err = inst.InitFromDriver(gccgo, args...) if err == nil { version = inst.GccVersion triple = inst.TargetTriple diff --git a/go/internal/gccgoimporter/gccgoinstallation.go b/go/internal/gccgoimporter/gccgoinstallation.go index 2bf1f6ff..cebfc571 100644 --- a/go/internal/gccgoimporter/gccgoinstallation.go +++ b/go/internal/gccgoimporter/gccgoinstallation.go @@ -28,8 +28,10 @@ type GccgoInstallation struct { } // Ask the driver at the given path for information for this GccgoInstallation. -func (inst *GccgoInstallation) InitFromDriver(gccgoPath string) (err error) { - cmd := exec.Command(gccgoPath, "-###", "-S", "-x", "go", "-") +// The given arguments are passed directly to the call to the driver. +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 @@ -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 { return }