pkgconf --list-all includes extra '/' character in front of each package name on Windows #209

Closed
opened 2021-02-02 11:46:19 +00:00 by RyanGlScott · 2 comments
RyanGlScott commented 2021-02-02 11:46:19 +00:00 (Migrated from github.com)

On Windows, running pkgconf --list-all prints the name of each package with an extra / character at the front:

$ ./pkgconf.exe --version
1.7.3

$ ./pkgconf.exe --list-all | sort
/bzip2                         bzip2 - Lossless, block-sorting data compression
/expat                         expat - expat XML parser
/formw                         formw - ncurses 6.2 add-on library
/gmp                           GNU MP - GNU Multiple Precision Arithmetic Library
/gmpxx                         GNU MP C++ - GNU Multiple Precision Arithmetic Library (C++ bindings)
/gnurx                         regex - Regular Expressions library
/hogweed                       Hogweed - Nettle low-level cryptographic library (public-key algorithms)
/iconv                         iconv - libiconv
/isl                           isl - isl Library
/jansson                       Jansson - Library for encoding, decoding and manipulating JSON data
/jemalloc                      jemalloc - A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.
/libbrotlicommon               libbrotlicommon - Brotli common dictionary library
/libbrotlidec                  libbrotlidec - Brotli decoder library
/libbrotlienc                  libbrotlienc - Brotli encoder library
/libcares                      c-ares - asynchronous DNS lookup library
/libcares-static               c-ares-static - asynchronous DNS lookup library
/libcrypto                     OpenSSL-libcrypto - OpenSSL cryptography library
/libcurl                       libcurl - Library to transfer files with ftp, http, etc.
/libffi                        libffi - Library supporting Foreign Function Interfaces
/libidn2                       libidn2 - Library implementing IDNA2008 and TR46
/liblz4                        lz4 - extremely fast lossless compression algorithm library
/liblzma                       liblzma - General purpose data compression library
/libmetalink                   libmetalink - Metalink library
/libnghttp2                    libnghttp2 - HTTP/2 C library
/libpsl                        libpsl - Public Suffix List C library
/libssh2                       libssh2 - Library for SSH-based communication
/libssl                        OpenSSL-libssl - Secure Sockets Layer and cryptography libraries
/libtasn1                      libtasn1 - Library for ASN.1 and DER manipulation
/libzstd                       zstd - fast lossless compression algorithm library
/menuw                         menuw - ncurses 6.2 add-on library
/mpfr                          mpfr - C library for multiple-precision floating-point computations
/ncurses++w                    ncurses++w - ncurses 6.2 add-on library
/ncursesw                      ncursesw - ncurses 6.2 library
/nettle                        Nettle - Nettle low-level cryptographic library (symmetric algorithms)
/openssl                       OpenSSL - Secure Sockets Layer and cryptography libraries and tools
/p11-kit-1                     p11-kit - Library and proxy module for properly loading and sharing PKCS
/panelw                        panelw - ncurses 6.2 add-on library
/python-3.8                    Python - Build a C extension for Python
/python-3.8-embed              Python - Embed Python into an application
/python3                       Python - Build a C extension for Python
/python3-embed                 Python - Embed Python into an application
/readline                      Readline - Gnu Readline library for command line editing
/regex                         regex - Regular Expressions library
/sdl2                          sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
/sqlite3                       SQLite - SQL database engine
/termcap                       Termcap - GNU Termcap library and data base that enables programs to use display terminals in a terminal-independent manner
/tre                           TRE - TRE regexp matching library
/vulkan                        Vulkan-Loader - Vulkan Loader
/zlib                          zlib - zlib compression library

Compare this to the output of pkg-config --list-all:

$ pkg-config.exe --list-all | sort
bzip2            bzip2 - Lossless, block-sorting data compression
expat            expat - expat XML parser
formw            formw - ncurses 6.2 add-on library
gmp              GNU MP - GNU Multiple Precision Arithmetic Library
gmpxx            GNU MP C++ - GNU Multiple Precision Arithmetic Library (C++ bindings)
gnurx            regex - Regular Expressions library
hogweed          Hogweed - Nettle low-level cryptographic library (public-key algorithms)
iconv            iconv - libiconv
isl              isl - isl Library
jansson          Jansson - Library for encoding, decoding and manipulating JSON data
jemalloc         jemalloc - A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.
libbrotlicommon  libbrotlicommon - Brotli common dictionary library
libbrotlidec     libbrotlidec - Brotli decoder library
libbrotlienc     libbrotlienc - Brotli encoder library
libcares         c-ares - asynchronous DNS lookup library
libcares-static  c-ares-static - asynchronous DNS lookup library
libcrypto        OpenSSL-libcrypto - OpenSSL cryptography library
libcurl          libcurl - Library to transfer files with ftp, http, etc.
libffi           libffi - Library supporting Foreign Function Interfaces
libidn2          libidn2 - Library implementing IDNA2008 and TR46
liblz4           lz4 - extremely fast lossless compression algorithm library
liblzma          liblzma - General purpose data compression library
libmetalink      libmetalink - Metalink library
libnghttp2       libnghttp2 - HTTP/2 C library
libpsl           libpsl - Public Suffix List C library
libssh2          libssh2 - Library for SSH-based communication
libssl           OpenSSL-libssl - Secure Sockets Layer and cryptography libraries
libtasn1         libtasn1 - Library for ASN.1 and DER manipulation
libzstd          zstd - fast lossless compression algorithm library
menuw            menuw - ncurses 6.2 add-on library
mpfr             mpfr - C library for multiple-precision floating-point computations
ncurses++w       ncurses++w - ncurses 6.2 add-on library
ncursesw         ncursesw - ncurses 6.2 library
nettle           Nettle - Nettle low-level cryptographic library (symmetric algorithms)
openssl          OpenSSL - Secure Sockets Layer and cryptography libraries and tools
p11-kit-1        p11-kit - Library and proxy module for properly loading and sharing PKCS
panelw           panelw - ncurses 6.2 add-on library
python-3.8       Python - Build a C extension for Python
python-3.8-embed Python - Embed Python into an application
python3          Python - Build a C extension for Python
python3-embed    Python - Embed Python into an application
readline         Readline - Gnu Readline library for command line editing
regex            regex - Regular Expressions library
sdl2             sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
sqlite3          SQLite - SQL database engine
termcap          Termcap - GNU Termcap library and data base that enables programs to use display terminals in a terminal-independent manner
tre              TRE - TRE regexp matching library
vulkan           Vulkan-Loader - Vulkan Loader
zlib             zlib - zlib compression library

This isn't just a cosmetic issue, as the cabal-install tool, which uses pkg-config --list-all to determine what packages are available, fails to parse when the extra / is present. As a result, it's impossible to use cabal-install with pkg-config symlinked to pkgconf.

On Windows, running `pkgconf --list-all` prints the name of each package with an extra `/` character at the front: ``` $ ./pkgconf.exe --version 1.7.3 $ ./pkgconf.exe --list-all | sort /bzip2 bzip2 - Lossless, block-sorting data compression /expat expat - expat XML parser /formw formw - ncurses 6.2 add-on library /gmp GNU MP - GNU Multiple Precision Arithmetic Library /gmpxx GNU MP C++ - GNU Multiple Precision Arithmetic Library (C++ bindings) /gnurx regex - Regular Expressions library /hogweed Hogweed - Nettle low-level cryptographic library (public-key algorithms) /iconv iconv - libiconv /isl isl - isl Library /jansson Jansson - Library for encoding, decoding and manipulating JSON data /jemalloc jemalloc - A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. /libbrotlicommon libbrotlicommon - Brotli common dictionary library /libbrotlidec libbrotlidec - Brotli decoder library /libbrotlienc libbrotlienc - Brotli encoder library /libcares c-ares - asynchronous DNS lookup library /libcares-static c-ares-static - asynchronous DNS lookup library /libcrypto OpenSSL-libcrypto - OpenSSL cryptography library /libcurl libcurl - Library to transfer files with ftp, http, etc. /libffi libffi - Library supporting Foreign Function Interfaces /libidn2 libidn2 - Library implementing IDNA2008 and TR46 /liblz4 lz4 - extremely fast lossless compression algorithm library /liblzma liblzma - General purpose data compression library /libmetalink libmetalink - Metalink library /libnghttp2 libnghttp2 - HTTP/2 C library /libpsl libpsl - Public Suffix List C library /libssh2 libssh2 - Library for SSH-based communication /libssl OpenSSL-libssl - Secure Sockets Layer and cryptography libraries /libtasn1 libtasn1 - Library for ASN.1 and DER manipulation /libzstd zstd - fast lossless compression algorithm library /menuw menuw - ncurses 6.2 add-on library /mpfr mpfr - C library for multiple-precision floating-point computations /ncurses++w ncurses++w - ncurses 6.2 add-on library /ncursesw ncursesw - ncurses 6.2 library /nettle Nettle - Nettle low-level cryptographic library (symmetric algorithms) /openssl OpenSSL - Secure Sockets Layer and cryptography libraries and tools /p11-kit-1 p11-kit - Library and proxy module for properly loading and sharing PKCS /panelw panelw - ncurses 6.2 add-on library /python-3.8 Python - Build a C extension for Python /python-3.8-embed Python - Embed Python into an application /python3 Python - Build a C extension for Python /python3-embed Python - Embed Python into an application /readline Readline - Gnu Readline library for command line editing /regex regex - Regular Expressions library /sdl2 sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. /sqlite3 SQLite - SQL database engine /termcap Termcap - GNU Termcap library and data base that enables programs to use display terminals in a terminal-independent manner /tre TRE - TRE regexp matching library /vulkan Vulkan-Loader - Vulkan Loader /zlib zlib - zlib compression library ``` Compare this to the output of `pkg-config --list-all`: ``` $ pkg-config.exe --list-all | sort bzip2 bzip2 - Lossless, block-sorting data compression expat expat - expat XML parser formw formw - ncurses 6.2 add-on library gmp GNU MP - GNU Multiple Precision Arithmetic Library gmpxx GNU MP C++ - GNU Multiple Precision Arithmetic Library (C++ bindings) gnurx regex - Regular Expressions library hogweed Hogweed - Nettle low-level cryptographic library (public-key algorithms) iconv iconv - libiconv isl isl - isl Library jansson Jansson - Library for encoding, decoding and manipulating JSON data jemalloc jemalloc - A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. libbrotlicommon libbrotlicommon - Brotli common dictionary library libbrotlidec libbrotlidec - Brotli decoder library libbrotlienc libbrotlienc - Brotli encoder library libcares c-ares - asynchronous DNS lookup library libcares-static c-ares-static - asynchronous DNS lookup library libcrypto OpenSSL-libcrypto - OpenSSL cryptography library libcurl libcurl - Library to transfer files with ftp, http, etc. libffi libffi - Library supporting Foreign Function Interfaces libidn2 libidn2 - Library implementing IDNA2008 and TR46 liblz4 lz4 - extremely fast lossless compression algorithm library liblzma liblzma - General purpose data compression library libmetalink libmetalink - Metalink library libnghttp2 libnghttp2 - HTTP/2 C library libpsl libpsl - Public Suffix List C library libssh2 libssh2 - Library for SSH-based communication libssl OpenSSL-libssl - Secure Sockets Layer and cryptography libraries libtasn1 libtasn1 - Library for ASN.1 and DER manipulation libzstd zstd - fast lossless compression algorithm library menuw menuw - ncurses 6.2 add-on library mpfr mpfr - C library for multiple-precision floating-point computations ncurses++w ncurses++w - ncurses 6.2 add-on library ncursesw ncursesw - ncurses 6.2 library nettle Nettle - Nettle low-level cryptographic library (symmetric algorithms) openssl OpenSSL - Secure Sockets Layer and cryptography libraries and tools p11-kit-1 p11-kit - Library and proxy module for properly loading and sharing PKCS panelw panelw - ncurses 6.2 add-on library python-3.8 Python - Build a C extension for Python python-3.8-embed Python - Embed Python into an application python3 Python - Build a C extension for Python python3-embed Python - Embed Python into an application readline Readline - Gnu Readline library for command line editing regex regex - Regular Expressions library sdl2 sdl2 - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. sqlite3 SQLite - SQL database engine termcap Termcap - GNU Termcap library and data base that enables programs to use display terminals in a terminal-independent manner tre TRE - TRE regexp matching library vulkan Vulkan-Loader - Vulkan Loader zlib zlib - zlib compression library ``` This isn't just a cosmetic issue, as the `cabal-install` tool, which [uses `pkg-config --list-all` to determine what packages are available](https://cabal.readthedocs.io/en/3.4/cabal-package.html#pkg-field-pkgconfig-depends), fails to parse when the extra `/` is present. As a result, it's impossible to use `cabal-install` with `pkg-config` symlinked to `pkgconf`.
RyanGlScott commented 2021-02-02 12:43:11 +00:00 (Migrated from github.com)

I am not at all familiar with the codebase, but I took a shot at attempting to diagnose the issue. I've narrowed down to this code:

869f2a84d6/libpkgconf/pkg.c (L387-L400)

The pkg->id = strdup(idptr); part is where a string like /sdl2.pc is given to a particular pkg, and the two lines after that remove the .pc extension, leaving just /sdl2. Before the #ifdef _WIN32 part, idptr is an absolute path like C:/msys64/mingw64/lib/pkgconfig/sdl2.pc, so that part of the code removes everything up to (but not including) the last / character. Why doesn't it remove the last / character? I think it's because of this line:

869f2a84d6/libpkgconf/pkg.c (L394)

If I'm reading that correctly, this will make idptr point to the same string as mungeptr and then increment mungeptr's address. For example, if mungeptr is /sdl2.pc before this line of code, then afterwards idptr will be /sdl2.pc and mungeptr will be sdl2.pc. This means that mungeptr actually points to the string that we want, but mungeptr is never used again after this line of code.

One possible fix would be to increment mungeptr before assigning it to idptr, like so:

diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c
index 02c990d..f302df3 100644
--- a/libpkgconf/pkg.c
+++ b/libpkgconf/pkg.c
@@ -391,7 +391,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
         */
        char *mungeptr;
        if ((mungeptr = strrchr(idptr, '/')) != NULL)
-               idptr = mungeptr++;
+               idptr = ++mungeptr;
 #endif

        pkg->id = strdup(idptr);

This fixes the issue for me locally.

I am not at all familiar with the codebase, but I took a shot at attempting to diagnose the issue. I've narrowed down to this code: https://github.com/pkgconf/pkgconf/blob/869f2a84d68b34a00c34e3434dffd76cd48a4a06/libpkgconf/pkg.c#L387-L400 The `pkg->id = strdup(idptr);` part is where a string like `/sdl2.pc` is given to a particular `pkg`, and the two lines after that remove the `.pc` extension, leaving just `/sdl2`. Before the `#ifdef _WIN32` part, `idptr` is an absolute path like `C:/msys64/mingw64/lib/pkgconfig/sdl2.pc`, so that part of the code removes everything up to (but not including) the last `/` character. Why doesn't it remove the last `/` character? I think it's because of this line: https://github.com/pkgconf/pkgconf/blob/869f2a84d68b34a00c34e3434dffd76cd48a4a06/libpkgconf/pkg.c#L394 If I'm reading that correctly, this will make `idptr` point to the same string as `mungeptr` and _then_ increment `mungeptr`'s address. For example, if `mungeptr` is `/sdl2.pc` before this line of code, then afterwards `idptr` will be `/sdl2.pc` and `mungeptr` will be `sdl2.pc`. This means that `mungeptr` actually points to the string that we want, but `mungeptr` is never used again after this line of code. One possible fix would be to increment `mungeptr` _before_ assigning it to `idptr`, like so: ```diff diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 02c990d..f302df3 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -391,7 +391,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE * */ char *mungeptr; if ((mungeptr = strrchr(idptr, '/')) != NULL) - idptr = mungeptr++; + idptr = ++mungeptr; #endif pkg->id = strdup(idptr); ``` This fixes the issue for me locally.
RyanGlScott commented 2021-02-04 12:29:05 +00:00 (Migrated from github.com)

See #210.

See #210.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ariadne/pkgconf#209
There is no content yet.