Commit a063a228 authored by Ali Rizvi-Santiago's avatar Ali Rizvi-Santiago Committed by Ian Lance Taylor

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: 4aa1d631eaca58be6c3a4be40f7404fa75a0db25
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: default avatarIan Lance Taylor <iant@golang.org>
parent f36e92db
......@@ -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:
//
......
......@@ -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:
......
......@@ -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
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment