1 #! /usr/bin/env python3
3 # Copyright (C) 2011-2022 Free Software Foundation, Inc.
5 # This file is part of GDB.
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.
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.
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/>.
22 This script updates the list of years in the copyright notices in
23 most files maintained by the GDB project.
25 Usage: cd src/gdb && python copyright.py
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.
41 def get_update_list():
42 """Return the list of files to update.
44 Assumes that the current working directory when called is the root
45 of the GDB source tree (NOT the gdb/ subdirectory!). The names of
46 the files are relative to that root directory.
57 for root
, dirs
, files
in os
.walk(gdb_dir
, topdown
=True):
59 reldirname
= "%s/%s" % (root
, dirname
)
61 dirname
in EXCLUDE_ALL_LIST
62 or reldirname
in EXCLUDE_LIST
63 or reldirname
in NOT_FSF_LIST
64 or reldirname
in BY_HAND
66 # Prune this directory from our search list.
68 for filename
in files
:
69 relpath
= "%s/%s" % (root
, filename
)
71 filename
in EXCLUDE_ALL_LIST
72 or relpath
in EXCLUDE_LIST
73 or relpath
in NOT_FSF_LIST
79 result
.append(relpath
)
83 def update_files(update_list
):
84 """Update the copyright header of the files in the given list.
86 We use gnulib's update-copyright script for that.
88 # We want to use year intervals in the copyright notices, and
89 # all years should be collapsed to one single year interval,
90 # even if there are "holes" in the list of years found in the
91 # original copyright notice (OK'ed by the FSF, case [gnu.org #719834]).
92 os
.environ
["UPDATE_COPYRIGHT_USE_INTERVALS"] = "2"
94 # Perform the update, and save the output in a string.
95 update_cmd
= ["bash", "gnulib/import/extra/update-copyright"]
96 update_cmd
+= update_list
100 stdout
=subprocess
.PIPE
,
101 stderr
=subprocess
.STDOUT
,
102 encoding
=locale
.getpreferredencoding(),
104 update_out
= p
.communicate()[0]
106 # Process the output. Typically, a lot of files do not have
107 # a copyright notice :-(. The update-copyright script prints
108 # a well defined warning when it did not find the copyright notice.
109 # For each of those, do a sanity check and see if they may in fact
110 # have one. For the files that are found not to have one, we filter
111 # the line out from the output, since there is nothing more to do,
112 # short of looking at each file and seeing which notice is appropriate.
113 # Too much work! (~4,000 files listed as of 2012-01-03).
114 update_out
= update_out
.splitlines(keepends
=False)
115 warning_string
= ": warning: copyright statement not found"
116 warning_len
= len(warning_string
)
118 for line
in update_out
:
119 if line
.endswith(warning_string
):
120 filename
= line
[:-warning_len
]
121 if may_have_copyright_notice(filename
):
124 # Unrecognized file format. !?!
128 def may_have_copyright_notice(filename
):
129 """Check that the given file does not seem to have a copyright notice.
131 The filename is relative to the root directory.
132 This function assumes that the current working directory is that root
135 The algorithm is fairly crude, meaning that it might return
136 some false positives. I do not think it will return any false
137 negatives... We might improve this function to handle more
138 complex cases later...
140 # For now, it may have a copyright notice if we find the word
141 # "Copyright" at the (reasonable) start of the given file, say
145 # We don't really know what encoding each file might be following,
146 # so just open the file as a byte stream. We only need to search
147 # for a pattern that should be the same regardless of encoding,
148 # so that should be good enough.
149 fd
= open(filename
, "rb")
153 if b
"Copyright" in line
:
162 """The main subprogram."""
163 root_dir
= os
.path
.dirname(os
.getcwd())
167 os
.path
.isdir("gdb") and os
.path
.isfile("gnulib/import/extra/update-copyright")
169 print("Error: This script must be called from the gdb directory.")
172 update_list
= get_update_list()
173 update_files(update_list
)
175 # Remind the user that some files need to be updated by HAND...
177 if MULTIPLE_COPYRIGHT_HEADERS
:
181 "REMINDER: Multiple copyright headers must be updated by hand:"
184 for filename
in MULTIPLE_COPYRIGHT_HEADERS
:
190 "\033[31mREMINDER: The following files must be updated by hand." "\033[0m"
192 for filename
in BY_HAND
:
196 ############################################################################
198 # Some constants, placed at the end because they take up a lot of room.
199 # The actual value of these constants is not significant to the understanding
202 ############################################################################
204 # Files which should not be modified, either because they are
205 # generated, non-FSF, or otherwise special (e.g. license text,
206 # or test cases which must be sensitive to line numbering).
208 # Filenames are relative to the root directory.
210 "gdb/nat/glibc_thread_db.h",
212 "gdbsupport/Makefile.in",
215 "gnulib/Makefile.in",
218 # Files which should not be modified, either because they are
219 # generated, non-FSF, or otherwise special (e.g. license text,
220 # or test cases which must be sensitive to line numbering).
222 # Matches any file or directory name anywhere. Use with caution.
223 # This is mostly for files that can be found in multiple directories.
224 # Eg: We want all files named COPYING to be left untouched.
237 # The list of files to update by hand.
239 # Nothing at the moment :-).
242 # Files containing multiple copyright headers. This script is only
243 # fixing the first one it finds, so we need to finish the update
245 MULTIPLE_COPYRIGHT_HEADERS
= (
246 "gdb/doc/gdb.texinfo",
247 "gdb/doc/refcard.tex",
248 "gdb/syscalls/update-netbsd.sh",
251 # The list of file which have a copyright, but not held by the FSF.
252 # Filenames are relative to the root directory.
254 "gdb/exc_request.defs",
256 "gdb/testsuite/gdb.gdbtk/",
261 "sim/arm/dbg_conf.h",
262 "sim/arm/communicate.h",
264 "sim/arm/armcopro.c",
267 "sim/arm/thumbemu.c",
279 "sim/arm/communicate.c",
283 "sim/common/cgen-fpu.c",
284 "sim/common/cgen-fpu.h",
285 "sim/common/cgen-accfp.c",
287 "sim/mips/sim-main.c",
288 "sim/moxie/moxie-gdb.dts",
289 # Not a single file in sim/ppc/ appears to be copyright FSF :-(.
291 "sim/ppc/gen-support.h",
295 "sim/ppc/idecode_branch.h",
296 "sim/ppc/sim-endian.h",
299 "sim/ppc/gen-support.c",
300 "sim/ppc/gen-semantics.h",
302 "sim/ppc/sim_callbacks.h",
304 "sim/ppc/Makefile.in",
305 "sim/ppc/emul_chirp.c",
306 "sim/ppc/hw_nvram.c",
307 "sim/ppc/dc-test.01",
309 "sim/ppc/hw_eeprom.c",
315 "sim/ppc/gen-idecode.c",
317 "sim/ppc/corefile-n.h",
318 "sim/ppc/std-config.h",
319 "sim/ppc/ld-decode.h",
320 "sim/ppc/filter_filename.h",
322 "sim/ppc/pk_disklabel.c",
325 "sim/ppc/device_table.h",
328 "sim/ppc/emul_bugapi.h",
333 "sim/ppc/gen-itable.h",
334 "sim/ppc/interrupts.c",
336 "sim/ppc/emul_unix.c",
337 "sim/ppc/sim_calls.c",
338 "sim/ppc/dc-complex",
339 "sim/ppc/ld-cache.c",
340 "sim/ppc/registers.h",
341 "sim/ppc/dc-test.02",
344 "sim/ppc/registers.c",
346 "sim/ppc/emul_chirp.h",
347 "sim/ppc/hw_register.c",
349 "sim/ppc/sim-endian-n.h",
350 "sim/ppc/filter_filename.c",
352 "sim/ppc/idecode_fields.h",
353 "sim/ppc/hw_memory.c",
357 "sim/ppc/hw_trace.c",
358 "sim/ppc/emul_netbsd.h",
360 "sim/ppc/ppc-instructions",
363 "sim/ppc/gen-icache.h",
364 "sim/ppc/gen-model.h",
365 "sim/ppc/ld-cache.h",
367 "sim/ppc/corefile.h",
370 "sim/ppc/gen-model.c",
372 "sim/ppc/corefile.c",
374 "sim/ppc/gen-icache.c",
377 "sim/ppc/emul_generic.c",
380 "sim/ppc/gen-semantics.c",
381 "sim/ppc/emul_bugapi.c",
383 "sim/ppc/emul_generic.h",
386 "sim/ppc/interrupts.h",
390 "sim/ppc/device_table.c",
395 "sim/ppc/ppc-spr-table",
396 "sim/ppc/emul_unix.h",
401 "sim/ppc/ld-decode.c",
402 "sim/ppc/sim-endian.c",
403 "sim/ppc/gen-itable.c",
404 "sim/ppc/idecode_expression.h",
408 "sim/ppc/gen-idecode.h",
409 "sim/ppc/emul_netbsd.c",
413 "sim/ppc/hw_iobus.c",
415 "sim/testsuite/mips/mips32-dsp2.s",
418 if __name__
== "__main__":