potatogim / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
Justin Vreeland 794d92
# By Paul Bolle October 2014.
Justin Vreeland 794d92
#
Justin Vreeland 794d92
# Contributed to the public domain by its author.
Justin Vreeland 794d92
Justin Vreeland 794d92
use 5.016;
Justin Vreeland 794d92
use warnings;
Justin Vreeland 794d92
use autodie;
Justin Vreeland 794d92
Justin Vreeland 794d92
use File::Find;
Justin Vreeland 794d92
Justin Vreeland 794d92
my @Kconfigs;
Justin Vreeland 794d92
Justin Vreeland 794d92
my $Kconfigre = qr/Kconfig.*/;
Justin Vreeland 794d92
my $configre = qr/^\s*(menu)?config\s+(?<config>(\w+))$/;
Justin Vreeland 794d92
my $CONFIG_re = qr/\bCONFIG_(?<CONFIG_>(\w+))/;
Justin Vreeland 794d92
Justin Vreeland 794d92
sub match {
Justin Vreeland 794d92
	push( @Kconfigs, $File::Find::name ) if ($_ =~ $Kconfigre);
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
sub parse_kconfig {
Justin Vreeland 794d92
	my ($path) = @_;
Justin Vreeland 794d92
Justin Vreeland 794d92
	my @ret;
Justin Vreeland 794d92
Justin Vreeland 794d92
	open( my $kconfig, "<", $path );
Justin Vreeland 794d92
	my $slurp = do { local $/ = undef; <$kconfig> };
Justin Vreeland 794d92
	close( $kconfig );
Justin Vreeland 794d92
	my @lines = split ( /\n/, $slurp );
Justin Vreeland 794d92
	foreach my $line (@lines) {
Justin Vreeland 794d92
		if ($line =~ /$configre/) {
Justin Vreeland 794d92
			push( @ret, $+{config} );
Justin Vreeland 794d92
		}
Justin Vreeland 794d92
	}
Justin Vreeland 794d92
Justin Vreeland 794d92
	@ret;
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
sub parse_shipped {
Justin Vreeland 794d92
	my ($path) = @_;
Justin Vreeland 794d92
Justin Vreeland 794d92
	my @ret;
Justin Vreeland 794d92
Justin Vreeland 794d92
	open( my $shipped, "<", $path );
Justin Vreeland 794d92
	my $slurp = do { local $/ = undef; <$shipped> };
Justin Vreeland 794d92
	close( $shipped );
Justin Vreeland 794d92
	my @lines = split ( /\n/, $slurp );
Justin Vreeland 794d92
	my $i = 1;
Justin Vreeland 794d92
	foreach my $line (@lines) {
Justin Vreeland 794d92
		if ($line =~ /$CONFIG_re/) {
Justin Vreeland 794d92
			push( @ret, [$i, $+{CONFIG_}] );
Justin Vreeland 794d92
		}
Justin Vreeland 794d92
		$i++;
Justin Vreeland 794d92
	}
Justin Vreeland 794d92
Justin Vreeland 794d92
	@ret;
Justin Vreeland 794d92
}
Justin Vreeland 794d92
Justin Vreeland 794d92
exit main ( @ARGV );
Justin Vreeland 794d92
Justin Vreeland 794d92
sub main {
Justin Vreeland 794d92
	my %configs;
Justin Vreeland 794d92
Justin Vreeland 794d92
	find( \&match, @_ );
Justin Vreeland 794d92
Justin Vreeland 794d92
	foreach my $Kconfig (@Kconfigs) {
Justin Vreeland 794d92
		my (@tmp) = parse_kconfig( $Kconfig );
Justin Vreeland 794d92
		foreach my $config ( @tmp ) {
Justin Vreeland 794d92
			$configs{ $config }++;
Justin Vreeland 794d92
		}
Justin Vreeland 794d92
	}
Justin Vreeland 794d92
Justin Vreeland 794d92
	foreach my $shipped (glob("*.config")) {
Justin Vreeland 794d92
		my (@tmp) = parse_shipped( $shipped );
Justin Vreeland 794d92
		foreach my $ref ( @tmp ) {
Justin Vreeland 794d92
			say( STDERR "$shipped:$ref->[0]: No Kconfig symbol matches 'CONFIG_$ref->[1]'" )
Justin Vreeland 794d92
				unless (grep( /^$ref->[1]$/, keys( %configs )));
Justin Vreeland 794d92
		}
Justin Vreeland 794d92
	}
Justin Vreeland 794d92
Justin Vreeland 794d92
	0;
Justin Vreeland 794d92
}
Justin Vreeland 794d92