Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: gdb/copyright.py

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/contrib/test_pubnames_and_indexes.py ('k') | gdb/copyright.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 2
3 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 #
5 # This file is part of GDB.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
3 """copyright.py 20 """copyright.py
4 21
5 This script updates most of the files that are not already handled 22 This script updates the list of years in the copyright notices in
6 by copyright.sh. It must be run from the gdb/ subdirectory of the 23 most files maintained by the GDB project.
7 GDB source tree. 24
8 25 Usage: cd src/gdb && python copyright.py
26
27 Always review the output of this script before committing it!
28 A useful command to review the output is:
29 % filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
30 This removes the bulk of the changes which are most likely to be correct.
9 """ 31 """
10 32
11 import datetime 33 import datetime
12 import re
13 import os 34 import os
14 import os.path 35 import os.path
15 36 import subprocess
16 class Comment(object): 37
17 """A class describing comment. 38
18 39 def get_update_list():
19 ATTRIBUTES 40 """Return the list of files to update.
20 start: A string describing how comments are started. 41
21 stop: A string describing how comments end. If None, then 42 Assumes that the current working directory when called is the root
22 a comment ends at the end of the line. 43 of the GDB source tree (NOT the gdb/ subdirectory!). The names of
23 start2: Some files accept more than 1 kind of comment. 44 the files are relative to that root directory.
24 For those that do, this is the alternative form.
25 For now, it is assumed that if start2 is not None,
26 then stop is None (thus no stop2 attribute).
27 """ 45 """
28 def __init__(self, start, stop=None, start2=None, max_lines=30): 46 result = []
29 """The "Copyright" keyword should be within MAX_LINES lines 47 for gdb_dir in ('gdb', 'sim', 'include/gdb'):
30 from the start of the file.""" 48 for root, dirs, files in os.walk(gdb_dir, topdown=True):
31 self.start = start 49 for dirname in dirs:
32 self.stop = stop 50 reldirname = "%s/%s" % (root, dirname)
33 self.start2 = start2 51 if (dirname in EXCLUDE_ALL_LIST
34 self.max_lines = max_lines 52 or reldirname in EXCLUDE_LIST
35 53 or reldirname in NOT_FSF_LIST
36 # The Comment object for Ada code (and GPR files). 54 or reldirname in BY_HAND):
37 ADA_COMMENT = Comment(start="--") 55 # Prune this directory from our search list.
38 56 dirs.remove(dirname)
39 THIS_YEAR = str(datetime.date.today().year) 57 for filename in files:
58 relpath = "%s/%s" % (root, filename)
59 if (filename in EXCLUDE_ALL_LIST
60 or relpath in EXCLUDE_LIST
61 or relpath in NOT_FSF_LIST
62 or relpath in BY_HAND):
63 # Ignore this file.
64 pass
65 else:
66 result.append(relpath)
67 return result
68
69
70 def update_files(update_list):
71 """Update the copyright header of the files in the given list.
72
73 We use gnulib's update-copyright script for that.
74 """
75 # We want to use year intervals in the copyright notices, and
76 # all years should be collapsed to one single year interval,
77 # even if there are "holes" in the list of years found in the
78 # original copyright notice (OK'ed by the FSF, case [gnu.org #719834]).
79 os.environ['UPDATE_COPYRIGHT_USE_INTERVALS'] = '2'
80
81 # Perform the update, and save the output in a string.
82 update_cmd = ['bash', 'gdb/gnulib/import/extra/update-copyright']
83 update_cmd += update_list
84
85 p = subprocess.Popen(update_cmd, stdout=subprocess.PIPE,
86 stderr=subprocess.STDOUT)
87 update_out = p.communicate()[0]
88
89 # Process the output. Typically, a lot of files do not have
90 # a copyright notice :-(. The update-copyright script prints
91 # a well defined warning when it did not find the copyright notice.
92 # For each of those, do a sanity check and see if they may in fact
93 # have one. For the files that are found not to have one, we filter
94 # the line out from the output, since there is nothing more to do,
95 # short of looking at each file and seeing which notice is appropriate.
96 # Too much work! (~4,000 files listed as of 2012-01-03).
97 update_out = update_out.splitlines()
98 warning_string = ': warning: copyright statement not found'
99 warning_len = len(warning_string)
100
101 for line in update_out:
102 if line.endswith('\n'):
103 line = line[:-1]
104 if line.endswith(warning_string):
105 filename = line[:-warning_len]
106 if may_have_copyright_notice(filename):
107 print line
108 else:
109 # Unrecognized file format. !?!
110 print "*** " + line
111
112
113 def may_have_copyright_notice(filename):
114 """Check that the given file does not seem to have a copyright notice.
115
116 The filename is relative to the root directory.
117 This function assumes that the current working directory is that root
118 directory.
119
120 The algorigthm is fairly crude, meaning that it might return
121 some false positives. I do not think it will return any false
122 negatives... We might improve this function to handle more
123 complex cases later...
124 """
125 # For now, it may have a copyright notice if we find the word
126 # "Copyright" at the (reasonable) start of the given file, say
127 # 50 lines...
128 MAX_LINES = 50
129
130 fd = open(filename)
131
132 lineno = 1
133 for line in fd:
134 if 'Copyright' in line:
135 return True
136 lineno += 1
137 if lineno > 50:
138 return False
139 return False
140
141
142 def main ():
143 """The main subprogram."""
144 if not os.path.isfile("gnulib/import/extra/update-copyright"):
145 print "Error: This script must be called from the gdb directory."
146 root_dir = os.path.dirname(os.getcwd())
147 os.chdir(root_dir)
148
149 update_list = get_update_list()
150 update_files (update_list)
151
152 # Remind the user that some files need to be updated by HAND...
153 if BY_HAND:
154 print
155 print "\033[31mREMINDER: The following files must be updated by hand." \
156 "\033[0m"
157 for filename in BY_HAND + MULTIPLE_COPYRIGHT_HEADERS:
158 print " ", filename
159
160 ############################################################################
161 #
162 # Some constants, placed at the end because they take up a lot of room.
163 # The actual value of these constants is not significant to the understanding
164 # of the script.
165 #
166 ############################################################################
40 167
41 # Files which should not be modified, either because they are 168 # Files which should not be modified, either because they are
42 # generated, non-FSF, or otherwise special (e.g. license text, 169 # generated, non-FSF, or otherwise special (e.g. license text,
43 # or test cases which must be sensitive to line numbering). 170 # or test cases which must be sensitive to line numbering).
44 EXCLUSION_LIST = ( 171 #
45 "COPYING", "COPYING.LIB", "CVS", "configure", "copying.c", "gdbarch.c", 172 # Filenames are relative to the root directory.
46 "gdbarch.h", "fdl.texi", "gpl.texi", "gdbtk", "gdb.gdbtk", "osf-share", 173 EXCLUDE_LIST = (
47 "aclocal.m4", "step-line.inp", "step-line.c", 174 'gdb/CONTRIBUTE',
48 ) 175 'gdb/gdbarch.c', 'gdb/gdbarch.h',
49 176 'gdb/gnulib'
50 # Files that are too different from the rest to be processed automatically. 177 )
51 BY_HAND = ['../sim/ppc/psim.texinfo'] 178
52 179 # Files which should not be modified, either because they are
53 # Files for which we know that they do not have a copyright header. 180 # generated, non-FSF, or otherwise special (e.g. license text,
54 # Ideally, this list should be empty (but it may not be possible to 181 # or test cases which must be sensitive to line numbering).
55 # add a copyright header in some of them). 182 #
56 NO_COPYRIGHT = ( 183 # Matches any file or directory name anywhere. Use with caution.
57 # Configure files. We should fix those, one day. 184 # This is mostly for files that can be found in multiple directories.
58 "testsuite/gdb.cell/configure.ac", "testsuite/gdb.hp/configure.ac", 185 # Eg: We want all files named COPYING to be left untouched.
59 "testsuite/gdb.hp/gdb.aCC/configure.ac", 186
60 "testsuite/gdb.hp/gdb.base-hp/configure.ac", 187 EXCLUDE_ALL_LIST = (
61 "testsuite/gdb.hp/gdb.compat/configure.ac", 188 "COPYING", "COPYING.LIB", "CVS", "configure", "copying.c",
62 "testsuite/gdb.hp/gdb.defects/configure.ac", 189 "fdl.texi", "gpl.texi", "aclocal.m4",
63 "testsuite/gdb.hp/gdb.objdbg/configure.ac", 190 )
64 "testsuite/gdb.stabs/configure.ac", 191
65 "../sim/arm/configure.ac", "../sim/avr/configure.ac", 192 # The list of files to update by hand.
66 "../sim/common/configure.ac", "../sim/configure.ac", 193 BY_HAND = (
67 "../sim/cr16/configure.ac", "../sim/cris/configure.ac", 194 # These files are sensitive to line numbering.
68 "../sim/d10v/configure.ac", "../sim/erc32/configure.ac", 195 "gdb/testsuite/gdb.base/step-line.inp",
69 "../sim/frv/configure.ac", "../sim/h8300/configure.ac", 196 "gdb/testsuite/gdb.base/step-line.c",
70 "../sim/igen/configure.ac", "../sim/iq2000/configure.ac", 197 )
71 "../sim/lm32/configure.ac", "../sim/m32r/configure.ac", 198
72 "../sim/m68hc11/configure.ac", "../sim/mcore/configure.ac", 199 # Files containing multiple copyright headers. This script is only
73 "../sim/microblaze/configure.ac", "../sim/mips/configure.ac", 200 # fixing the first one it finds, so we need to finish the update
74 "../sim/mn10300/configure.ac", "../sim/moxie/configure.ac", 201 # by hand.
75 "../sim/ppc/configure.ac", "../sim/sh/configure.ac", 202 MULTIPLE_COPYRIGHT_HEADERS = (
76 "../sim/sh64/configure.ac", "../sim/testsuite/configure.ac", 203 "gdb/doc/gdb.texinfo",
77 "../sim/testsuite/d10v-elf/configure.ac", 204 "gdb/doc/refcard.tex",
78 "../sim/testsuite/frv-elf/configure.ac", 205 )
79 "../sim/testsuite/m32r-elf/configure.ac", 206
80 "../sim/testsuite/mips64el-elf/configure.ac", "../sim/v850/configure.ac", 207 # The list of file which have a copyright, but not head by the FSF.
81 # Assembly files. It's not certain that we can add a copyright 208 # Filenames are relative to the root directory.
82 # header in a way that works for all platforms supported by the 209 NOT_FSF_LIST = (
83 # testcase... 210 "gdb/exc_request.defs",
84 "testsuite/gdb.arch/pa-nullify.s", "testsuite/gdb.arch/pa64-nullify.s", 211 "gdb/osf-share",
85 "testsuite/gdb.asm/asmsrc1.s", "testsuite/gdb.asm/asmsrc2.s", 212 "gdb/gdbtk",
86 "testsuite/gdb.disasm/am33.s", "testsuite/gdb.disasm/h8300s.s", 213 "gdb/testsuite/gdb.gdbtk/",
87 "testsuite/gdb.disasm/hppa.s", "testsuite/gdb.disasm/mn10200.s", 214 "sim/arm/armemu.h", "sim/arm/armos.c", "sim/arm/gdbhost.c",
88 "testsuite/gdb.disasm/mn10300.s", "testsuite/gdb.disasm/sh3.s", 215 "sim/arm/dbg_hif.h", "sim/arm/dbg_conf.h", "sim/arm/communicate.h",
89 "testsuite/gdb.disasm/t01_mov.s", "testsuite/gdb.disasm/t02_mova.s", 216 "sim/arm/armos.h", "sim/arm/armcopro.c", "sim/arm/armemu.c",
90 "testsuite/gdb.disasm/t03_add.s", "testsuite/gdb.disasm/t04_sub.s", 217 "sim/arm/kid.c", "sim/arm/thumbemu.c", "sim/arm/armdefs.h",
91 "testsuite/gdb.disasm/t05_cmp.s", "testsuite/gdb.disasm/t06_ari2.s", 218 "sim/arm/armopts.h", "sim/arm/dbg_cp.h", "sim/arm/dbg_rdi.h",
92 "testsuite/gdb.disasm/t07_ari3.s", "testsuite/gdb.disasm/t08_or.s", 219 "sim/arm/parent.c", "sim/arm/armsupp.c", "sim/arm/armrdi.c",
93 "testsuite/gdb.disasm/t09_xor.s", "testsuite/gdb.disasm/t10_and.s", 220 "sim/arm/bag.c", "sim/arm/armvirt.c", "sim/arm/main.c", "sim/arm/bag.h",
94 "testsuite/gdb.disasm/t11_logs.s", "testsuite/gdb.disasm/t12_bit.s", 221 "sim/arm/communicate.c", "sim/arm/gdbhost.h", "sim/arm/armfpe.h",
95 "testsuite/gdb.disasm/t13_otr.s", "testsuite/gdb.hp/gdb.base-hp/reg-pa64.s", 222 "sim/arm/arminit.c",
96 "testsuite/gdb.hp/gdb.base-hp/reg.s", 223 "sim/common/cgen-fpu.c", "sim/common/cgen-fpu.h", "sim/common/cgen-fpu.h",
97 "../sim/testsuite/d10v-elf/exit47.s", 224 "sim/common/cgen-accfp.c", "sim/common/sim-fpu.c",
98 "../sim/testsuite/d10v-elf/hello.s", 225 "sim/erc32/sis.h", "sim/erc32/erc32.c", "sim/erc32/func.c",
99 "../sim/testsuite/d10v-elf/loop.s", 226 "sim/erc32/float.c", "sim/erc32/interf.c", "sim/erc32/sis.c",
100 "../sim/testsuite/d10v-elf/t-ae-ld-d.s", 227 "sim/erc32/exec.c",
101 "../sim/testsuite/d10v-elf/t-ae-ld-i.s", 228 "sim/mips/m16run.c", "sim/mips/sim-main.c",
102 "../sim/testsuite/d10v-elf/t-ae-ld-id.s", 229 "sim/mn10300/sim-main.h",
103 "../sim/testsuite/d10v-elf/t-ae-ld-im.s", 230 "sim/moxie/moxie-gdb.dts",
104 "../sim/testsuite/d10v-elf/t-ae-ld-ip.s", 231 # Not a single file in sim/ppc/ appears to be copyright FSF :-(.
105 "../sim/testsuite/d10v-elf/t-ae-ld2w-d.s", 232 "sim/ppc/filter.h", "sim/ppc/gen-support.h", "sim/ppc/ld-insn.h",
106 "../sim/testsuite/d10v-elf/t-ae-ld2w-i.s", 233 "sim/ppc/hw_sem.c", "sim/ppc/hw_disk.c", "sim/ppc/idecode_branch.h",
107 "../sim/testsuite/d10v-elf/t-ae-ld2w-id.s", 234 "sim/ppc/sim-endian.h", "sim/ppc/table.c", "sim/ppc/hw_core.c",
108 "../sim/testsuite/d10v-elf/t-ae-ld2w-im.s", 235 "sim/ppc/gen-support.c", "sim/ppc/gen-semantics.h", "sim/ppc/cpu.h",
109 "../sim/testsuite/d10v-elf/t-ae-ld2w-ip.s", 236 "sim/ppc/sim_callbacks.h", "sim/ppc/RUN", "sim/ppc/Makefile.in",
110 "../sim/testsuite/d10v-elf/t-ae-st-d.s", 237 "sim/ppc/emul_chirp.c", "sim/ppc/hw_nvram.c", "sim/ppc/dc-test.01",
111 "../sim/testsuite/d10v-elf/t-ae-st-i.s", 238 "sim/ppc/hw_phb.c", "sim/ppc/hw_eeprom.c", "sim/ppc/bits.h",
112 "../sim/testsuite/d10v-elf/t-ae-st-id.s", 239 "sim/ppc/hw_vm.c", "sim/ppc/cap.h", "sim/ppc/os_emul.h",
113 "../sim/testsuite/d10v-elf/t-ae-st-im.s", 240 "sim/ppc/options.h", "sim/ppc/gen-idecode.c", "sim/ppc/filter.c",
114 "../sim/testsuite/d10v-elf/t-ae-st-ip.s", 241 "sim/ppc/corefile-n.h", "sim/ppc/std-config.h", "sim/ppc/ld-decode.h",
115 "../sim/testsuite/d10v-elf/t-ae-st-is.s", 242 "sim/ppc/filter_filename.h", "sim/ppc/hw_shm.c",
116 "../sim/testsuite/d10v-elf/t-ae-st2w-d.s", 243 "sim/ppc/pk_disklabel.c", "sim/ppc/dc-simple", "sim/ppc/misc.h",
117 "../sim/testsuite/d10v-elf/t-ae-st2w-i.s", 244 "sim/ppc/device_table.h", "sim/ppc/ld-insn.c", "sim/ppc/inline.c",
118 "../sim/testsuite/d10v-elf/t-ae-st2w-id.s", 245 "sim/ppc/emul_bugapi.h", "sim/ppc/hw_cpu.h", "sim/ppc/debug.h",
119 "../sim/testsuite/d10v-elf/t-ae-st2w-im.s", 246 "sim/ppc/hw_ide.c", "sim/ppc/debug.c", "sim/ppc/gen-itable.h",
120 "../sim/testsuite/d10v-elf/t-ae-st2w-ip.s", 247 "sim/ppc/interrupts.c", "sim/ppc/hw_glue.c", "sim/ppc/emul_unix.c",
121 "../sim/testsuite/d10v-elf/t-ae-st2w-is.s", 248 "sim/ppc/sim_calls.c", "sim/ppc/dc-complex", "sim/ppc/ld-cache.c",
122 "../sim/testsuite/d10v-elf/t-dbt.s", 249 "sim/ppc/registers.h", "sim/ppc/dc-test.02", "sim/ppc/options.c",
123 "../sim/testsuite/d10v-elf/t-ld-st.s", 250 "sim/ppc/igen.h", "sim/ppc/registers.c", "sim/ppc/device.h",
124 "../sim/testsuite/d10v-elf/t-mac.s", 251 "sim/ppc/emul_chirp.h", "sim/ppc/hw_register.c", "sim/ppc/hw_init.c",
125 "../sim/testsuite/d10v-elf/t-mod-ld-pre.s", 252 "sim/ppc/sim-endian-n.h", "sim/ppc/filter_filename.c",
126 "../sim/testsuite/d10v-elf/t-msbu.s", 253 "sim/ppc/bits.c", "sim/ppc/idecode_fields.h", "sim/ppc/hw_memory.c",
127 "../sim/testsuite/d10v-elf/t-mulxu.s", 254 "sim/ppc/misc.c", "sim/ppc/double.c", "sim/ppc/psim.h",
128 "../sim/testsuite/d10v-elf/t-mvtac.s", 255 "sim/ppc/hw_trace.c", "sim/ppc/emul_netbsd.h", "sim/ppc/psim.c",
129 "../sim/testsuite/d10v-elf/t-mvtc.s", 256 "sim/ppc/ppc-instructions", "sim/ppc/tree.h", "sim/ppc/README",
130 "../sim/testsuite/d10v-elf/t-rac.s", 257 "sim/ppc/gen-icache.h", "sim/ppc/gen-model.h", "sim/ppc/ld-cache.h",
131 "../sim/testsuite/d10v-elf/t-rachi.s", 258 "sim/ppc/mon.c", "sim/ppc/corefile.h", "sim/ppc/vm.c",
132 "../sim/testsuite/d10v-elf/t-rdt.s", 259 "sim/ppc/INSTALL", "sim/ppc/gen-model.c", "sim/ppc/hw_cpu.c",
133 "../sim/testsuite/d10v-elf/t-rep.s", 260 "sim/ppc/corefile.c", "sim/ppc/hw_opic.c", "sim/ppc/gen-icache.c",
134 "../sim/testsuite/d10v-elf/t-rie-xx.s", 261 "sim/ppc/events.h", "sim/ppc/os_emul.c", "sim/ppc/emul_generic.c",
135 "../sim/testsuite/d10v-elf/t-rte.s", 262 "sim/ppc/main.c", "sim/ppc/hw_com.c", "sim/ppc/gen-semantics.c",
136 "../sim/testsuite/d10v-elf/t-sac.s", 263 "sim/ppc/emul_bugapi.c", "sim/ppc/device.c", "sim/ppc/emul_generic.h",
137 "../sim/testsuite/d10v-elf/t-sachi.s", 264 "sim/ppc/tree.c", "sim/ppc/mon.h", "sim/ppc/interrupts.h",
138 "../sim/testsuite/d10v-elf/t-sadd.s", 265 "sim/ppc/cap.c", "sim/ppc/cpu.c", "sim/ppc/hw_phb.h",
139 "../sim/testsuite/d10v-elf/t-slae.s", 266 "sim/ppc/device_table.c", "sim/ppc/lf.c", "sim/ppc/lf.c",
140 "../sim/testsuite/d10v-elf/t-sp.s", 267 "sim/ppc/dc-stupid", "sim/ppc/hw_pal.c", "sim/ppc/ppc-spr-table",
141 "../sim/testsuite/d10v-elf/t-sub.s", 268 "sim/ppc/emul_unix.h", "sim/ppc/words.h", "sim/ppc/basics.h",
142 "../sim/testsuite/d10v-elf/t-sub2w.s", 269 "sim/ppc/hw_htab.c", "sim/ppc/lf.h", "sim/ppc/ld-decode.c",
143 "../sim/testsuite/d10v-elf/t-subi.s", 270 "sim/ppc/sim-endian.c", "sim/ppc/gen-itable.c",
144 "../sim/testsuite/d10v-elf/t-trap.s", 271 "sim/ppc/idecode_expression.h", "sim/ppc/table.h", "sim/ppc/dgen.c",
145 "../sim/testsuite/frv-elf/cache.s", 272 "sim/ppc/events.c", "sim/ppc/gen-idecode.h", "sim/ppc/emul_netbsd.c",
146 "../sim/testsuite/frv-elf/exit47.s", 273 "sim/ppc/igen.c", "sim/ppc/vm_n.h", "sim/ppc/vm.h",
147 "../sim/testsuite/frv-elf/grloop.s", 274 "sim/ppc/hw_iobus.c", "sim/ppc/inline.h",
148 "../sim/testsuite/frv-elf/hello.s", 275 "sim/testsuite/sim/bfin/s21.s", "sim/testsuite/sim/mips/mips32-dsp2.s",
149 "../sim/testsuite/frv-elf/loop.s", 276 )
150 "../sim/testsuite/m32r-elf/exit47.s",
151 "../sim/testsuite/m32r-elf/hello.s",
152 "../sim/testsuite/m32r-elf/loop.s",
153 "../sim/testsuite/sim/cris/hw/rv-n-cris/quit.s",
154 "../sim/testsuite/sim/h8300/addb.s",
155 "../sim/testsuite/sim/h8300/addl.s",
156 "../sim/testsuite/sim/h8300/adds.s",
157 "../sim/testsuite/sim/h8300/addw.s",
158 "../sim/testsuite/sim/h8300/addx.s",
159 "../sim/testsuite/sim/h8300/andb.s",
160 "../sim/testsuite/sim/h8300/andl.s",
161 "../sim/testsuite/sim/h8300/andw.s",
162 "../sim/testsuite/sim/h8300/band.s",
163 "../sim/testsuite/sim/h8300/bfld.s",
164 "../sim/testsuite/sim/h8300/biand.s",
165 "../sim/testsuite/sim/h8300/bra.s",
166 "../sim/testsuite/sim/h8300/brabc.s",
167 "../sim/testsuite/sim/h8300/bset.s",
168 "../sim/testsuite/sim/h8300/cmpb.s",
169 "../sim/testsuite/sim/h8300/cmpl.s",
170 "../sim/testsuite/sim/h8300/cmpw.s",
171 "../sim/testsuite/sim/h8300/daa.s",
172 "../sim/testsuite/sim/h8300/das.s",
173 "../sim/testsuite/sim/h8300/dec.s",
174 "../sim/testsuite/sim/h8300/div.s",
175 "../sim/testsuite/sim/h8300/extl.s",
176 "../sim/testsuite/sim/h8300/extw.s",
177 "../sim/testsuite/sim/h8300/inc.s",
178 "../sim/testsuite/sim/h8300/jmp.s",
179 "../sim/testsuite/sim/h8300/ldc.s",
180 "../sim/testsuite/sim/h8300/ldm.s",
181 "../sim/testsuite/sim/h8300/mac.s",
182 "../sim/testsuite/sim/h8300/mova.s",
183 "../sim/testsuite/sim/h8300/movb.s",
184 "../sim/testsuite/sim/h8300/movl.s",
185 "../sim/testsuite/sim/h8300/movmd.s",
186 "../sim/testsuite/sim/h8300/movsd.s",
187 "../sim/testsuite/sim/h8300/movw.s",
188 "../sim/testsuite/sim/h8300/mul.s",
189 "../sim/testsuite/sim/h8300/neg.s",
190 "../sim/testsuite/sim/h8300/nop.s",
191 "../sim/testsuite/sim/h8300/not.s",
192 "../sim/testsuite/sim/h8300/orb.s",
193 "../sim/testsuite/sim/h8300/orl.s",
194 "../sim/testsuite/sim/h8300/orw.s",
195 "../sim/testsuite/sim/h8300/rotl.s",
196 "../sim/testsuite/sim/h8300/rotr.s",
197 "../sim/testsuite/sim/h8300/rotxl.s",
198 "../sim/testsuite/sim/h8300/rotxr.s",
199 "../sim/testsuite/sim/h8300/shal.s",
200 "../sim/testsuite/sim/h8300/shar.s",
201 "../sim/testsuite/sim/h8300/shll.s",
202 "../sim/testsuite/sim/h8300/shlr.s",
203 "../sim/testsuite/sim/h8300/stack.s",
204 "../sim/testsuite/sim/h8300/stc.s",
205 "../sim/testsuite/sim/h8300/subb.s",
206 "../sim/testsuite/sim/h8300/subl.s",
207 "../sim/testsuite/sim/h8300/subs.s",
208 "../sim/testsuite/sim/h8300/subw.s",
209 "../sim/testsuite/sim/h8300/subx.s",
210 "../sim/testsuite/sim/h8300/tas.s",
211 "../sim/testsuite/sim/h8300/xorb.s",
212 "../sim/testsuite/sim/h8300/xorl.s",
213 "../sim/testsuite/sim/h8300/xorw.s",
214 "../sim/testsuite/sim/mips/fpu64-ps-sb1.s",
215 "../sim/testsuite/sim/mips/fpu64-ps.s",
216 "../sim/testsuite/sim/mips/hilo-hazard-1.s",
217 "../sim/testsuite/sim/mips/hilo-hazard-2.s",
218 "../sim/testsuite/sim/mips/hilo-hazard-3.s",
219 "../sim/testsuite/sim/mips/mdmx-ob-sb1.s",
220 "../sim/testsuite/sim/mips/mdmx-ob.s",
221 "../sim/testsuite/sim/mips/mips32-dsp.s",
222 "../sim/testsuite/sim/mips/mips32-dsp2.s",
223 "../sim/testsuite/sim/mips/sanity.s",
224 "../sim/testsuite/sim/sh/add.s",
225 "../sim/testsuite/sim/sh/and.s",
226 "../sim/testsuite/sim/sh/bandor.s",
227 "../sim/testsuite/sim/sh/bandornot.s",
228 "../sim/testsuite/sim/sh/bclr.s",
229 "../sim/testsuite/sim/sh/bld.s",
230 "../sim/testsuite/sim/sh/bldnot.s",
231 "../sim/testsuite/sim/sh/bset.s",
232 "../sim/testsuite/sim/sh/bst.s",
233 "../sim/testsuite/sim/sh/bxor.s",
234 "../sim/testsuite/sim/sh/clip.s",
235 "../sim/testsuite/sim/sh/div.s",
236 "../sim/testsuite/sim/sh/dmxy.s",
237 "../sim/testsuite/sim/sh/fabs.s",
238 "../sim/testsuite/sim/sh/fadd.s",
239 "../sim/testsuite/sim/sh/fail.s",
240 "../sim/testsuite/sim/sh/fcmpeq.s",
241 "../sim/testsuite/sim/sh/fcmpgt.s",
242 "../sim/testsuite/sim/sh/fcnvds.s",
243 "../sim/testsuite/sim/sh/fcnvsd.s",
244 "../sim/testsuite/sim/sh/fdiv.s",
245 "../sim/testsuite/sim/sh/fipr.s",
246 "../sim/testsuite/sim/sh/fldi0.s",
247 "../sim/testsuite/sim/sh/fldi1.s",
248 "../sim/testsuite/sim/sh/flds.s",
249 "../sim/testsuite/sim/sh/float.s",
250 "../sim/testsuite/sim/sh/fmac.s",
251 "../sim/testsuite/sim/sh/fmov.s",
252 "../sim/testsuite/sim/sh/fmul.s",
253 "../sim/testsuite/sim/sh/fneg.s",
254 "../sim/testsuite/sim/sh/fpchg.s",
255 "../sim/testsuite/sim/sh/frchg.s",
256 "../sim/testsuite/sim/sh/fsca.s",
257 "../sim/testsuite/sim/sh/fschg.s",
258 "../sim/testsuite/sim/sh/fsqrt.s",
259 "../sim/testsuite/sim/sh/fsrra.s",
260 "../sim/testsuite/sim/sh/fsub.s",
261 "../sim/testsuite/sim/sh/ftrc.s",
262 "../sim/testsuite/sim/sh/ldrc.s",
263 "../sim/testsuite/sim/sh/loop.s",
264 "../sim/testsuite/sim/sh/macl.s",
265 "../sim/testsuite/sim/sh/macw.s",
266 "../sim/testsuite/sim/sh/mov.s",
267 "../sim/testsuite/sim/sh/movi.s",
268 "../sim/testsuite/sim/sh/movli.s",
269 "../sim/testsuite/sim/sh/movua.s",
270 "../sim/testsuite/sim/sh/movxy.s",
271 "../sim/testsuite/sim/sh/mulr.s",
272 "../sim/testsuite/sim/sh/pabs.s",
273 "../sim/testsuite/sim/sh/padd.s",
274 "../sim/testsuite/sim/sh/paddc.s",
275 "../sim/testsuite/sim/sh/pand.s",
276 "../sim/testsuite/sim/sh/pass.s",
277 "../sim/testsuite/sim/sh/pclr.s",
278 "../sim/testsuite/sim/sh/pdec.s",
279 "../sim/testsuite/sim/sh/pdmsb.s",
280 "../sim/testsuite/sim/sh/pinc.s",
281 "../sim/testsuite/sim/sh/pmuls.s",
282 "../sim/testsuite/sim/sh/prnd.s",
283 "../sim/testsuite/sim/sh/pshai.s",
284 "../sim/testsuite/sim/sh/pshar.s",
285 "../sim/testsuite/sim/sh/pshli.s",
286 "../sim/testsuite/sim/sh/pshlr.s",
287 "../sim/testsuite/sim/sh/psub.s",
288 "../sim/testsuite/sim/sh/pswap.s",
289 "../sim/testsuite/sim/sh/pushpop.s",
290 "../sim/testsuite/sim/sh/resbank.s",
291 "../sim/testsuite/sim/sh/sett.s",
292 "../sim/testsuite/sim/sh/shll.s",
293 "../sim/testsuite/sim/sh/shll16.s",
294 "../sim/testsuite/sim/sh/shll2.s",
295 "../sim/testsuite/sim/sh/shll8.s",
296 "../sim/testsuite/sim/sh/shlr.s",
297 "../sim/testsuite/sim/sh/shlr16.s",
298 "../sim/testsuite/sim/sh/shlr2.s",
299 "../sim/testsuite/sim/sh/shlr8.s",
300 "../sim/testsuite/sim/sh/swap.s",
301 "../sim/testsuite/sim/sh64/misc/fr-dr.s",
302 # .inc files. These are usually assembly or C files...
303 "testsuite/gdb.asm/alpha.inc",
304 "testsuite/gdb.asm/arm.inc",
305 "testsuite/gdb.asm/common.inc",
306 "testsuite/gdb.asm/empty.inc",
307 "testsuite/gdb.asm/frv.inc",
308 "testsuite/gdb.asm/h8300.inc",
309 "testsuite/gdb.asm/i386.inc",
310 "testsuite/gdb.asm/ia64.inc",
311 "testsuite/gdb.asm/iq2000.inc",
312 "testsuite/gdb.asm/m32c.inc",
313 "testsuite/gdb.asm/m32r-linux.inc",
314 "testsuite/gdb.asm/m32r.inc",
315 "testsuite/gdb.asm/m68hc11.inc",
316 "testsuite/gdb.asm/m68k.inc",
317 "testsuite/gdb.asm/mips.inc",
318 "testsuite/gdb.asm/netbsd.inc",
319 "testsuite/gdb.asm/openbsd.inc",
320 "testsuite/gdb.asm/pa.inc",
321 "testsuite/gdb.asm/pa64.inc",
322 "testsuite/gdb.asm/powerpc.inc",
323 "testsuite/gdb.asm/powerpc64.inc",
324 "testsuite/gdb.asm/s390.inc",
325 "testsuite/gdb.asm/s390x.inc",
326 "testsuite/gdb.asm/sh.inc",
327 "testsuite/gdb.asm/sparc.inc",
328 "testsuite/gdb.asm/sparc64.inc",
329 "testsuite/gdb.asm/spu.inc",
330 "testsuite/gdb.asm/v850.inc",
331 "testsuite/gdb.asm/x86_64.inc",
332 "testsuite/gdb.asm/xstormy16.inc",
333 "../sim/testsuite/sim/arm/iwmmxt/testutils.inc",
334 "../sim/testsuite/sim/arm/testutils.inc",
335 "../sim/testsuite/sim/arm/thumb/testutils.inc",
336 "../sim/testsuite/sim/arm/xscale/testutils.inc",
337 "../sim/testsuite/sim/cr16/testutils.inc",
338 "../sim/testsuite/sim/cris/asm/testutils.inc",
339 "../sim/testsuite/sim/cris/hw/rv-n-cris/testutils.inc",
340 "../sim/testsuite/sim/fr30/testutils.inc",
341 "../sim/testsuite/sim/frv/testutils.inc",
342 "../sim/testsuite/sim/h8300/testutils.inc",
343 "../sim/testsuite/sim/m32r/testutils.inc",
344 "../sim/testsuite/sim/sh/testutils.inc",
345 "../sim/testsuite/sim/sh64/compact/testutils.inc",
346 "../sim/testsuite/sim/sh64/media/testutils.inc",
347 "../sim/testsuite/sim/v850/testutils.inc",
348 )
349
350 # A mapping between file extensions to their associated Comment object.
351 # This dictionary also contains a number of exceptions, based on
352 # filename.
353 COMMENT_MAP = \
354 {".1" : Comment(start=r'.\"'),
355 ".ac" : Comment(start="dnl", start2="#"),
356 ".ads" : ADA_COMMENT,
357 ".adb" : ADA_COMMENT,
358 ".f" : Comment(start="c"),
359 ".f90" : Comment(start="!"),
360 ".gpr" : ADA_COMMENT,
361 ".inc" : Comment(start="#", start2=";"),
362 ".s" : Comment(start="!"),
363 ".tex" : Comment(start="%"),
364 ".texi" : Comment(start="@c"),
365 ".texinfo" : Comment(start="@c"),
366
367 # Files that use a different way of including the copyright
368 # header...
369 "ada-operator.inc" : Comment(start="/*", stop="*/"),
370 "gdbint.texinfo" : Comment(start='@copying', stop="@end copying"),
371 "annotate.texinfo" : Comment(start='@copying', stop="@end copying",
372 max_lines=50),
373 "stabs.texinfo" : Comment(start='@copying', stop="@end copying"),
374 }
375
376 class NotFound(Exception):
377 pass
378
379 class AlreadyDone(Exception):
380 pass
381
382 def process_header(src, dst, cdescr):
383 """Read from SRC for up to CDESCR.MAX_LINES until we find a copyright
384 notice. If found, then write the entire file, with the copyright
385 noticed updated with the current year added.
386
387 Raises NotFound if the copyright notice could not be found or has
388 some inconsistencies.
389
390 Raises AlreadyDone if the copyright notice already includes the current
391 year.
392 """
393 line_count = 0
394 # The start-of-comment marker used for this file. Only really useful
395 # in the case where comments ends at the end of the line, as this
396 # allows us to know which comment marker to use when breaking long
397 # lines (in the cases where there are more than one.
398 cdescr_start = ""
399
400 while True:
401 # If we still haven't found a copyright line within a certain
402 # number of lines, then give up.
403 if line_count > cdescr.max_lines:
404 raise NotFound("start of Copyright not found")
405
406 line = src.readline()
407 line_count += 1
408 if not line:
409 raise NotFound("start of Copyright not found (EOF)")
410
411 # Is this a copyright line? If not, then no transformation is
412 # needed. Write it as is, and continue.
413 if not re.search(r"Copyright\b.*\b(199\d|20\d\d)\b", line):
414 dst.write(line)
415 continue
416
417 # If a start-of-comment marker is needed for every line, try to
418 # figure out which one it is that is being used in this file (most
419 # files only accept one, in which case it's easy - but some accept
420 # two or more...).
421 if cdescr.stop is None:
422 stripped_line = line.lstrip()
423 if stripped_line.startswith(cdescr.start):
424 cdescr_start = cdescr.start
425 elif (cdescr.start2 is not None
426 and stripped_line.startswith(cdescr.start2)):
427 cdescr_start = cdescr.start2
428 elif cdescr.start in stripped_line:
429 cdescr_start = cdescr.start
430 elif (cdescr.start2 is not None
431 and cdescr.start2 in stripped_line):
432 cdescr_start = cdescr.start2
433 else:
434 # This can't be a line with a comment, so not the copyright
435 # line we were looking for. Ignore.
436 continue
437
438 comment = line
439 break
440
441 while not re.search(r"Free\s+Software\s+Foundation", comment):
442 line = src.readline()
443 line_count += 1
444 if not line:
445 raise NotFound("Copyright owner not found (EOF)")
446
447 if cdescr.stop is None:
448 # Expect a new comment marker at the start of each line
449 line = line.lstrip()
450 if not line.startswith(cdescr_start):
451 raise NotFound("Copyright owner not found "
452 "(end of comment)")
453 comment += " " + line[len(cdescr_start):]
454 else:
455 if cdescr.stop in comment:
456 raise NotFound("Copyright owner not found "
457 "(end of comment)")
458 comment += line
459
460 # Normalize a bit the copyright string (we preserve the string
461 # up until "Copyright", in order to help preserve any original
462 # alignment.
463 (before, after) = comment.split("Copyright", 1)
464 after = after.replace("\n", " ")
465 after = re.sub("\s+", " ", after)
466 after = after.rstrip()
467
468 # If the copyright year has already been added, the nothing else
469 # to do.
470 if THIS_YEAR in after:
471 raise AlreadyDone
472
473 m = re.match("(.*[0-9]+)(.*)", after)
474 if m is None:
475 raise NotFound("Internal error - cannot split copyright line: "
476 "`%s'" % comment)
477
478 # Reconstruct the comment line
479 comment = before + "Copyright" + m.group(1) + ', %s' % THIS_YEAR
480 owner_part = m.group(2).lstrip()
481
482 # Max comment len...
483 max_len = 76
484
485 # If we have to break the copyright line into multiple lines,
486 # we want to align all the lines on the "Copyright" keyword.
487 # Create a small "indent" string that we can use for that.
488 if cdescr.stop is None:
489 # The comment marker is needed on every line, so put it at the
490 # start of our "indent" string.
491 indent = cdescr_start + ' ' * (len(before) - len(cdescr_start))
492 else:
493 indent = ' ' * len(before)
494
495 # If the line is too long...
496 while len(comment) > max_len:
497 # Split the line at the first space before max_len.
498 space_index = comment[0:max_len].rfind(' ')
499 if space_index < 0: # No space in the first max_len characters???
500 # Split at the first space, then...
501 space_index = comment.find(' ')
502 if space_index < 0:
503 # Still no space found. This is extremely unlikely, but
504 # just pretend there is one at the end of the string.
505 space_index = len(comment)
506
507 # Write the first part of the string up until the space
508 # we selected to break our line.
509 dst.write(comment[:space_index] + '\n')
510
511 # Strip the part of comment that we have finished printing.
512 if space_index < len(comment):
513 comment = comment[space_index + 1:]
514 else:
515 comment = ""
516
517 # Prepend the "indent" string to make sure that we remain
518 # aligned on the "Copyright" word.
519 comment = indent + comment
520
521 # And finally, write the rest of the last line... We want to write
522 # "Free Software Foundation, Inc" on the same line, so handle this
523 # with extra care.
524 dst.write(comment)
525 if len(comment) + 1 + len (owner_part) > max_len:
526 dst.write('\n' + indent)
527 else:
528 dst.write(' ')
529 dst.write(owner_part + '\n')
530
531 def comment_for_filename(filename):
532 """Return the Comment object that best describes the given file.
533 This a smart lookup of the COMMENT_MAP dictionary where we check
534 for filename-based exceptions first, before looking up the comment
535 by filename extension. """
536 # First, consult the COMMENT_MAP using the filename, in case this
537 # file needs special treatment.
538 basename = os.path.basename(filename)
539 if basename in COMMENT_MAP:
540 return COMMENT_MAP[basename]
541 # Not a special file. Check the file extension.
542 ext = os.path.splitext(filename)[1]
543 if ext in COMMENT_MAP:
544 return COMMENT_MAP[ext]
545 # Not a know extension either, return None.
546 return None
547
548 def process_file(filename):
549 """Processes the given file.
550 """
551 cdescr = comment_for_filename(filename)
552 if cdescr is None:
553 # Either no filename extension, or not an extension that we
554 # know how to handle.
555 return
556
557 dst_filename = filename + '.new'
558 src = open(filename)
559 dst = open(dst_filename, 'w')
560 try:
561 process_header(src, dst, cdescr)
562 except AlreadyDone:
563 print "+++ Already up to date: `%s'." % filename
564 dst.close()
565 os.unlink(dst_filename)
566 if filename in NO_COPYRIGHT:
567 # We expect the search for a copyright header to fail, and
568 # yet we found one...
569 print "Warning: `%s' should not be in NO_COPYRIGHT" % filename
570 return
571 except NotFound as inst:
572 dst.close()
573 os.unlink(dst_filename)
574 if not filename in NO_COPYRIGHT:
575 print "*** \033[31m%s\033[0m: %s" % (filename, inst)
576 return
577
578 if filename in NO_COPYRIGHT:
579 # We expect the search for a copyright header to fail, and
580 # yet we found one...
581 print "Warning: `%s' should not be in NO_COPYRIGHT" % filename
582
583 for line in src:
584 dst.write(line)
585 src.close()
586 dst.close()
587 os.rename(dst_filename, filename)
588 277
589 if __name__ == "__main__": 278 if __name__ == "__main__":
590 if not os.path.isfile("doc/gdb.texinfo"): 279 main()
591 print "Error: This script must be called from the gdb directory." 280
592 for gdb_dir in ('.', '../sim', '../include/gdb'):
593 for root, dirs, files in os.walk(gdb_dir):
594 for filename in files:
595 fullpath = os.path.join(root, filename)
596 if fullpath.startswith('./'):
597 fullpath = fullpath[2:]
598 if filename not in EXCLUSION_LIST and fullpath not in BY_HAND:
599 # Paths that start with './' are ugly, so strip that.
600 # This also allows us to omit them in the NO_COPYRIGHT
601 # list...
602 process_file(fullpath)
603 print
604 print "\033[32mREMINDER: The following files must be updated by hand." \
605 "\033[0m"
606 for filename in BY_HAND:
607 print " ", filename
608
OLDNEW
« no previous file with comments | « gdb/contrib/test_pubnames_and_indexes.py ('k') | gdb/copyright.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698