Bug 97453 - ENABLE_DEFINE_PREFIX defined and empty prefix yields incorrect results
Summary: ENABLE_DEFINE_PREFIX defined and empty prefix yields incorrect results
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) other
: medium normal
Assignee: Dan Nicholson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-23 16:54 UTC by philippe_renon
Modified: 2016-08-30 16:44 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
full debug output (64.58 KB, text/plain)
2016-08-24 09:39 UTC, philippe_renon
Details
full debug output (167 bytes, text/plain)
2016-08-24 09:41 UTC, philippe_renon
Details
full debug output (65.67 KB, text/plain)
2016-08-24 09:42 UTC, philippe_renon
Details
Don't override empty prefix setting (2.55 KB, patch)
2016-08-24 17:35 UTC, Dan Nicholson
Details | Splinter Review

Description philippe_renon 2016-08-23 16:54:13 UTC
The msys2/mingw provided pkg-config is compiled with ENABLE_DEFINE_PREFIX defined.

gstreamer has this pc file:

# the standard variables don't make sense for an uninstalled copy
prefix=
exec_prefix=
libdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs
# includedir is builddir because it is used to find gstconfig.h in places
includedir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32
toolsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/tools
pluginsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32
girdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst
completionsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/data/completions
helpersdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/libs/gst/helpers
typelibdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst

Name: GStreamer Uninstalled
Description: Streaming media framework, Not Installed
Version: 1.8.2
Requires: glib-2.0, gobject-2.0
Requires.private: gmodule-no-export-2.0
Libs: -L${libdir} -lgstreamer-1.0
Cflags: -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/../gstreamer-1.8.2 -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/../gstreamer-1.8.2/libs -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32 -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/libs


Running pkgconf on it yields this:

$  pkg-config --libs gstreamer-1.0-uninstalled
-LD:/msys64/mingw64/lib -LD:/M/mingw-w64-gstreamer/src/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl

You can see that the second -L dir is messed up.

Same with --debug gives this (only significant output is kept):

Reading 'gstreamer-1.0-uninstalled' from file 'D:/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/pkgconfig\gstreamer-1.0-uninstalled.pc'
Parsing package file 'D:/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/pkgconfig\gstreamer-1.0-uninstalled.pc'
  line>
  line>prefix=
 Variable declaration, 'prefix' overridden with 'D:/M/mingw-w64-gstreamer/src'
  line>exec_prefix=
 Variable declaration, 'exec_prefix' has value ''
  line>libdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs
 Variable declaration, 'libdir' has value 'D:/M/mingw-w64-gstreamer/src/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs'
  line>

Further research shows that this is caused by pkg-config being compiled with ENABLE_DEFINE_PREFIX enabled.
This will make pkg-config guess the prefix value.
And if the the libdir starts with the original prefix (empty in my case) it will prepend the libdir with the guessed prefix. Net result is wacky and gstreamer fails to compile.
Comment 1 Dan Nicholson 2016-08-23 17:30:34 UTC
That is messed up. The prefix redefinition shouldn't be happening if the original prefix setting is NULL.

What version of pkg-config is this? Can you attach the entire --debug output?

It's entirely possible that the --define-prefix behavior is wrong for msys2. That currently defaults to enabled when the pkg-config build host is "*-*-mingw*".
Comment 2 Dan Nicholson 2016-08-23 17:35:47 UTC
Oh, wait. Isn't msys2 using pkgconf? I don't think this is a pkg-config bug. This would work correctly in pkg-config for 2 reasons:

1. The prefix redefinition only occurs by default if the pc file is in a directory called "pkgconfig". This is a heuristic to try to only do prefix redefinition when operating on installed pc files.

2. The prefix redefinition is skipped if the original prefix is NULL.

Please reopen if this is really pkg-config.
Comment 3 philippe_renon 2016-08-24 09:37:05 UTC
Reopening as msys2 does use pkg-config. I have no pkgconf installed in my msys2 setup (although there is a pkgconf package available).

Please also note that I reproduce the issue when using pkg-config directly on the command line.

$ pkg-config --version
0.29.1

$ pkg-config --libs gstreamer-1.0-uninstalled
-LD:/msys64/mingw64/lib -LD:/M/mingw-w64-gstreamer/src/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl

Note that :
- gstreamer-1.0-uninstalled.pc file is located in a pkgconfig directory
- the gstreamer-1.0-uninstalled.pc file has this line "prefix="
Looks like the original prefix is not NULL but an empty string, which triggers the issue.
Comment 4 philippe_renon 2016-08-24 09:39:42 UTC
Created attachment 125994 [details]
full debug output

Attached full debug output of: 

pkg-config --debug --libs gstreamer-1.0-uninstalled
Comment 5 philippe_renon 2016-08-24 09:41:48 UTC
Created attachment 125995 [details]
full debug output
Comment 6 philippe_renon 2016-08-24 09:42:55 UTC
Created attachment 125996 [details]
full debug output

correct one this time... sorry for the noise.
Comment 7 Dan Nicholson 2016-08-24 17:35:54 UTC
Created attachment 126012 [details] [review]
Don't override empty prefix setting

If the original prefix setting is empty, skip prepending the redefined
prefix to other variables. This works the same as if the pc file doesn't
have a prefix variable at all.

https://bugs.freedesktop.org/show_bug.cgi?id=97453-empty
Comment 8 Dan Nicholson 2016-08-24 17:38:16 UTC
Right. I was thinking that empty and not set would be handled the same in the code, but that was wrong. Can you try attachment 126012 [details] [review]?
Comment 9 philippe_renon 2016-08-25 12:41:59 UTC
With the patch there is one failed test:

../pkg-config.exe --cflags public-dep :
'-I/sysroot/public-dep/include' != '-ID:/msys64//sysroot/public-dep/include'
FAIL: check-sysroot
...
1 of 28 tests failed


There is also a minor issue when applying the patch:

patching file check/Makefile.am
Hunk #1 succeeded at 98 (offset -1 lines).
patching file check/check-relocatable
patching file check/pkgconfig/empty-prefix.pc
patching file parse.c
patch unexpectedly ends in middle of line

but the patch is applied fine nonetheless.
Comment 10 philippe_renon 2016-08-25 12:56:40 UTC
Oddly, it fails in the same manner without the patch.
Comment 11 Dan Nicholson 2016-08-25 13:17:39 UTC
When you say fails in the same manner, are you referring to the check-sysroot test? If so, I'm not surprised. This patch shouldn't affect that behavior. The test may not be looking for the right result on msys2. I wouldn't worry about that one.

Does the patch fix your gstreamer case?
Comment 12 philippe_renon 2016-08-25 13:47:20 UTC
Yes, the build fails the check-sysroot test with and withour your patch.

Hacking line 12 of the check-sysroot file so it leaves the root variable empty allows the build to complete successfully.

And with this version of pkg-config, gstreamer 1.8.2 still fails.

../../../libtool: line 7537: cd: ../../D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs: No such file or directory
libtool:   error: cannot determine absolute directory name of '../../D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs'


I don't have the spurious prefix prepended anymore. But I have a ../.. prepended... Don't know where that one comes from (and I think it was there too before your fix).
Comment 13 philippe_renon 2016-08-25 14:58:51 UTC
Ok. I am bit lost atm and will need to do more research.

The step that fails when compiling gstreamer is related to g-ir-scanner:

GstBase-1.0.gir: $(INTROSPECTION_SCANNER) libgstbase-1.0.la
	$(AM_V_GEN)PKG_CONFIG_PATH="$(GST_PKG_CONFIG_PATH)" GI_SCANNER_DISABLE_CACHE=yes\
		GST_PLUGIN_SYSTEM_PATH_1_0="" GST_PLUGIN_PATH_1_0="" GST_REGISTRY_UPDATE=no \
		$(INTROSPECTION_SCANNER) -v --namespace GstBase \
		--nsversion=1.0 \
		--warn-all \
		--identifier-prefix=Gst \
		--symbol-prefix=gst \
		-I$(top_srcdir) \
		-I$(top_srcdir)/libs \
		-I$(top_builddir) \
		-I$(top_builddir)/libs \
		--c-include "gst/base/base.h" \
		--add-include-path=$(top_builddir)/gst \
		--library-path=$(top_builddir)/gst \
		--library=libgstbase-1.0.la \
		--include=Gst-1.0 \
		--libtool="${LIBTOOL}" \
		--pkg gstreamer-1.0 \
		--pkg-export gstreamer-base-1.0 \
		--add-init-section="$(INTROSPECTION_INIT)" \
		--output $@ \
		$(gir_headers) \
		$(gir_sources)

I don't know what it does with --pkg arguments (i.e. if and how it uses pkg-config).
Comment 14 philippe_renon 2016-08-25 16:44:06 UTC
$ export PKG_CONFIG_PATH="../../../pkgconfig:/mingw64/lib/pkgconfig"

$ pkg-config --libs gstreamer-1.0-uninstalled
-L../../D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs -LD:/msys64/mingw64/lib -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl

$ pkg-config --dont-define-prefix --libs gstreamer-1.0-uninstalled
-L/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl



With gstreamer-1.0-uninstalled.pc:

# the standard variables don't make sense for an uninstalled copy
prefix=
exec_prefix=
libdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs
# includedir is builddir because it is used to find gstconfig.h in places
includedir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32
toolsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/tools
pluginsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32
girdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst
completionsdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/data/completions
helpersdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/libs/gst/helpers
typelibdir=/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst

Name: GStreamer Uninstalled
Description: Streaming media framework, Not Installed
Version: 1.8.2
Requires: glib-2.0, gobject-2.0
Requires.private: gmodule-no-export-2.0
Libs: -L${libdir} -lgstreamer-1.0
Cflags: -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/../gstreamer-1.8.2 -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/../gstreamer-1.8.2/libs -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32 -I/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/libs



If I force the value used in Libs (without using ${libdir} then I get the correct result with and without the --dont-define-prefix option.

$ pkg-config --libs gstreamer-1.0-uninstalled
-L/D/M/mingw-w64-gstreamer/src/build-x86_64-w64-mingw32/gst/.libs -LD:/msys64/mingw64/lib -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl



What is strange is that msys2 as a patch to force g-ir-introspection to use the --dont-define-prefix flag (https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-gobject-introspection/0022-change-pkg-config-invocations.mingw.patch). Seems to be broken somehow.
Comment 15 philippe_renon 2016-08-25 16:45:01 UTC
PS : message just above is with the patched pkg-config.
Comment 16 philippe_renon 2016-08-25 16:51:05 UTC
Seems like the patched version is installed only for msys2 shell and not mingw64 shell. Duh!
Comment 17 philippe_renon 2016-08-26 15:08:31 UTC
gstreamer compiles fine with the patched pkg-config. Thanks!
Comment 18 philippe_renon 2016-08-30 14:02:28 UTC
Hi,

What is the release policy/frequency of pkg-config ?

Should I wait for a new release with a fix for this issue or proceed to patch msys2 ?
Comment 19 Dan Nicholson 2016-08-30 16:44:57 UTC
Pushed in commit bbbdab4 - https://cgit.freedesktop.org/pkg-config/commit/?id=bbbdab4.

I do the releases basically when I have time :) There are a couple more fixes I'd like to get in for the next release, so it'll probably be a couple more weeks. If you need this now, I'd add the patch to msys2. Since it's a one liner, it will be easy to spot that it's not needed when updating.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.