]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: handle escapes in pkg-config ldflags output
authorzlasd <zlasd@hotmail.com>
Thu, 9 Feb 2023 14:03:45 +0000 (14:03 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 10 Feb 2023 21:45:51 +0000 (21:45 +0000)
#16455 handled escapes in pkg-config output but only for cflags. The fix
for #41400 left a note that we don't need to parse quotes and unescapes,
but it is still necessary to handle spaces in pkg-config output. As cflags
has already been processed correctly, we apply the same logic to ldflags
here.

Fixes #35262

Change-Id: Id01d422b103780f67f89e99ff1df0d8f51a7a137
GitHub-Last-Rev: c67e5112130fa008397cfd0bc03e1de58201da86
GitHub-Pull-Request: golang/go#58429
Reviewed-on: https://go-review.googlesource.com/c/go/+/466875
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/go/go_test.go
src/cmd/go/internal/work/exec.go

index ef22499b87add3cd362524aa0a85107d0e1c3216..f056ab9a376275864a36b2d859e1a5d96b8b5cf1 100644 (file)
@@ -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) {
index 8dde0a9e06412792700ab73079129a848d342941..c1476f8757ade3781220332267dd3c9c45ee894b 100644 (file)
@@ -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
                        }