Skip to content

Commit

Permalink
cmd/go: handle spaces in pkg-config ldflags output
Browse files Browse the repository at this point in the history
Change-Id: I2949befa42bf572836ecf112fe8af098178e3ee5
  • Loading branch information
zlasd committed Feb 9, 2023
1 parent fd208c8 commit c67e511
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/cmd/go/go_test.go
Expand Up @@ -1616,6 +1616,22 @@ func main() {
`)
tg.setenv("PKG_CONFIG_PATH", tg.path("."))
tg.run("run", tg.path("foo.go"))

// test for ldflags
tg.tempFile("bar.pc", `
Name: bar
Description: The bar library
Version: 1.0.0
Libs: -Wl,-rpath=/path\ with\ spaces/bin
`)
tg.tempFile("bar.go", `package main
/*
#cgo pkg-config: bar
*/
import "C"
func main() {}
`)
tg.run("run", tg.path("bar.go"))
}

func TestListTemplateContextFunction(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/go/internal/work/exec.go
Expand Up @@ -1549,9 +1549,12 @@ func (b *Builder) getPkgConfigFlags(p *load.Package) (cflags, ldflags []string,
return nil, nil, err
}
if len(out) > 0 {
// NOTE: we don't attempt to parse quotes and unescapes here. pkg-config
// is typically used within shell backticks, which treats quotes literally.
ldflags = strings.Fields(string(out))
// We need to handle path with spaces so that C:/Program\ Files can pass
// checkLinkerFlags. Use splitPkgConfigOutput here just like we treat cflags.
ldflags, err = splitPkgConfigOutput(out)
if err != nil {
return nil, nil, err
}
if err := checkLinkerFlags("LDFLAGS", "pkg-config --libs", ldflags); err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit c67e511

Please sign in to comment.