]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix build -n for cgo enabled packages
authorAnthony Martin <ality@pbrane.org>
Wed, 30 Jan 2013 23:09:34 +0000 (15:09 -0800)
committerAnthony Martin <ality@pbrane.org>
Wed, 30 Jan 2013 23:09:34 +0000 (15:09 -0800)
R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7095067

src/cmd/go/build.go

index 4591225ef492477c78a0b9b55d2500f88d6fdf27..2d1f252770dbb4e96a2958397a5cbcc8d2be0deb 100644 (file)
@@ -1534,10 +1534,28 @@ func gccgoCleanPkgpath(p *Package) string {
 // libgcc returns the filename for libgcc, as determined by invoking gcc with
 // the -print-libgcc-file-name option.
 func (b *builder) libgcc(p *Package) (string, error) {
+       var buf bytes.Buffer
+
+       prev := b.print
+       if buildN {
+               // In -n mode we temporarily swap out the builder's
+               // print function to capture the command-line. This
+               // let's us assign it to $LIBGCC and produce a valid
+               // buildscript for cgo packages.
+               b.print = func(a ...interface{}) (n int, err error) {
+                       return fmt.Fprint(&buf, a...)
+               }
+       }
        f, err := b.runOut(p.Dir, p.ImportPath, b.gccCmd(p.Dir), "-print-libgcc-file-name")
        if err != nil {
                return "", fmt.Errorf("gcc -print-libgcc-file-name: %v (%s)", err, f)
        }
+       if buildN {
+               s := fmt.Sprintf("LIBGCC=$(%s)\n", buf.Next(buf.Len()-1))
+               b.print = prev
+               b.print(s)
+               return "$LIBGCC", nil
+       }
        return strings.Trim(string(f), "\r\n"), nil
 }