From 6dc7c9c5e1a5eb29c63b492c5b9fec65dece06bc Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Sun, 19 Jun 2016 22:49:58 +0100 Subject: [PATCH] Adds checks to 1.3->2.0 API migration script --- scripts/rename.pl | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scripts/rename.pl b/scripts/rename.pl index c169078e3..c29519eef 100755 --- a/scripts/rename.pl +++ b/scripts/rename.pl @@ -1,12 +1,25 @@ #!/usr/bin/perl - -# rename identifiers (functions, types, enum constant, etc) -# on upgrades of major version according to a list +# +# This file is part of mbed TLS (https://tls.mbed.org) +# +# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved +# +# Purpose +# +# This script migrates application source code from the mbed TLS 1.3 API to the +# mbed TLS 2.0 API. +# +# The script processes the given source code and renames identifiers - functions +# types, enums etc, as +# +# Usage: rename.pl [-f datafile] [-s] [--] [filenames...] +# use warnings; use strict; use utf8; +use Path::Class; use open qw(:std utf8); my $usage = "Usage: $0 [-f datafile] [-s] [--] [filenames...]\n"; @@ -45,15 +58,28 @@ my $space = qr/\s+/; my $idnum = qr/[a-zA-Z0-9_]+/; my $symbols = qr/[-!#\$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~]+|"/; +my $lib_include_dir = dir($0)->parent->parent->subdir('include', 'mbedtls'); +my $lib_source_dir = dir($0)->parent->parent->subdir('library'); + # if we replace inside strings, we don't consider them a token my $token = $do_strings ? qr/$space|$idnum|$symbols/ : qr/$string|$space|$idnum|$symbols/; my %warnings; +# If no files were passed, exit... +if ( not defined($ARGV[0]) ){ die $usage; } + while( my $filename = shift ) { print STDERR "$filename... "; + + if( dir($filename)->parent eq $lib_include_dir || + dir($filename)->parent eq $lib_source_dir ) + { + die "Script cannot be executed on the mbed TLS library itself."; + } + if( -d $filename ) { print STDERR "skip (directory)\n"; next } open my $rfh, '<', $filename or die;