22This script updates the list of years in the copyright notices in
23most files maintained by the GDB project.
25Usage: cd src/gdb && ./copyright.py
27Always review the output of this script before committing it!
28A useful command to review the output is:
29 % filterdiff -x \*.c -x \*.cc -x \*.h -x \*.exp updates.diff
30This removes the bulk of the changes which are most likely to be correct.
40from typing import List, Optional
44 """Return the list of files to update.
46 Assumes that the current working directory when called is the root
47 of the GDB source tree (NOT the gdb/ subdirectory!). The names of
48 the files are relative to that root directory.
59 for root, dirs, files
in os.walk(gdb_dir, topdown=
True):
61 reldirname =
"%s/%s" % (root, dirname)
63 dirname
in EXCLUDE_ALL_LIST
64 or reldirname
in EXCLUDE_LIST
65 or reldirname
in NOT_FSF_LIST
66 or reldirname
in BY_HAND
70 for filename
in files:
71 relpath =
"%s/%s" % (root, filename)
73 filename
in EXCLUDE_ALL_LIST
74 or relpath
in EXCLUDE_LIST
75 or relpath
in NOT_FSF_LIST
81 result.append(relpath)
86 """Update the copyright header of the files in the given list.
88 We use gnulib's update-copyright script for that.
94 os.environ[
"UPDATE_COPYRIGHT_USE_INTERVALS"] =
"2"
97 update_cmd = [
"bash",
"gnulib/import/extra/update-copyright"]
98 update_cmd += update_list
100 p = subprocess.Popen(
102 stdout=subprocess.PIPE,
103 stderr=subprocess.STDOUT,
104 encoding=locale.getpreferredencoding(),
106 update_out = p.communicate()[0]
116 update_out = update_out.splitlines(keepends=
False)
117 warning_string =
": warning: copyright statement not found"
118 warning_len = len(warning_string)
120 for line
in update_out:
121 if line.endswith(warning_string):
122 filename = line[:-warning_len]
131 """Check that the given file does not seem to have a copyright notice.
133 The filename is relative to the root directory.
134 This function assumes that the current working directory
is that root
137 The algorithm
is fairly crude, meaning that it might
return
138 some false positives. I do
not think it will
return any false
139 negatives... We might improve this function to handle more
140 complex cases later...
151 with open(filename,
"rb")
as fd:
152 for lineno, line
in enumerate(fd, start=1):
153 if b
"Copyright" in line:
155 if lineno > MAX_LINES:
161 """Get a command line parser."""
162 parser = argparse.ArgumentParser(
163 description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
168def main(argv: List[str]) -> Optional[int]:
169 """The main subprogram."""
171 _ = parser.parse_args(argv)
172 root_dir = os.path.dirname(os.getcwd())
176 os.path.isdir(
"gdb")
and os.path.isfile(
"gnulib/import/extra/update-copyright")
178 sys.exit(
"Error: This script must be called from the gdb directory.")
185 if MULTIPLE_COPYRIGHT_HEADERS:
189 "REMINDER: Multiple copyright headers must be updated by hand:"
192 for filename
in MULTIPLE_COPYRIGHT_HEADERS:
198 "\033[31mREMINDER: The following files must be updated by hand." "\033[0m"
200 for filename
in BY_HAND:
218 "gdb/nat/glibc_thread_db.h",
220 "gdbsupport/Makefile.in",
223 "gnulib/Makefile.in",
253MULTIPLE_COPYRIGHT_HEADERS = (
254 "gdb/doc/gdb.texinfo",
255 "gdb/doc/refcard.tex",
256 "gdb/syscalls/update-netbsd.sh",
262 "gdb/exc_request.defs",
264 "gdb/testsuite/gdb.gdbtk/",
269 "sim/arm/dbg_conf.h",
270 "sim/arm/communicate.h",
272 "sim/arm/armcopro.c",
275 "sim/arm/thumbemu.c",
287 "sim/arm/communicate.c",
291 "sim/common/cgen-fpu.c",
292 "sim/common/cgen-fpu.h",
293 "sim/common/cgen-accfp.c",
295 "sim/mips/sim-main.c",
296 "sim/moxie/moxie-gdb.dts",
299 "sim/ppc/gen-support.h",
303 "sim/ppc/idecode_branch.h",
304 "sim/ppc/sim-endian.h",
307 "sim/ppc/gen-support.c",
308 "sim/ppc/gen-semantics.h",
310 "sim/ppc/sim_callbacks.h",
312 "sim/ppc/Makefile.in",
313 "sim/ppc/emul_chirp.c",
314 "sim/ppc/hw_nvram.c",
315 "sim/ppc/dc-test.01",
317 "sim/ppc/hw_eeprom.c",
323 "sim/ppc/gen-idecode.c",
325 "sim/ppc/corefile-n.h",
326 "sim/ppc/std-config.h",
327 "sim/ppc/ld-decode.h",
328 "sim/ppc/filter_filename.h",
330 "sim/ppc/pk_disklabel.c",
333 "sim/ppc/device_table.h",
336 "sim/ppc/emul_bugapi.h",
341 "sim/ppc/gen-itable.h",
342 "sim/ppc/interrupts.c",
344 "sim/ppc/emul_unix.c",
345 "sim/ppc/sim_calls.c",
346 "sim/ppc/dc-complex",
347 "sim/ppc/ld-cache.c",
348 "sim/ppc/registers.h",
349 "sim/ppc/dc-test.02",
352 "sim/ppc/registers.c",
354 "sim/ppc/emul_chirp.h",
355 "sim/ppc/hw_register.c",
357 "sim/ppc/sim-endian-n.h",
358 "sim/ppc/filter_filename.c",
360 "sim/ppc/idecode_fields.h",
361 "sim/ppc/hw_memory.c",
365 "sim/ppc/hw_trace.c",
366 "sim/ppc/emul_netbsd.h",
368 "sim/ppc/powerpc.igen",
371 "sim/ppc/gen-icache.h",
372 "sim/ppc/gen-model.h",
373 "sim/ppc/ld-cache.h",
375 "sim/ppc/corefile.h",
378 "sim/ppc/gen-model.c",
380 "sim/ppc/corefile.c",
382 "sim/ppc/gen-icache.c",
385 "sim/ppc/emul_generic.c",
388 "sim/ppc/gen-semantics.c",
389 "sim/ppc/emul_bugapi.c",
391 "sim/ppc/emul_generic.h",
394 "sim/ppc/interrupts.h",
398 "sim/ppc/device_table.c",
403 "sim/ppc/ppc-spr-table",
404 "sim/ppc/emul_unix.h",
409 "sim/ppc/ld-decode.c",
410 "sim/ppc/sim-endian.c",
411 "sim/ppc/gen-itable.c",
412 "sim/ppc/idecode_expression.h",
416 "sim/ppc/gen-idecode.h",
417 "sim/ppc/emul_netbsd.c",
421 "sim/ppc/hw_iobus.c",
423 "sim/testsuite/mips/mips32-dsp2.s",
426if __name__ ==
"__main__":
427 sys.exit(
main(sys.argv[1:]))
argparse.ArgumentParser get_parser()
may_have_copyright_notice(filename)
update_files(update_list)