[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#701477: lintian: Should it support XDG?



On 2013-02-24 22:55, Jakub Wilk wrote:
> * Niels Thykier <niels@thykier.net>, 2013-02-23, 17:08:
>> * lintianrc (ignoring $LINTIAN_ROOT/lintianrc for a moment):
>>   NOW: $HOME/.lintian/rc:/etc/lintianrc
>>   XDG: $HOME/.config/lintianrc:/etc/xdg/lintianrc
> 
> I agree with Lanoxx that having a separate directory for Lintian
> configuration would be nice.
> 
>> Note the lintianrc file currently is special cased to prefer
>> $LINTIAN_ROOT/lintianrc above all other paths.  It seems a bit weird,
> 
> Yeah, that's odd.
> 
>> To be honest, I would be in favour of simply removing the
>> LINTIAN_ROOT/lintianrc case unless there is still a use for it, which
>> I simply missed (regardless of whether we adopt XDG or not).
> 
> Agreed.
> 

Supporting XDG_CONFIG_{HOME,DIRS} can be done fairly easily, see
attached patch (which is bluntly assuming we are dropping
LINTIAN_ROOT/lintianrc).

>> Current LINTIAN_ROOT is always last in the search dir.  I have no
>> intention of changing that.  Though with $XDG_DATA_DIRS,
>> /usr/share/lintian could appear earlier than last.  I suggest we
>> handle that XDG_DATA_DIRS similar to dirs passed via --include-dirs
> 
> This is going to be a pickle... When I set LINTIAN_ROOT to something
> non-default, I expect that /usr/share/lintian won't be on the search
> path. I think we should completely ignore XDG_DATA_DIRS if LINTIAN_ROOT
> is set.
> 

Obviously, I missed the most common use of LINTIAN_ROOT/--root.

> Or maybe ignoring XDG_*_DIRS completely (and honouring only XDG_*_HOME)
> is the way to go? That would make keeping backwards compatiblity easier.
> 

Of the two suggestions, I am more tempted towards ignoring
$XDG_DATA_DIRS if $LINTIAN_ROOT (or --root) is involved.

~Niels


diff --git a/debian/changelog b/debian/changelog index 9ced827..2c25354 100644 --- a/debian/changelog +++ b/debian/changelog @@ -185,6 +185,10 @@ lintian (2.5.12) UNRELEASED; urgency=low to --profile. + [NT] Add new command line option "--ignore-lintian-env" to make lintian ignore all environment variables starting with LINTIAN_. + + [NT] Also search for the lintianrc file in XDG_CONFIG_{HOME,DIRS}. + The default paths are now ~/.config/lintian/lintianrc and + /etc/xdg/lintian/lintianrc. The previous lintianrc paths are + still accepted. * lib/Lintian/Collect.pm: + [NT] Add "is_non_free" method to easily check of a given diff --git a/debian/control b/debian/control index 353c40e..fe472aa 100644 --- a/debian/control +++ b/debian/control @@ -79,6 +79,7 @@ Depends: binutils, libdigest-sha-perl, libdpkg-perl, libemail-valid-perl, + libfile-basedir-perl, libipc-run-perl, libparse-debianchangelog-perl, libtext-levenshtein-perl, diff --git a/frontend/lintian b/frontend/lintian index 8d852d1..50cb1e4 100755 --- a/frontend/lintian +++ b/frontend/lintian @@ -691,15 +691,8 @@ if (defined $experimental_output_opts) { # search for configuration file if it was not set with --cfg # do not search the default locations if it was set. unless ($no_conf) { - if ($opt{'LINTIAN_CFG'}) { - } elsif (exists $ENV{'LINTIAN_CFG'} && - -f ($opt{'LINTIAN_CFG'} = $ENV{'LINTIAN_CFG'})) { - } elsif (-f ($opt{'LINTIAN_CFG'} = $opt{'LINTIAN_ROOT'} . '/lintianrc')) { - } elsif ($opt{'user-dirs'} && exists $ENV{'HOME'} && - -f ($opt{'LINTIAN_CFG'} = $ENV{'HOME'} . '/.lintianrc')) { - } elsif ($opt{'user-dirs'} && -f ($opt{'LINTIAN_CFG'} = '/etc/lintianrc')) { - } else { - $opt{'LINTIAN_CFG'} = ''; + if (not $opt{'LINTIAN_CFG'}) { + $opt{'LINTIAN_CFG'} = _find_cfg_file() // ''; } } else { $opt{'LINTIAN_CFG'} = ''; @@ -1502,6 +1495,46 @@ sub handle_lab_query { } } +sub _find_cfg_file { + return $ENV{'LINTIAN_CFG'} if exists $ENV{'LINTIAN_CFG'} and -f $ENV{'LINTIAN_CFG'}; + + if ($opt{'user-dirs'}) { + my $hasFBD = 0; + my $rcfile; + eval { + # File::BaseDir sprews warnings if $ENV{'HOME'} is undef, so + # make sure it is defined. + local $ENV{'HOME'} = $ENV{'HOME'} // '/nonexistent'; + require File::BaseDir; + import File::BaseDir qw(config_home config_files); + $hasFBD = 1; + }; + if ($hasFBD) { + # only accept config_home if either HOME or + # XDG_CONFIG_HOME was set. If both are unset, then this + # will return the "bogus" path + # "/nonexistent/lintian/lintianrc" and we don't want that + # (in the however unlikely case that file actually + # exists). + $rcfile = config_home ('lintian/lintianrc') + if exists $ENV{'HOME'} or exists $ENV{'XDG_CONFIG_HOME'}; + return $rcfile if defined $rcfile and -f $rcfile; + } + if (exists $ENV{'HOME'}) { + $rcfile = $ENV{'HOME'} . '/.lintianrc'; + return $rcfile if -f $rcfile; + } + return '/etc/lintianrc' if -f '/etc/lintianrc'; + if ($hasFBD) { + # config_files checks that the file exists for us + $rcfile = config_files ('lintian/lintianrc'); + return $rcfile if defined $rcfile and $rcfile ne ''; + } + + } + + return; # None found +} sub _find_changes { require Parse::DebianChangelog; diff --git a/man/lintian.pod.in b/man/lintian.pod.in index 4202b29..ecd3ace 100644 --- a/man/lintian.pod.in +++ b/man/lintian.pod.in @@ -422,9 +422,6 @@ B will check this directory for (additional) profiles, data files, support libraries and checks. The latter two implies that Lintian may attempt to I from this directory. -Unlike with the B<--root> option, B will I load -collections nor the I from this directory. - This option may appear more than once; each time adding an additional directory. Directories are searched in the order they appear on the command line. @@ -475,9 +472,9 @@ These option can appear multiple times, in which case the of them to appear determines the result. Note that if the intention is only to disable the user's I<$HOME>, -then unsetting $HOME may suffice. Alternatively, I can be -"re-added" by using I<--include-dir> (caveat: I will -be ignored by this). +then unsetting $HOME and $XDG_CONFIG_HOME may suffice. Alternatively, +I can be "re-added" by using I<--include-dir> (caveat: +I will be ignored by this). If the intention is to avoid (unintentional) side-effects from the calling user, then this option could be combined with @@ -547,13 +544,24 @@ The file name given with the --cfg option =over 4 -=item I<$LINTIAN_CFG> +=item * I<$LINTIAN_CFG> + +=item * I<$XDG_CONFIG_HOME/lintian/lintianrc> + +=item * I<$HOME/.lintianrc> + +Deprecated in Lintian/2.5.12 and newer (use the XDG based variant +above) + +=item * I -=item I<$LINTIAN_ROOT/lintianrc> +Where XGD_DIR is a directories listed in I<$XDG_CONFIG_DIRS> (or +I if I<$XDG_CONFIG_DIRS> is unset). -=item I<$HOME/.lintianrc> +=item * I -=item I +Deprecated in Lintian/2.5.12 and newer (use the XDG based variant +above) =back
Reply to: