Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: errors when using pkg-config 0.29.2 from the OpenWRT toolchain #27940

Closed
corny opened this issue Sep 29, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@corny
Copy link

commented Sep 29, 2018

What version of Go are you using (go version)?

1.10

Does this issue reproduce with the latest release?

not tried, but relevant code has not been changed since 1.10

What operating system and processor architecture are you using (go env)?

linux / amd64

What did you do?

I tried to build a binary using the library https://github.com/digineo/fastd/fastd with the OpenWRT toolchain.

What did you expect to see?

A successful build.
pkg-config --cflags -- libuecc on the host machine with version 0.29.1-0ubuntu2 prints -I/usr/include/libuecc-7

What did you see instead?

~/workspace/lede/staging_dir/host/bin/pkg-config --cflags -- libuecc
# ~/workspace/lede/staging_dir/host/bin/pkg-config --cflags libuecc
Package -- was not found in the pkg-config search path.
Perhaps you should add the directory containing `--.pc'
to the PKG_CONFIG_PATH environment variable
No package '--' found

pkg-config --cflags -- libuecc in the OpenWRT build environment with pkg-config 0.29.2 fails with Package -- was not found in the pkg-config search path

Possible solution

Remove the "--" argument in src/cmd/go/internal/work/exec.go:

out, err = b.runOut(p.Dir, nil, b.PkgconfigCmd(), "--cflags", pcflags, "--", pkgs)
@mvdan

This comment has been minimized.

Copy link
Member

commented Sep 30, 2018

It's very common for programs to understand -- as the end of the flag arguments. This way, even if any of the strings in pkgs started with a dash, it would still be understood as a regular argument and not a flag.

Locally, I have pkg-config from pkgconf, and it seems to understand -- just fine:

$ pkg-config --version
1.5.3
$ pkg-config --cflags -- libuecc
Package libuecc was not found in the pkg-config search path.
Perhaps you should add the directory containing `libuecc.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libuecc', required by 'virtual:world', not found

I downloaded pkg-config 0.29.2 from freedesktop (https://pkgconfig.freedesktop.org/releases/) and compiled it, but it seems to also understand that flag:

$ ./pkg-config --version
0.29.2
$ ./pkg-config --cflags -- libuecc
Package libuecc was not found in the pkg-config search path.
Perhaps you should add the directory containing `libuecc.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libuecc' found

What am I missing? Does OpenWRT compile pkg-config in some special way that I'm not? Or perhaps I tested the wrong software?

Ideally we wouldn't remove the -- argument, as it's useful and there's (in theory) nothing wrong with using it.

@mvdan mvdan changed the title pkg-config fails in version 0.29.2 cmd/go: errors when using pkg-config 0.29.2 from the OpenWRT toolchain Sep 30, 2018

@mvdan

This comment has been minimized.

Copy link
Member

commented Sep 30, 2018

@corny

This comment has been minimized.

Copy link
Author

commented Sep 30, 2018

@mvdan Thanks a lot for your investigation. I am going to ask the OpenWRT developers for taking a look at this issue.

Where exactly is the -- argument of pkg-config documented? I can't find anything in the man page.

@mvdan

This comment has been minimized.

Copy link
Member

commented Sep 30, 2018

It seems like pkg-config 0.29.2 uses g_option_context_parse, which has support for --.

You can see the code in question in glib/glib/goption.c:1825, as extracted from the 0.29.2 source:

/* '--' terminates list of arguments */
if (*arg == 0)
  {
    separator_pos = i;
    stop_parsing = TRUE;
    continue;
  }

It's true that the manpage doesn't explicitly mention support for --, but given that it accepts GNU style flags, I'd imagine it's a given that one can stop flag parsing as usual.

Here seems to be OpenWRT's Makefile for pkg-config, though I don't see anything that could change this behavior: https://github.com/openwrt/openwrt/blob/master/tools/pkg-config/Makefile

They do build their own glib though, so perhaps they build it in a specific way that affects flag parsing.

@corny

This comment has been minimized.

Copy link
Author

commented Oct 1, 2018

This problem has to be fixed in the OpenWRT toolchain.

@corny corny closed this Oct 1, 2018

jow- pushed a commit to lede-project/source that referenced this issue Oct 20, 2018

tools/pkg-config: pass arguments at the end
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>

jollaman999 added a commit to jollaman999/openwrt that referenced this issue Oct 20, 2018

tools/pkg-config: pass arguments at the end
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>

stumper932 added a commit to stumper932/openwrt that referenced this issue Nov 11, 2018

tools/pkg-config: pass arguments at the end
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>

jow- added a commit to openwrt/openwrt that referenced this issue Apr 24, 2019

tools/pkg-config: pass arguments at the end
Go for openwrt passes pkg-config arguments in the format of

        pkg-config --cflags -- pkg-name

which in turn will be passed down to the real pkg-config as something
like

        pkg-config.real --cflags -- pkg-name --define...

and causes the real pkg-config implementation to missinterpret the given
argument list.

This also helps to fix golang/go#27940

Signed-off-by: Arthur Skowronek <arthur.skowronek@tuta.io>
(cherry picked from commit 5f2cb6d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.