blob: 7b835e54ce65bc145725edcb8368c6384e1da952 [file] [log] [blame]
fbrosson3a745712018-04-04 22:26:56 +00001#!/usr/bin/env perl
Paul Bakker9a736322012-11-14 12:39:52 +00002
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é-Gonnardf234ff82015-01-22 17:01:27 +00007# sed -e '/EXTRACT/s/YES/NO/' doxygen/mbedtls.doxyfile | doxygen -
Paul Bakker9a736322012-11-14 12:39:52 +00008# 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útib7246ad2020-05-26 00:33:31 +020010#
11# Copyright (C) 2012-2016, Arm Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020012# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13#
14# This file is provided under the Apache License 2.0, or the
15# GNU General Public License v2.0 or later.
16#
17# **********
18# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020019#
20# Licensed under the Apache License, Version 2.0 (the "License"); you may
21# not use this file except in compliance with the License.
22# You may obtain a copy of the License at
23#
24# http://www.apache.org/licenses/LICENSE-2.0
25#
26# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
Bence Szépkútib7246ad2020-05-26 00:33:31 +020031#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020032# **********
33#
34# **********
35# GNU General Public License v2.0 or later:
36#
37# This program is free software; you can redistribute it and/or modify
38# it under the terms of the GNU General Public License as published by
39# the Free Software Foundation; either version 2 of the License, or
40# (at your option) any later version.
41#
42# This program is distributed in the hope that it will be useful,
43# but WITHOUT ANY WARRANTY; without even the implied warranty of
44# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45# GNU General Public License for more details.
46#
47# You should have received a copy of the GNU General Public License along
48# with this program; if not, write to the Free Software Foundation, Inc.,
49# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50#
51# **********
52#
Bence Szépkútib7246ad2020-05-26 00:33:31 +020053# This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker9a736322012-11-14 12:39:52 +000054
55use warnings;
56use strict;
57use File::Basename;
58
Manuel Pégourié-Gonnardd09a6b52015-04-09 17:19:23 +020059# C/header files in the following directories will be checked
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060my @directories = qw(include/mbedtls library doxygen/input);
Paul Bakker9a736322012-11-14 12:39:52 +000061
62# very naive pattern to find directives:
Manuel Pégourié-Gonnardef009ff2013-09-16 13:40:25 +020063# everything with a backslach except '\0' and backslash at EOL
64my $doxy_re = qr/\\(?!0|\n)/;
Paul Bakker9a736322012-11-14 12:39:52 +000065
Andres Amaya Garciad3f0f5e2016-12-14 09:36:55 +000066# Return an error code to the environment if a potential error in the
67# source code is found.
68my $exit_code = 0;
69
Paul Bakker9a736322012-11-14 12:39:52 +000070sub check_file {
71 my ($fname) = @_;
72 open my $fh, '<', $fname or die "Failed to open '$fname': $!\n";
73
74 # first line of the last normal comment block,
75 # or 0 if not in a normal comment block
76 my $block_start = 0;
77 while (my $line = <$fh>) {
78 $block_start = $. if $line =~ m/\/\*(?![*!])/;
79 $block_start = 0 if $line =~ m/\*\//;
80 if ($block_start and $line =~ m/$doxy_re/) {
81 print "$fname:$block_start: directive on line $.\n";
82 $block_start = 0; # report only one directive per block
Andres Amaya Garciad3f0f5e2016-12-14 09:36:55 +000083 $exit_code = 1;
Paul Bakker9a736322012-11-14 12:39:52 +000084 }
85 }
86
87 close $fh;
88}
89
90sub check_dir {
91 my ($dirname) = @_;
92 for my $file (<$dirname/*.[ch]>) {
93 check_file($file);
94 }
95}
96
Andres Amaya Garciad3f0f5e2016-12-14 09:36:55 +000097# Check that the script is being run from the project's root directory.
Paul Bakker9a736322012-11-14 12:39:52 +000098for my $dir (@directories) {
Andres Amaya Garciad3f0f5e2016-12-14 09:36:55 +000099 if (! -d $dir) {
100 die "This script must be run from the mbed TLS root directory";
101 } else {
102 check_dir($dir)
103 }
Paul Bakker9a736322012-11-14 12:39:52 +0000104}
105
Andres Amaya Garciad3f0f5e2016-12-14 09:36:55 +0000106exit $exit_code;
107
Paul Bakker9a736322012-11-14 12:39:52 +0000108__END__