Skip to content

Commit c67e511

Browse files
committed
cmd/go: handle spaces in pkg-config ldflags output
Change-Id: I2949befa42bf572836ecf112fe8af098178e3ee5
1 parent fd208c8 commit c67e511

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/cmd/go/go_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,22 @@ func main() {
16161616
`)
16171617
tg.setenv("PKG_CONFIG_PATH", tg.path("."))
16181618
tg.run("run", tg.path("foo.go"))
1619+
1620+
// test for ldflags
1621+
tg.tempFile("bar.pc", `
1622+
Name: bar
1623+
Description: The bar library
1624+
Version: 1.0.0
1625+
Libs: -Wl,-rpath=/path\ with\ spaces/bin
1626+
`)
1627+
tg.tempFile("bar.go", `package main
1628+
/*
1629+
#cgo pkg-config: bar
1630+
*/
1631+
import "C"
1632+
func main() {}
1633+
`)
1634+
tg.run("run", tg.path("bar.go"))
16191635
}
16201636

16211637
func TestListTemplateContextFunction(t *testing.T) {

src/cmd/go/internal/work/exec.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1549,9 +1549,12 @@ func (b *Builder) getPkgConfigFlags(p *load.Package) (cflags, ldflags []string,
15491549
return nil, nil, err
15501550
}
15511551
if len(out) > 0 {
1552-
// NOTE: we don't attempt to parse quotes and unescapes here. pkg-config
1553-
// is typically used within shell backticks, which treats quotes literally.
1554-
ldflags = strings.Fields(string(out))
1552+
// We need to handle path with spaces so that C:/Program\ Files can pass
1553+
// checkLinkerFlags. Use splitPkgConfigOutput here just like we treat cflags.
1554+
ldflags, err = splitPkgConfigOutput(out)
1555+
if err != nil {
1556+
return nil, nil, err
1557+
}
15551558
if err := checkLinkerFlags("LDFLAGS", "pkg-config --libs", ldflags); err != nil {
15561559
return nil, nil, err
15571560
}

0 commit comments

Comments
 (0)