fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 2 | |
| 3 | # Detect comment blocks that are likely meant to be doxygen blocks but aren't. |
| 4 | # |
| 5 | # More precisely, look for normal comment block containing '\'. |
| 6 | # Of course one could use doxygen warnings, eg with: |
Manuel Pégourié-Gonnard | f234ff8 | 2015-01-22 17:01:27 +0000 | [diff] [blame] | 7 | # sed -e '/EXTRACT/s/YES/NO/' doxygen/mbedtls.doxyfile | doxygen - |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 8 | # but that would warn about any undocumented item, while our goal is to find |
| 9 | # items that are documented, but not marked as such by mistake. |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 10 | # |
| 11 | # Copyright (C) 2012-2016, Arm Limited, All Rights Reserved |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 12 | # SPDX-License-Identifier: Apache-2.0 |
| 13 | # |
| 14 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 15 | # not use this file except in compliance with the License. |
| 16 | # You may obtain a copy of the License at |
| 17 | # |
| 18 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | # |
| 20 | # Unless required by applicable law or agreed to in writing, software |
| 21 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 22 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | # See the License for the specific language governing permissions and |
| 24 | # limitations under the License. |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 25 | # |
| 26 | # This file is part of Mbed TLS (https://tls.mbed.org) |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 27 | |
| 28 | use warnings; |
| 29 | use strict; |
| 30 | use File::Basename; |
| 31 | |
Manuel Pégourié-Gonnard | d09a6b5 | 2015-04-09 17:19:23 +0200 | [diff] [blame] | 32 | # C/header files in the following directories will be checked |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 33 | my @directories = qw(include/mbedtls library doxygen/input); |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 34 | |
| 35 | # very naive pattern to find directives: |
Manuel Pégourié-Gonnard | ef009ff | 2013-09-16 13:40:25 +0200 | [diff] [blame] | 36 | # everything with a backslach except '\0' and backslash at EOL |
| 37 | my $doxy_re = qr/\\(?!0|\n)/; |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 38 | |
Andres Amaya Garcia | d3f0f5e | 2016-12-14 09:36:55 +0000 | [diff] [blame] | 39 | # Return an error code to the environment if a potential error in the |
| 40 | # source code is found. |
| 41 | my $exit_code = 0; |
| 42 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 43 | sub check_file { |
| 44 | my ($fname) = @_; |
| 45 | open my $fh, '<', $fname or die "Failed to open '$fname': $!\n"; |
| 46 | |
| 47 | # first line of the last normal comment block, |
| 48 | # or 0 if not in a normal comment block |
| 49 | my $block_start = 0; |
| 50 | while (my $line = <$fh>) { |
| 51 | $block_start = $. if $line =~ m/\/\*(?![*!])/; |
| 52 | $block_start = 0 if $line =~ m/\*\//; |
| 53 | if ($block_start and $line =~ m/$doxy_re/) { |
| 54 | print "$fname:$block_start: directive on line $.\n"; |
| 55 | $block_start = 0; # report only one directive per block |
Andres Amaya Garcia | d3f0f5e | 2016-12-14 09:36:55 +0000 | [diff] [blame] | 56 | $exit_code = 1; |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | close $fh; |
| 61 | } |
| 62 | |
| 63 | sub check_dir { |
| 64 | my ($dirname) = @_; |
| 65 | for my $file (<$dirname/*.[ch]>) { |
| 66 | check_file($file); |
| 67 | } |
| 68 | } |
| 69 | |
Andres Amaya Garcia | d3f0f5e | 2016-12-14 09:36:55 +0000 | [diff] [blame] | 70 | # Check that the script is being run from the project's root directory. |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 71 | for my $dir (@directories) { |
Andres Amaya Garcia | d3f0f5e | 2016-12-14 09:36:55 +0000 | [diff] [blame] | 72 | if (! -d $dir) { |
| 73 | die "This script must be run from the mbed TLS root directory"; |
| 74 | } else { |
| 75 | check_dir($dir) |
| 76 | } |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Andres Amaya Garcia | d3f0f5e | 2016-12-14 09:36:55 +0000 | [diff] [blame] | 79 | exit $exit_code; |
| 80 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 81 | __END__ |