Merge remote-tracking branch 'origin/pr/2547' into development

* origin/pr/2547:
  generate_visualc_files.pl: add mbedtls source shadowing by crypto
  generate_errors.pl: refactor and simplify the code
  generate_errors.pl: typo fix
  revert changes to generate_features.pl and generate_query_config.pl
  generate_errors.pl: add mbedtls header shadowing by crypto headers
  Add an option to use crypto source files in generated visual c project
  Add description of generate_query_config.pl argument
  Add crypto includes when generating features in generate_features.pl
  Include crypto config when generating query config
  Add crypto includes when generating errors in generate_errors.pl
This commit is contained in:
Jaeden Amero 2019-04-24 11:21:56 +01:00
commit 5c03c65a66
2 changed files with 47 additions and 10 deletions

View file

@ -3,15 +3,17 @@
# Generate error.c
#
# Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments,
# or generate_errors.pl include_dir data_dir error_file
# 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;
my ($include_dir, $data_dir, $error_file);
my ($include_dir, $data_dir, $error_file, $include_crypto);
my $crypto_dir = "crypto";
if( @ARGV ) {
die "Invalid number of arguments" if scalar @ARGV != 3;
($include_dir, $data_dir, $error_file) = @ARGV;
die "Invalid number of arguments" if scalar @ARGV != 4;
($include_dir, $data_dir, $error_file, $include_crypto) = @ARGV;
-d $include_dir or die "No such directory: $include_dir\n";
-d $data_dir or die "No such directory: $data_dir\n";
@ -19,6 +21,7 @@ if( @ARGV ) {
$include_dir = 'include/mbedtls';
$data_dir = 'scripts/data_files';
$error_file = 'library/error.c';
$include_crypto = 1;
unless( -d $include_dir && -d $data_dir ) {
chdir '..' or die;
@ -27,6 +30,10 @@ if( @ARGV ) {
}
}
if( $include_crypto ) {
-d $crypto_dir or die "Crypto submodule not present\n";
}
my $error_format_file = $data_dir.'/error.fmt';
my @low_level_modules = qw( AES ARC4 ARIA ASN1 BASE64 BIGNUM BLOWFISH
@ -47,9 +54,19 @@ close(FORMAT_FILE);
$/ = $line_separator;
my @files = <$include_dir/*.h>;
my @headers = ();
if ($include_crypto) {
@headers = <$crypto_dir/$include_dir/*.h>;
foreach my $header (<$include_dir/*.h>) {
my $basename = $header; $basename =~ s!.*/!!;
push @headers, $header unless -e "$crypto_dir/$include_dir/$basename";
}
} else {
@headers = <$include_dir/*.h>;
}
my @matches;
foreach my $file (@files) {
foreach my $file (@headers) {
open(FILE, "$file");
my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, <FILE>);
push(@matches, @grep_res);
@ -73,8 +90,9 @@ foreach my $line (@matches)
my ($error_name, $error_code) = $line =~ /(MBEDTLS_ERR_\w+)\s+\-(0x\w+)/;
my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//;
die "Duplicated error code: $error_code ($error_name)\n"
if( $error_codes_seen{$error_code}++ );
if( $error_codes_seen{$error_code}++ ) {
die "Duplicated error code: $error_code ($error_name)\n";
}
$description =~ s/\\/\\\\/g;
if ($description eq "") {

View file

@ -4,7 +4,8 @@
# 2010
#
# Must be run from mbedTLS root or scripts directory.
# Takes no argument.
# Takes "include_crypto" as an argument that can be either 0 (don't include) or
# 1 (include). Off by default.
use warnings;
use strict;
@ -18,9 +19,16 @@ my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext";
my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln";
my $vsx_sln_file = "$vsx_dir/mbedTLS.sln";
my $include_crypto = 0;
if( @ARGV ) {
die "Invalid number of arguments" if scalar @ARGV != 1;
($include_crypto) = @ARGV;
}
my $programs_dir = 'programs';
my $header_dir = 'include/mbedtls';
my $source_dir = 'library';
my $crypto_dir = 'crypto';
# Need windows line endings!
my $vsx_hdr_tpl = <<EOT;
@ -194,7 +202,18 @@ sub main {
my @app_list = get_app_list();
my @headers = <$header_dir/*.h>;
my @sources = <$source_dir/*.c>;
my @sources = ();
if ($include_crypto) {
@sources = <$crypto_dir/$source_dir/*.c>;
foreach my $file (<$source_dir/*.c>) {
my $basename = $file; $basename =~ s!.*/!!;
push @sources, $file unless -e "$crypto_dir/$source_dir/$basename";
}
} else {
@sources = <$source_dir/*.c>;
}
map { s!/!\\!g } @headers;
map { s!/!\\!g } @sources;