cmd/go: allow the user to specify ar via an environment variable

This allows one to customize which ar to use by fetching its path
from the environment. This way one can swap it out for a
different implementation.

Change-Id: I40d8cbd8a69e97b5254e66081d9bf0b726c10366
GitHub-Last-Rev: 4aa1d631ea
GitHub-Pull-Request: golang/go#28746
Reviewed-on: https://go-review.googlesource.com/c/149117
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ali Rizvi-Santiago 2018-11-14 20:16:14 +00:00 committed by Ian Lance Taylor
parent f36e92dbfc
commit a063a2284a
3 changed files with 21 additions and 5 deletions

View File

@ -1500,6 +1500,10 @@
// The command to use to compile C++ code.
// PKG_CONFIG
// Path to pkg-config tool.
// AR
// The command to use to manipulate library archives when
// building with the gccgo compiler.
// The default is 'ar'.
//
// Architecture-specific environment variables:
//

View File

@ -546,6 +546,10 @@ Environment variables for use with cgo:
The command to use to compile C++ code.
PKG_CONFIG
Path to pkg-config tool.
AR
The command to use to manipulate library archives when
building with the gccgo compiler.
The default is 'ar'.
Architecture-specific environment variables:

View File

@ -43,6 +43,14 @@ func (gccgoToolchain) linker() string {
return GccgoBin
}
func (gccgoToolchain) ar() string {
ar := os.Getenv("AR")
if ar == "" {
ar = "ar"
}
return ar
}
func checkGccgoBin() {
if gccgoErr == nil {
return
@ -183,7 +191,7 @@ func gccgoArchive(basedir, imp string) string {
return filepath.Join(filepath.Dir(afile), "lib"+filepath.Base(afile))
}
func (gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) error {
func (tools gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) error {
p := a.Package
objdir := a.Objdir
var absOfiles []string
@ -198,7 +206,7 @@ func (gccgoToolchain) pack(b *Builder, a *Action, afile string, ofiles []string)
arArgs = []string{"-X64"}
}
return b.run(a, p.Dir, p.ImportPath, nil, "ar", arArgs, "rc", mkAbs(objdir, afile), absOfiles)
return b.run(a, p.Dir, p.ImportPath, nil, tools.ar(), arArgs, "rc", mkAbs(objdir, afile), absOfiles)
}
func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string, allactions []*Action, buildmode, desc string) error {
@ -257,11 +265,11 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
return "", nil
}
}
err := b.run(root, root.Objdir, desc, nil, "ar", "x", newArchive, "_cgo_flags")
err := b.run(root, root.Objdir, desc, nil, tools.ar(), "x", newArchive, "_cgo_flags")
if err != nil {
return "", err
}
err = b.run(root, ".", desc, nil, "ar", "d", newArchive, "_cgo_flags")
err = b.run(root, ".", desc, nil, tools.ar(), "d", newArchive, "_cgo_flags")
if err != nil {
return "", err
}
@ -473,7 +481,7 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, out, importcfg string
switch buildmode {
case "c-archive":
if err := b.run(root, ".", desc, nil, "ar", "rc", realOut, out); err != nil {
if err := b.run(root, ".", desc, nil, tools.ar(), "rc", realOut, out); err != nil {
return err
}
}