File: check_copy.sh

package info (click to toggle)
cppad 2026.00.00.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,584 kB
  • sloc: cpp: 112,960; sh: 6,146; ansic: 179; python: 71; sed: 12; makefile: 10
file content (169 lines) | stat: -rwxr-xr-x 4,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /usr/bin/env bash
set -e -u
# !! EDITS TO THIS FILE ARE LOST DURING UPDATES BY xrst.git/bin/dev_tools.sh !!
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
# SPDX-FileContributor: 2023-25 Bradley M. Bell
# ----------------------------------------------------------------------------
# bin/check_copy.sh
# Checks that the copyright message, in all the source files,
# is correct and up to date. If there were any errors, a message is printed,
# it is automatically corrected, and this script exits with an error.
# Files that are not checked can be specified in bin/dev_setting.sh
# ----------------------------------------------------------------------------
if [ "$0" != "bin/check_copy.sh" ]
then
   echo "bin/check_copy.sh: must be executed from its parent directory"
   exit 1
fi
if [ "$#" != 0 ]
then
   echo 'check_copy does not expect any arguments'
   exit 1
fi
#
# grep, sed
source bin/grep_and_sed.sh
#
# spdx_license_id, no_copyright_list
source bin/dev_settings.sh
#
# yy
yy=$(date +%y)
#
# ----------------------------------------------------------------------------
if [ $# != 0 ]
then
   echo 'bin/check_copy.sh does not expect any arguments'
   exit 1
fi
if [ "$0" != 'bin/check_copy.sh' ]
then
   echo 'bin/check_copy.sh: must be executed from its parent directory'
   exit 1
fi
if [ ! -e './.git' ]
then
   echo 'bin/check_copy.sh: cannot find ./.git'
   exit 1
fi
# ---------------------------------------------------------------------------
# fullname
fullname=''
if [ "${USER+x}" != '' ]
then
   for contributor in $contributor_list
   do
      if [[ $contributor == ${USER}* ]]
      then
         fullname=$(echo $contributor | sed -e 's|^.*:||' -e 's|_| |g')
      fi
   done
   if [ "$fullname" == '' ] && [ "${USER+x}" != '' ]
   then
      echo "Cannot user name = $USER in bin/dev_settings.sh contributor_list"
      exit 1
   fi
fi
# ---------------------------------------------------------------------------
# copyright_all, copyright_changed
echo "#" > temp.sed
for name in $no_copyright_list
do
   if [ -f $name ]
   then
      echo "^$name\$" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> temp.sed
   elif [ -d $name ]
   then
      echo "^$name/" | $sed -e 's|/|[/]|g' -e 's|.*|/&/d|' >> temp.sed
   else
      echo "$name in no_copyright_list is not a file or directory"
      exit 1
   fi
done
copyright_all=$(git ls-files | $sed -f temp.sed)
copyright_changed=$(
   git status --porcelain | $sed -e 's|^...||' | $sed -f temp.sed
)
# ---------------------------------------------------------------------------
missing='no'
changed='no'
for file_name in $copyright_all
do
   # if file has not been deleted
   if [ -e $file_name ]
   then
      # if file does not have expected license identifier
      if ! $grep "$spdx_license_id\$" $file_name > /dev/null
      then
         if [ "$missing" == 'no' ]
         then
            echo "Cannot find line that ends with:"
            echo "   $spdx_license_id"
            echo "In the following files:"
         fi
         echo "$file_name"
         missing='yes'
      fi
   fi
done
# ---------------------------------------------------------------------------
cat << EOF > temp.sed
/SPDX-FileContributor:[ 0-9.-]*$fullname/! b end
s|\\([0-9]\\{4\\}\\)[-0-9]* |\\1-$yy |
s|20$yy-$yy |20$yy |
#
: end
EOF
list=''
if [ "$fullname" != '' ]
then
   list="$copyright_changed"
fi
for file_name in $list
do
   if [ -e $file_name ] && [ -f $file_name ]
   then
      if ! $grep "SPDX-FileContributor:[ 0-9.-]*$fullname" $file_name \
         > /dev/null
      then
         echo "username = $USER, fullname = $fullname"
         echo "The following pattern does not appear in $file_name"
         echo 'SPDX-FileContributor:[ 0-9.-]*'$fullname:
         exit 1
      fi
      $sed -f temp.sed $file_name > temp.$$
      if diff $file_name temp.$$ > /dev/null
      then
         rm temp.$$
      else
         if [ "$changed" == 'no' ]
         then
            echo 'The following file contributor dates have been updated'
         fi
         echo $file_name
         if diff $file_name temp.$$
         then
            echo 'check_version.sh: program error'
            exit 1
         fi
         changed='yes'
         if [ -x $file_name ]
         then
            mv temp.$$ $file_name
            chmod +x $file_name
         else
            mv temp.$$ $file_name
         fi
      fi
   fi
done
#
if [ "$missing" = 'yes' ] || [ "$changed" == 'yes' ]
then
   echo 'check_copy.sh: The copyright messages above were updated.'
   echo 'Re-execute bin/check_copy.sh ?'
   exit 1
fi
echo 'bin/check_copy.sh: OK'
exit 0