mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-25 17:21:08 +00:00
generate_errors.pl: add mbedtls header shadowing by crypto headers
Abort script upon encountering a duplicated error
This commit is contained in:
parent
92f91fc9ff
commit
91c6030584
|
@ -4,6 +4,7 @@
|
||||||
#
|
#
|
||||||
# Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments,
|
# Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments,
|
||||||
# or generate_errors.pl include_dir data_dir error_file include_crypto
|
# or generate_errors.pl include_dir data_dir error_file include_crypto
|
||||||
|
# Include crypto can be either 0 (don't include) or 1 (include). On by default.
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
@ -16,15 +17,12 @@ if( @ARGV ) {
|
||||||
|
|
||||||
-d $include_dir or die "No such directory: $include_dir\n";
|
-d $include_dir or die "No such directory: $include_dir\n";
|
||||||
-d $data_dir or die "No such directory: $data_dir\n";
|
-d $data_dir or die "No such directory: $data_dir\n";
|
||||||
if( $include_crypto ) {
|
|
||||||
-d $crypto_dir or die "Crypto submodule not present\n";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$include_dir = 'include/mbedtls';
|
$include_dir = 'include/mbedtls';
|
||||||
$data_dir = 'scripts/data_files';
|
$data_dir = 'scripts/data_files';
|
||||||
$error_file = 'library/error.c';
|
$error_file = 'library/error.c';
|
||||||
$include_crypto = 1;
|
$include_crypto = 1;
|
||||||
-d $crypto_dir or die "Crypto submodule not present\n";
|
|
||||||
unless( -d $include_dir && -d $data_dir ) {
|
unless( -d $include_dir && -d $data_dir ) {
|
||||||
chdir '..' or die;
|
chdir '..' or die;
|
||||||
-d $include_dir && -d $data_dir
|
-d $include_dir && -d $data_dir
|
||||||
|
@ -32,6 +30,10 @@ if( @ARGV ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $include_crypto ) {
|
||||||
|
-d $crypto_include_dir or die "Crypto submodule not present\n";
|
||||||
|
}
|
||||||
|
|
||||||
my $error_format_file = $data_dir.'/error.fmt';
|
my $error_format_file = $data_dir.'/error.fmt';
|
||||||
|
|
||||||
my @low_level_modules = qw( AES ARC4 ARIA ASN1 BASE64 BIGNUM BLOWFISH
|
my @low_level_modules = qw( AES ARC4 ARIA ASN1 BASE64 BIGNUM BLOWFISH
|
||||||
|
@ -52,14 +54,31 @@ close(FORMAT_FILE);
|
||||||
|
|
||||||
$/ = $line_separator;
|
$/ = $line_separator;
|
||||||
|
|
||||||
my @files = <$include_dir/*.h>;
|
my %files;
|
||||||
|
|
||||||
if( $include_crypto ) {
|
if( $include_crypto ) {
|
||||||
@files = (<$include_dir/*.h>,<$crypto_dir/$include_dir/*.h>);
|
my @crypto_headers = <$crypto_dir/$include_dir/*.h>;
|
||||||
|
my @mbedtls_files = <$include_dir/*.h>;
|
||||||
|
$files{$_}++ for (@crypto_headers);
|
||||||
|
|
||||||
|
foreach my $file (@mbedtls_files) {
|
||||||
|
my $stripped_filename = substr($file, rindex($file,"/")+1, length($file)-rindex($file,"/")-1);
|
||||||
|
my $crypto_counterpart = "$crypto_dir/$include_dir/$stripped_filename";
|
||||||
|
if ( exists $files{$crypto_counterpart} ){
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
push(@{$files{$file}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
my @headers = <$include_dir/*.h>;
|
||||||
|
$files{$_}++ for (@headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
my @matches;
|
my @matches;
|
||||||
foreach my $file (@files) {
|
foreach my $file (sort keys %files) {
|
||||||
open(FILE, "$file");
|
open(FILE, "$file");
|
||||||
my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>);
|
my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>);
|
||||||
push(@matches, @grep_res);
|
push(@matches, @grep_res);
|
||||||
|
@ -84,13 +103,7 @@ foreach my $line (@matches)
|
||||||
my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//;
|
my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//;
|
||||||
|
|
||||||
if( $error_codes_seen{$error_code}++ ) {
|
if( $error_codes_seen{$error_code}++ ) {
|
||||||
if( $include_crypto ) {
|
die "Duplicated error code: $error_code ($error_name)\n";
|
||||||
print "Duplicated error code: $error_code ($error_name)\n";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
die "Duplicated error code: $error_code ($error_name)\n" ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$description =~ s/\\/\\\\/g;
|
$description =~ s/\\/\\\\/g;
|
||||||
|
|
Loading…
Reference in a new issue