[devel] Re: find-requires directories

Alexey Tourbin =?iso-8859-1?q?at_=CE=C1_altlinux=2Eru?=
Пн Июн 16 05:49:59 MSD 2003


On Mon, Jun 16, 2003 at 12:06:55AM +0400, Dmitry V. Levin wrote:
> Кажется, на этой стадии ещё определена переменная RPM_BUILD_DIR.

        export RPM_BUILD_DIR="/home/at/RPM/BUILD"
	
Короче нельзя.  Но я немного по-другому придумал.  Смотреть на тему
.perl.req.  Это наброски.

$ pwd | sed s,$HOME,~,
~/RPM/BUILD/libnet-1.13
$ perl Makefile.PL PRINT_PREREQ=1
Checking for Socket...ok
Checking for IO::Socket...ok
perl(IO::Socket)>=1.05  perl(Socket)>=1.3
$
----------- следующая часть -----------

# perl library paths
%perl_vendor_privlib	%(eval "`%__perl -V:installvendorlib`"; echo "$installvendorlib")
%perl_vendor_archlib	%(eval "`%__perl -V:installvendorarch`"; echo "$installvendorarch")
%perl_vendor_autolib	%perl_vendor_archlib/auto

# mandirs
%perl_vendor_man1dir	%_man1dir
%perl_vendor_man3dir	%_man3dir

# perl version/build-specific binary token (PreReq: %perl_binary_compat)
# ALT RPM inserts this dependency automatically since
# Fri Oct 25 2002 Dmitry V. Levin <ldv на altlinux.org> 4.0.4-alt9
%perl_binary_compat	%(eval "`%__perl -V:libperl`"; echo "$libperl")

# automate various rpmbuild stages
%perl_vendor_build() \
	%{?_without_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	%{?_disable_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	: looking for PREREQ dependencies \
	%__perl Makefile.PL PRINT_PREREQ=1 | tee .perl.req \
	: writing Makefile \
	%__perl Makefile.PL \\\
		PREFIX=%prefix \\\
		INSTALLDIRS=vendor \\\
 		%* \\\
		</dev/null \
	: running make \
	%make_build OPTIMIZE="$RPM_OPT_FLAGS" \
	%{?_without_test: : WARNING: tests disabled && exit 0} \
	%{?_disable_test: : WARNING: tests disabled && exit 0} \
	: running tests \
	export LD_BIND_NOW=1 PERL_DL_NONLAZY=1 \
	%make test
%perl_vendor_install() \
	: installing \
	%make_install \\\
		PREFIX=$RPM_BUILD_ROOT%prefix \\\
		INSTALLDIRS=vendor \\\
		INSTALLMAN1DIR=$RPM_BUILD_ROOT%perl_vendor_man1dir \\\
		INSTALLMAN3DIR=$RPM_BUILD_ROOT%perl_vendor_man3dir \\\
 		%* \\\
		pure_install </dev/null \
	%__grep -Fqs 'perl(' .perl.req && cat .perl.req >> $RPM_BUILD_ROOT/.perl.req \
	%{!?_enable_debug: \
		: fixing \
		find $RPM_BUILD_ROOT%perl_vendor_privlib \\\
			-type f '(' -name '*.al' -o -name '*.ix' ')' \\\
			-exec %__perl -ni -e \\\
			'/^#/ and $fixed=1 or print; END{print STDERR "$ARGV: comments removed\\n" if $fixed}' \\\
			{} ';' } \
	: prompting for files that contain /usr/local \
	find $RPM_BUILD_ROOT -type f -exec %__grep -H /usr/local {} ';'
%perl_fix_local %__subst 's|/usr/local|/usr|g'
----------- следующая часть -----------
#!/usr/bin/perl
#
# perl.req
#
# Copyright (C) 2003  Alexey Tourbin <at на altlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

use 5.8.0;
use Getopt::Long;
use strict;

GetOptions("debug" => \my $debug, "method=s" => \my $method);
sub debug ($) {
	my $msg = shift;
	warn "$msg\n" if $debug;
	1;
}
if ($debug) {
	require IO::Handle;
	STDOUT->autoflush(1);
	STDERR->autoflush(1);
	debug "debug mode enabled";
}
$method ||= $ENV{RPM_PERL_REQ_METHOD};
$method eq "strict" || $method eq "normal" || $method eq "relaxed" ||
	die "$0: strict, normal, relaxed methods supported\n";
debug "method = $method";

my @ignore_files = (
	qr(/usr/share/doc/),
	qr(/[Dd]emos?/),
	qr(/examples?/),
);
my @ignore_reqs = (
	qr(^Makefile\b),
# OS-specific
	qr(^machine/ansi\b),
	qr(^sys/systeminfo\b),
	qr(^vmsish\b),
	qr(^MacPerl\b),
	qr(^Win32\b),
	qr(^VMS\b),
	qr(^OS2\b),
	qr(^Mac\b),
	qr(^ExtUtils/XSSymSet\b),
	qr(^Convert/EBCDIC\b),
# old names
	qr(^Digest/Perl/MD5\b),
	qr(^Pod/PlainText\b),
# wrong names
	qr(/\.),
	qr(\$),
# so commonly used... just a database junk (guaranteed to be in perl-base)
	qr(^strict\.pm$),
	qr(^vars\.pm$),
	qr(^Exporter\.pm$),
	qr(^DynaLoader\.pm$),
	qr(^AutoLoader\.pm$),
	qr(^Carp\.pm$),
);

# list of requires
my %req;

if ($ENV{RPM_BUILD_ROOT} && open REQ, "$ENV{RPM_BUILD_ROOT}/.perl.req") {
	while (<REQ>) {
		while (s/perl\(([\w:]+)\)>=([\dv._]+)//) {
			$2
			and $req{package_filename($1)}{package_version($2)}++
			or  $req{package_filename($1)} ||= undef;
		}
	}
	close REQ;
}

# begin
process_file($_) foreach @ARGV ? @ARGV : <>;

sub process_file {
	my $fname = shift;
	chomp $fname;
	return unless $fname;
	if ($method ne "strict") {
		foreach my $re (@ignore_files) {
			if ($fname =~ $re) {
				debug "file: $fname; matches: $re; skip";
				return;
			}
		}
	}
	debug "processing $fname";
# skip "syntax OK" messages
#	use Fcntl;
#	fcntl(STDERR, F_SETFD, 1) if !$debug && $method eq 'relaxed';

# fake paths should take precedence
	local $_ = $ENV{RPM_PERL_LIB_PATH};
	my @inc = $ENV{RPM_BUILD_ROOT}
		? map { "-I$ENV{RPM_BUILD_ROOT}$_" } split, @INC
		: map { "-I$_" } split;
# deparse
	open(PIPE, "-|", $^X, "-MO=Deparse", @inc, $fname) || die;
	while (<PIPE>) {
		last if /^__(DATA|END)__/;
		process_line($_);
	}
	close(PIPE) or $method ne 'relaxed' and die "$fname: deparse failed.\n";
}

# whether we are in BEGIN block
my $prio;

sub process_line {
	my $line = shift;
	my $re_mod = qr/\b(?!\d)\w+(?:::(?!\d)\w+)*/;
	my $re_fna = qr/'(\w+(?:\/\w+)*\.p[lmh])'/;
	my $re_ver = qr/\bv?[0-9]+(?:\.[0-9]+(?:_[0-9]+)?)*\b/;

	if ($line =~ /^sub [\w:]+\bBEGIN {$/) {
		$prio = 1; return;
	} elsif ($line =~ /^}$/) {
		$prio = 0; return;
	}
again:
	if ($line =~ /^\s*(?:use|require) ($re_ver)/) {
		$req{"perl-base"}{package_version($1, '%.5f')}++;
	} elsif ($line =~ /^\s*use ($re_mod) ($re_ver)/) {
		$req{package_filename($1)}{package_version($2)}++;
	} elsif ($line =~ /^\s*use ($re_mod)/) {
		$req{package_filename($1)} ||= undef;
	} elsif ($line =~ /^\s*(?:require|do) $re_fna/) {
		$req{$1} ||= undef;
	} elsif ($line =~ /^(\s*)require ($re_mod)( if\b| unless\b)?/) {
		if ($prio) {
			$req{package_filename($2)} ||= undef;
		} elsif ($3 && $method ne "strict") {
			debug "skip: $line (conditional)";
		} elsif ($1 && $method ne "strict") {
			debug "skip: $line (indent)";
		} else {
			$req{package_filename($2)} ||= undef;
		}
}	}

sub package_filename {
	my $package = shift;
	$package =~ s/::/\//g;
	return $package . '.pm';
}

sub package_version {
	my ($version, $fmt) = (@_, '%s');
	$version =~ s/_//g;
	if ($version =~ s/^v(?=\d)// || $version =~ /\.\d+\./) {
		return "1:$version";
	} else {
		$version =  sprintf($fmt, $version);
		return "0:$version";
	}
}

# end
req:
foreach my $k (keys %req) {
	if ($method ne "strict") {
		foreach my $re (@ignore_reqs) {
			if ($k =~ $re) {
				debug "req: $k; matches: $re; skip";
				delete $req{$k};
				next req;
			}
		}
	}
	foreach my $v (ref $req{$k} ? keys %{$req{$k}} : undef) {
		if ($k eq "perl-base") {
# too old perl? XXX
			if ($method ne "strict"
			&& ($v lt "0:5.006" || $v lt "1:5.6.0")) {
				delete $req{$k}{$v};
				%{$req{$k}} && next;
				delete $req{$k};
				next req;
			} else {
				print "perl-base";
			}
		} else {
			print "perl($k)";
		}
		print " >= $v" if $v;
		print "\n";
	}
}
# nothing special?
print "perl-base\n" unless %req;
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 189 байтов
Описание: =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Url     : <http://lists.altlinux.org/pipermail/devel/attachments/20030616/213139c8/attachment-0001.bin>


Подробная информация о списке рассылки Devel