Received: by mail.netbsd.org (Postfix, from userid 605) id 664CB84DB9; Tue, 9 Aug 2022 19:31:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id A005084D6C for ; Tue, 9 Aug 2022 19:31:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([IPv6:::1]) by localhost (mail.netbsd.org [IPv6:::1]) (amavisd-new, port 10025) with ESMTP id tL7QNm-zfI3H for ; Tue, 9 Aug 2022 19:31:58 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id D074584CE2 for ; Tue, 9 Aug 2022 19:31:57 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id C9EC8FB1A; Tue, 9 Aug 2022 19:31:57 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1660073517180570" MIME-Version: 1.0 Date: Tue, 9 Aug 2022 19:31:57 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc/pkgtools/lintpkgsrc/files To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20220809193157.C9EC8FB1A@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1660073517180570 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: rillig Date: Tue Aug 9 19:31:57 UTC 2022 Modified Files: pkgsrc/pkgtools/lintpkgsrc/files: lintpkgsrc.pl Log Message: lintpkgsrc: cleanup: extract parse_makefile_line_include To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1660073517180570 Content-Disposition: inline Content-Length: 4364 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.60 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.61 --- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.60 Tue Aug 9 19:06:33 2022 +++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl Tue Aug 9 19:31:57 2022 @@ -1,6 +1,6 @@ #!@PERL5@ -# $NetBSD: lintpkgsrc.pl,v 1.60 2022/08/09 19:06:33 rillig Exp $ +# $NetBSD: lintpkgsrc.pl,v 1.61 2022/08/09 19:31:57 rillig Exp $ # Written by David Brownlee . # @@ -423,6 +423,65 @@ sub parse_eval_make_false($$) { $false; } +sub parse_makefile_line_include($$$$$$) { + my ($file, $incfile, $incdirs, $included, $lines, $vars) = @_; + + # At this point just skip any includes which we were + # not able to fully expand. + if ($incfile =~ m#/mk/bsd# + || $incfile =~ /$magic_undefined/ + || $incfile =~ /\$\{/ + || (!$opt{d} && $incfile =~ m#/(buildlink[^/]*\.mk)#)) { + debug("$file: .include \"$incfile\" skipped\n"); + return; + } + + debug("$file: .include \"$incfile\"\n"); + + if (substr($incfile, 0, 1) ne '/') { + foreach my $dir (keys %$incdirs) { + if (-f "$dir/$incfile") { + $incfile = "$dir/$incfile"; + last; + } + } + } + + # perl 5.6.1 realpath() cannot handle files, only directories. + # If the last component is a symlink, this will give a false + # negative, but that is not a problem, as the duplicate check + # is for performance. + $incfile =~ m#^(.+)(/[^/]+)$#; + + if (!-f $incfile) { + $opt{L} or verbose("\n"); + + my $dirs = join(' ', sort keys %$incdirs); + verbose("$file: Cannot locate $incfile in $dirs\n"); + return; + } + + $incfile = realpath($1) . $2; + return if $included->{$incfile}; + + $opt{L} and print "inc $incfile\n"; + $included->{$incfile} = 1; + + if (!open(FILE, $incfile)) { + verbose("Cannot open '$incfile' (from $file): $_ $!\n"); + return; + } + + my $NEWCURDIR = $incfile; + $NEWCURDIR =~ s#/[^/]*$##; + $incdirs->{$NEWCURDIR} = 1; + unshift(@$lines, ".CURDIR=" . $vars->{'.CURDIR'}); + chomp(my @inc_lines = ); + unshift(@$lines, @inc_lines); + unshift(@$lines, ".CURDIR=$NEWCURDIR"); + close(FILE); +} + # Extract variable assignments from Makefile # Much unpalatable magic to avoid having to use make (all for speed) # @@ -522,70 +581,11 @@ sub parse_makefile_vars($$) { $if_false[$#if_false] && next; - # Included files (just unshift onto @data) - # if (m#^\.\s*include\s+"([^"]+)"#) { - my ($incfile) = parse_expand_vars($1, \%vars); - - # At this point just skip any includes which we were - # not able to fully expand. - if ($incfile =~ m#/mk/bsd# - || $incfile =~ /$magic_undefined/ - || $incfile =~ /\$\{/ - || (!$opt{d} && $incfile =~ m#/(buildlink[^/]*\.mk)#)) { - debug("$file: .include \"$incfile\" skipped\n"); - - } else { - debug("$file: .include \"$incfile\"\n"); + my $incfile = parse_expand_vars($1, \%vars); - if (substr($incfile, 0, 1) ne '/') { - foreach my $dir (keys %incdirs) { - if (-f "$dir/$incfile") { - $incfile = "$dir/$incfile"; - last; - } - } - } - - # perl 5.6.1 realpath() cannot handle files, only directories. - # If the last component is a symlink, this will give a false - # negative, but that is not a problem, as the duplicate check - # is for performance. - $incfile =~ m#^(.+)(/[^/]+)$#; - - if (!-f $incfile) { - if (!$opt{L}) { - verbose("\n"); - } - - verbose("$file: Cannot locate $incfile in " - . join(' ', sort keys %incdirs) - . "\n"); - - } else { - $incfile = realpath($1) . $2; - - if (!$incfiles{$incfile}) { - if ($opt{L}) { - print "inc $incfile\n"; - } - $incfiles{$incfile} = 1; - - if (!open(FILE, $incfile)) { - verbose("Cannot open '$incfile' (from $file): $_ $!\n"); - } else { - my $NEWCURDIR = $incfile; - $NEWCURDIR =~ s#/[^/]*$##; - $incdirs{$NEWCURDIR} = 1; - unshift(@lines, ".CURDIR=$vars{'.CURDIR'}"); - chomp(my @inc_lines = ); - unshift(@lines, @inc_lines); - unshift(@lines, ".CURDIR=$NEWCURDIR"); - close(FILE); - } - } - } - } + parse_makefile_line_include($file, $incfile, + \%incdirs, \%incfiles, \@lines, \%vars); next; } --_----------=_1660073517180570--