Re: pkg-config tweaks
A bit more pkg-config tweaks. - I missed two anonymous subs. - somehow I did mangle the flags with respect to --libs-only-other - so I added regress tests for those. - I found out that stuff like --libs-only-l will tend to prepend a space like -lalpha2 turns out the glib2 version of pkg-config doesn't, so I fixed that (not that hard to do, it's just a question of having do_libs return a proper list with only existing elements) - also found a warning message wrt -stable in the regress test now, support for an extra suffix shouldn't be too hard. But seeing duplicate code for suffixes handling made me cringe so much I had to fix it. Please test :) Hopefully the last iteration. Index: regress/usr.bin/pkg-config/Makefile === RCS file: /cvs/src/regress/usr.bin/pkg-config/Makefile,v retrieving revision 1.62 diff -u -p -r1.62 Makefile --- regress/usr.bin/pkg-config/Makefile 15 Sep 2020 07:19:31 - 1.62 +++ regress/usr.bin/pkg-config/Makefile 5 Jun 2023 08:05:19 - @@ -101,7 +101,12 @@ REGRESS_TARGETS=cmp-vers1-1 \ filter-system-dirs-5 \ filter-system-dirs-6 \ cflags-system-path-1 \ - cflags-system-path-2 + cflags-system-path-2 \ + lib-flags-1 \ + lib-flags-2 \ + lib-flags-3 \ + lib-flags-4 \ + PKG_CONFIG?= /usr/bin/pkg-config PCONFIG = PKG_CONFIG_PATH=${.CURDIR}/pcdir/ ${PKG_CONFIG} @@ -329,7 +334,7 @@ cmp-vers5-10: cmp-vers6-1: # Test suffixed versions in Requires - @echo " -lalpha2" > ${WANT} + @echo "-lalpha2" > ${WANT} @${VPCONFIG} --libs requires-test2 @diff -u ${WANT} ${GOT} @@ -474,7 +479,7 @@ whitespace-libs: whitespace-linebreak: # Test linebreak in Description field - @echo " -lc" > ${WANT} + @echo "-lc" > ${WANT} @${VPCONFIG} --libs linebreak @diff -u ${WANT} ${GOT} @@ -631,19 +636,19 @@ variables-4: variables-5: # Test --variable - @echo ' -lfoo-1' > ${WANT} + @echo '-lfoo-1' > ${WANT} @${VPCONFIG} --libs variables @diff -u ${WANT} ${GOT} variables-6: # Test variable overriding from environment - @echo ' -lfoo-2' > ${WANT} + @echo '-lfoo-2' > ${WANT} @PKG_CONFIG_VARIABLES_FOO_API_VERSION=2 ${VPCONFIG} --libs variables @diff -u ${WANT} ${GOT} variables-7: # Ensure variable overriding only uses uppercase keys - @echo ' -lfoo-1' > ${WANT} + @echo '-lfoo-1' > ${WANT} @PKG_CONFIG_variables_foo_api_version=2 ${VPCONFIG} --libs variables @diff -u ${WANT} ${GOT} @@ -655,13 +660,13 @@ filter-system-dirs-1: filter-system-dirs-2: # Test removing -L/usr/lib as a system directory - @echo ' -lfilter' > ${WANT} + @echo '-lfilter' > ${WANT} @${VPCONFIG} --libs filter @diff -u ${WANT} ${GOT} filter-system-dirs-3: # Test removing -L/usr/lib as a system directory (static) - @echo ' -lfilter -lprivate-filter' > ${WANT} + @echo '-lfilter -lprivate-filter' > ${WANT} @${VPCONFIG} --static --libs filter @diff -u ${WANT} ${GOT} @@ -697,6 +702,30 @@ cflags-system-path-2: clean: rm -f *.want *.got + +lib-flags-1: + # Test --libs-only-other + @echo "-pthread" > ${WANT} + @${VPCONFIG} --libs-only-other lib-flags + @diff -u ${WANT} ${GOT} + +lib-flags-2: + # Test --libs + @echo "-L/usr/local/lib -pthread -lalpha2" > ${WANT} + @${VPCONFIG} --libs lib-flags + @diff -u ${WANT} ${GOT} + +lib-flags-3: + # Test --libs-only-L + @echo "-L/usr/local/lib" > ${WANT} + @${VPCONFIG} --libs-only-L lib-flags + @diff -u ${WANT} ${GOT} + +lib-flags-4: + # Test --libs-only-l + @echo "-lalpha2" > ${WANT} + @${VPCONFIG} --libs-only-l lib-flags + @diff -u ${WANT} ${GOT} .PHONY: ${REGRESS_TARGETS} Index: regress/usr.bin/pkg-config/pcdir/lib-flags.pc === RCS file: regress/usr.bin/pkg-config/pcdir/lib-flags.pc diff -N regress/usr.bin/pkg-config/pcdir/lib-flags.pc --- /dev/null 1 Jan 1970 00:00:00 - +++ regress/usr.bin/pkg-config/pcdir/lib-flags.pc 5 Jun 2023 08:05:19 - @@ -0,0 +1,4 @@ +Name: lib separation test +Description: pkg-config(1) regress file +Version: 0.0 +Libs: -lalpha2 -L/usr/local/lib -pthread Index: usr.bin/pkg-config/pkg-config === RCS file: /cvs/src/usr.bin/pkg-config/pkg-config,v retrieving revision 1.95 diff -u -p -r1.95 pkg-config --- usr.bin/pkg-config/pkg-config 15 Sep 2020 07:18:45 - 1.95 +++ usr.bin/pkg-config/pkg-config 5 Jun
Re: pkg-config tweaks
There was a small typo which broke xenocara, as noticed by tb@ (sidenote: I hate this shitty configure stuff that can't even give you the warning messages from tools that ran. *OF COURSE* it's because so much of that shit talks incessantly even when things are fine) Index: pkg-config === RCS file: /cvs/src/usr.bin/pkg-config/pkg-config,v retrieving revision 1.95 diff -u -p -r1.95 pkg-config --- pkg-config 15 Sep 2020 07:18:45 - 1.95 +++ pkg-config 26 May 2023 09:40:46 - @@ -16,14 +16,20 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use strict; -use warnings; +use v5.36; use Config; use Getopt::Long; use File::Basename; use File::stat; use OpenBSD::PkgConfig; +use constant { + ONLY_I => 1, + ONLY_l => 2, + ONLY_L => 4, + ONLY_OTHER => 8 +}; + my @PKGPATH = qw(/usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig @@ -70,7 +76,7 @@ defined $ENV{PKG_CONFIG_DEBUG_SPEW} ? $m if ($logfile) { open my $L, ">>" , $logfile or die; - print $L beautify_list($0, @ARGV), "\n"; + say $L beautify_list($0, @ARGV); close $L; } @@ -87,7 +93,7 @@ GetOptions( 'debug' => \$mode{debug}, 'help' => \, #does not return 'usage' => \, #does not return 'list-all' => \$mode{list}, - 'version' => sub { print "$version\n" ; exit(0);} , + 'version' => sub { say $version ; exit(0);} , 'errors-to-stdout' => sub { $mode{estdout} = 1}, 'print-errors' => sub { $mode{printerr} = 1}, 'silence-errors'=> sub { $mode{printerr} = 0}, @@ -97,13 +103,13 @@ GetOptions('debug' => \$mode{debug}, 'print-requires'=> \$mode{printrequires}, 'print-requires-private' => \$mode{printrequiresprivate}, - 'cflags'=> sub { $mode{cflags} = 3}, - 'cflags-only-I' => sub { $mode{cflags} |= 1}, - 'cflags-only-other' => sub { $mode{cflags} |= 2}, - 'libs' => sub { $mode{libs} = 7}, - 'libs-only-l' => sub { $mode{libs} |= 1}, - 'libs-only-L' => sub { $mode{libs} |= 2}, - 'libs-only-other' => sub { $mode{libs} |= 4}, + 'cflags'=> sub { $mode{cflags} = ONLY_I|ONLY_OTHER}, + 'cflags-only-I' => sub { $mode{cflags} |= ONLY_I}, + 'cflags-only-other' => sub { $mode{cflags} |= ONLY_OTHER}, + 'libs' => sub { $mode{libs} = ONLY_L|ONLY_l|ONLY_OTHER}, + 'libs-only-l' => sub { $mode{libs} |= ONLY_l}, + 'libs-only-L' => sub { $mode{libs} |= ONLY_L}, + 'libs-only-other' => sub { $mode{libs} |= ONLY_OTHER}, 'exists'=> sub { $mode{exists} = 1} , 'validate' => sub { $mode{validate} = 1}, 'static'=> sub { $mode{static} = 1}, @@ -178,9 +184,9 @@ sub get_next_module if ($module =~ m/,/) { my @ms = split(/,/, $module); $m = shift @ms; - unshift(@ARGV, @ms) if (scalar(@ms) > 0); + unshift(@ARGV, @ms) if @ms != 0; } else { - return $module; + return $module; } return $m; @@ -267,16 +273,15 @@ if ($mode{static}){ if ($mode{cflags} || $mode{libs} || $mode{variable}) { push @vlist, do_cflags($dep_cfg_list) if $mode{cflags}; push @vlist, do_libs($dep_cfg_list) if $mode{libs}; - print join(' ', @vlist), "\n" if $rc == 0; + say join(' ', @vlist) if $rc == 0; } exit $rc; ### -sub handle_config +sub handle_config($p, $op, $v, $list) { - my ($p, $op, $v, $list) = @_; my $cfg = cache_find_config($p); unshift @$list, $p if defined $cfg; @@ -316,7 +321,7 @@ sub handle_config my $deps = $cfg->get_property($property, $variables); return unless defined $deps; for my $dep (@$deps) { - if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+|[\d\.]+[\w]*[\d]+)$/) { + if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+|[\d\.]+\w*\d+)$/) { handle_config($1, $2, $3, $list); } else { handle_config($dep, undef, undef, $list); @@ -339,10 +344,8 @@ sub handle_config # look for the .pc file in each of the PKGPATH elements.
Re: pkg-config tweaks
On Mon, May 22, 2023 at 09:33:48AM +0200, Marc Espie wrote: > - move to 5.36: signatures + prototypes mostly everywhere > Not used for Getopt::Long, because the calling conventions are somewhat > too verbose. > - use constant for the mode{libs} and mode{cflags} values > - remove two completely unneeded [] in regexps > - fix indentation and parentheses in a few locations > > > There should be no behavior change, please test. Mostly this seems OK. There is one that isn't a behavior change, but using $a and $b as names can sometimes cause confusing behavior, so I generally try to avoid those names. https://perldoc.perl.org/perlvar#$a Changing the flag values from what they were makes it really hard for me to tell if they are right. I think they all seem to have translated properly, but wow, the new stuff is so much easier to read, I'm glad it changed, but it was hard to review! The rest _looked_ right, but I may have missed a typo. If so I expect that would be obvious on running it. > Deeper question: as it stands \w and such do handle unicode, more or less. > Is this something we actually want/need in pkg-config ? should we look at > restricting the regexps through one of the locale modifiers ? I assume we'll only want to support UTF-8, which is probably just adding the "standard preamble" to switch undeclared file streams to use the UTF-8 encoding. https://perldoc.perl.org/perlunicook#%E2%84%9E-0:-Standard-preamble https://perldoc.perl.org/perlunicook#%E2%84%9E-17:-Make-file-I/O-default-to-utf8 We can also switch the regex character classes to be limited to ascii. https://perldoc.perl.org/perlunicook#%E2%84%9E-24:-Disabling-Unicode-awareness-in-builtin-charclasses I don't know enough about when pkg-config might encounter anything that isn't ascii, so it's hard for me to say what the right answer is. > > Index: pkg-config > === > RCS file: /cvs/src/usr.bin/pkg-config/pkg-config,v > retrieving revision 1.95 > diff -u -p -r1.95 pkg-config > --- pkg-config15 Sep 2020 07:18:45 - 1.95 > +++ pkg-config22 May 2023 07:22:10 - > @@ -16,14 +16,20 @@ > # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF > # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > > -use strict; > -use warnings; > +use v5.36; > use Config; > use Getopt::Long; > use File::Basename; > use File::stat; > use OpenBSD::PkgConfig; > > +use constant { > + ONLY_I => 1, > + ONLY_l => 2, > + ONLY_L => 4, > + ONLY_OTHER => 8 > +}; > + > my @PKGPATH = qw(/usr/lib/pkgconfig >/usr/local/lib/pkgconfig >/usr/local/share/pkgconfig > @@ -70,7 +76,7 @@ defined $ENV{PKG_CONFIG_DEBUG_SPEW} ? $m > > if ($logfile) { > open my $L, ">>" , $logfile or die; > - print $L beautify_list($0, @ARGV), "\n"; > + say $L beautify_list($0, @ARGV); > close $L; > } > > @@ -87,7 +93,7 @@ GetOptions( 'debug' => \$mode{debug}, > 'help' => \, #does not return > 'usage' => \, #does not return > 'list-all' => \$mode{list}, > - 'version' => sub { print "$version\n" ; exit(0);} > , > + 'version' => sub { say $version ; exit(0);} , > 'errors-to-stdout' => sub { $mode{estdout} = 1}, > 'print-errors' => sub { $mode{printerr} = 1}, > 'silence-errors'=> sub { $mode{printerr} = 0}, > @@ -97,13 +103,13 @@ GetOptions( 'debug' => > \$mode{debug}, > 'print-requires'=> \$mode{printrequires}, > 'print-requires-private' => \$mode{printrequiresprivate}, > > - 'cflags'=> sub { $mode{cflags} = 3}, > - 'cflags-only-I' => sub { $mode{cflags} |= 1}, > - 'cflags-only-other' => sub { $mode{cflags} |= 2}, > - 'libs' => sub { $mode{libs} = 7}, > - 'libs-only-l' => sub { $mode{libs} |= 1}, > - 'libs-only-L' => sub { $mode{libs} |= 2}, > - 'libs-only-other' => sub { $mode{libs} |= 4}, > + 'cflags'=> sub { $mode{cflags} = > ONLY_I|ONLY_OTHER}, > + 'cflags-only-I' => sub { $mode{cflags} |= ONLY_I}, > + 'cflags-only-other' => sub { $mode{cflags} |= ONLY_OTHER}, > + 'libs' => sub { $mode{libs} = > ONLY_L|ONLY_l|ONLY_OTHER}, > + 'libs-only-l' => sub { $mode{libs} |= ONLY_l}, > + 'libs-only-L' => sub { $mode{libs} |= ONLY_L}, > + 'libs-only-other' => sub { $mode{libs} |= ONLY_OTHER}, > 'exists'=> sub { $mode{exists} = 1} , > 'validate' => sub {
pkg-config tweaks
- move to 5.36: signatures + prototypes mostly everywhere Not used for Getopt::Long, because the calling conventions are somewhat too verbose. - use constant for the mode{libs} and mode{cflags} values - remove two completely unneeded [] in regexps - fix indentation and parentheses in a few locations There should be no behavior change, please test. Deeper question: as it stands \w and such do handle unicode, more or less. Is this something we actually want/need in pkg-config ? should we look at restricting the regexps through one of the locale modifiers ? Index: pkg-config === RCS file: /cvs/src/usr.bin/pkg-config/pkg-config,v retrieving revision 1.95 diff -u -p -r1.95 pkg-config --- pkg-config 15 Sep 2020 07:18:45 - 1.95 +++ pkg-config 22 May 2023 07:22:10 - @@ -16,14 +16,20 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use strict; -use warnings; +use v5.36; use Config; use Getopt::Long; use File::Basename; use File::stat; use OpenBSD::PkgConfig; +use constant { + ONLY_I => 1, + ONLY_l => 2, + ONLY_L => 4, + ONLY_OTHER => 8 +}; + my @PKGPATH = qw(/usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/local/share/pkgconfig @@ -70,7 +76,7 @@ defined $ENV{PKG_CONFIG_DEBUG_SPEW} ? $m if ($logfile) { open my $L, ">>" , $logfile or die; - print $L beautify_list($0, @ARGV), "\n"; + say $L beautify_list($0, @ARGV); close $L; } @@ -87,7 +93,7 @@ GetOptions( 'debug' => \$mode{debug}, 'help' => \, #does not return 'usage' => \, #does not return 'list-all' => \$mode{list}, - 'version' => sub { print "$version\n" ; exit(0);} , + 'version' => sub { say $version ; exit(0);} , 'errors-to-stdout' => sub { $mode{estdout} = 1}, 'print-errors' => sub { $mode{printerr} = 1}, 'silence-errors'=> sub { $mode{printerr} = 0}, @@ -97,13 +103,13 @@ GetOptions('debug' => \$mode{debug}, 'print-requires'=> \$mode{printrequires}, 'print-requires-private' => \$mode{printrequiresprivate}, - 'cflags'=> sub { $mode{cflags} = 3}, - 'cflags-only-I' => sub { $mode{cflags} |= 1}, - 'cflags-only-other' => sub { $mode{cflags} |= 2}, - 'libs' => sub { $mode{libs} = 7}, - 'libs-only-l' => sub { $mode{libs} |= 1}, - 'libs-only-L' => sub { $mode{libs} |= 2}, - 'libs-only-other' => sub { $mode{libs} |= 4}, + 'cflags'=> sub { $mode{cflags} = ONLY_I|ONLY_OTHER}, + 'cflags-only-I' => sub { $mode{cflags} |= ONLY_I}, + 'cflags-only-other' => sub { $mode{cflags} |= ONLY_OTHER}, + 'libs' => sub { $mode{libs} = ONLY_L|ONLY_l|ONLY_OTHER}, + 'libs-only-l' => sub { $mode{libs} |= ONLY_l}, + 'libs-only-L' => sub { $mode{libs} |= ONLY_L}, + 'libs-only-other' => sub { $mode{libs} |= ONLY_OTHER}, 'exists'=> sub { $mode{exists} = 1} , 'validate' => sub { $mode{validate} = 1}, 'static'=> sub { $mode{static} = 1}, @@ -178,9 +184,9 @@ sub get_next_module if ($module =~ m/,/) { my @ms = split(/,/, $module); $m = shift @ms; - unshift(@ARGV, @ms) if (scalar(@ms) > 0); + unshift(@ARGV, @ms) if @ms != 0; } else { - return $module; + return $module; } return $m; @@ -267,16 +273,15 @@ if ($mode{static}){ if ($mode{cflags} || $mode{libs} || $mode{variable}) { push @vlist, do_cflags($dep_cfg_list) if $mode{cflags}; push @vlist, do_libs($dep_cfg_list) if $mode{libs}; - print join(' ', @vlist), "\n" if $rc == 0; + say join(' ', @vlist) if $rc == 0; } exit $rc; ### -sub handle_config +sub handle_config($p, $op, $v, $list) { - my ($p, $op, $v, $list) = @_; my $cfg = cache_find_config($p); unshift @$list, $p if defined $cfg; @@ -316,7 +321,7 @@ sub handle_config my $deps = $cfg->get_property($property, $variables); return unless defined $deps; for my $dep (@$deps) { - if ($dep =~ m/^(.*?)\s*([<=>]+)\s*([\d\.]+|[\d\.]+[\w]*[\d]+)$/) { + if ($dep =~