From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 554F23858D1E; Wed, 4 Jan 2023 11:44:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554F23858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672832684; bh=oCwDnDpGPKGv9+eqfXo7y1KDwLW04pDdPt0+fzplDcc=; h=From:To:Subject:Date:From; b=A3fqUnzunGc63c2ppoQoQBMv5E8oh5HefAQafdjnRLI1xtvu9d4PobMtj/qkJWp9u VsPrwa//iEreW8LxSAzFcNC9nY0FxzMU7t15gXeZSzXbj+MFFAm34tVVZsfGhHcX/e 5Jd0bdnbIB0mLu1XP2VB/kT3gFTX1VqfgC3b8ua8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_40-branch] Update etc/update-copyright.py X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/binutils-2_40-branch X-Git-Oldrev: f4e184b2747542b123cd06c7f9a4fbaaedc1bbca X-Git-Newrev: 26e7db51c269c863d05923b5551e9692561ec582 Message-Id: <20230104114444.554F23858D1E@sourceware.org> Date: Wed, 4 Jan 2023 11:44:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D26e7db51c269= c863d05923b5551e9692561ec582 commit 26e7db51c269c863d05923b5551e9692561ec582 Author: Alan Modra Date: Sun Jan 1 16:33:14 2023 +1030 Update etc/update-copyright.py =20 This picks up some improvements from gcc/contrib. exceptions must derive from BaseException, port to python3, retain original file mode, fix name of script in examples. =20 Adds libsframe to list of default dirs. I would have added gprofng too but there are some files claiming copyright by authors other than the Free Software Foundation. Diff: --- etc/update-copyright.py | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/etc/update-copyright.py b/etc/update-copyright.py index f0036cae212..fcbf1045d1b 100755 --- a/etc/update-copyright.py +++ b/etc/update-copyright.py @@ -1,6 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -# Copyright (C) 2013-2022 Free Software Foundation, Inc. +# Copyright (C) 2013-2023 Free Software Foundation, Inc. # # This script is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,15 +23,15 @@ # output has been vetted. You can instead pass the names of individual # directories, including those that haven't been approved. So: # -# update-copyright.pl --this-year +# update-copyright.py --this-year # # is the command that would be used at the beginning of a year to update # all copyright notices (and possibly at other times to check whether # new files have been added with old years). On the other hand: # -# update-copyright.pl --this-year libjava +# update-copyright.py --this-year libiberty # -# would run the script on just libjava/. +# would run the script on just libiberty/. # # This script was copied from gcc's contrib/ and modified to suit # binutils. In contrast to the gcc script, this one will update @@ -60,7 +60,10 @@ class GenericFilter: def __init__ (self): self.skip_files =3D set() self.skip_dirs =3D set() - self.skip_extensions =3D set() + self.skip_extensions =3D set([ + '.png', + '.pyc', + ]) self.fossilised_files =3D set() self.own_files =3D set() =20 @@ -238,7 +241,7 @@ class Copyright: def add_external_author (self, holder): self.holders[holder] =3D None =20 - class BadYear(): + class BadYear (Exception): def __init__ (self, year): self.year =3D year =20 @@ -315,7 +318,7 @@ class Copyright: # If it looks like the copyright is incomplete, add the next l= ine. while not self.is_complete (match): try: - next_line =3D file.next() + next_line =3D file.readline() except StopIteration: break =20 @@ -394,6 +397,15 @@ class Copyright: =20 return (line !=3D orig_line, line, next_line) =20 + def guess_encoding (self, pathname): + for encoding in ('utf8', 'iso8859'): + try: + open(pathname, 'r', encoding=3Dencoding).read() + return encoding + except UnicodeDecodeError: + pass + return None + def process_file (self, dir, filename, filter): pathname =3D os.path.join (dir, filename) if filename.endswith ('.tmp'): @@ -407,8 +419,11 @@ class Copyright: lines =3D [] changed =3D False line_filter =3D filter.get_line_filter (dir, filename) - with open (pathname, 'r') as file: + mode =3D None + encoding =3D self.guess_encoding(pathname) + with open (pathname, 'r', encoding=3Dencoding) as file: prev =3D None + mode =3D os.fstat (file.fileno()).st_mode for line in file: while line: next_line =3D None @@ -432,9 +447,10 @@ class Copyright: # If something changed, write the new file out. if changed and self.errors.ok(): tmp_pathname =3D pathname + '.tmp' - with open (tmp_pathname, 'w') as file: + with open (tmp_pathname, 'w', encoding=3Dencoding) as file: for line in lines: file.write (line) + os.fchmod (file.fileno(), mode) if self.use_quilt: subprocess.call (['quilt', 'add', pathname]) os.rename (tmp_pathname, pathname) @@ -442,7 +458,7 @@ class Copyright: def process_tree (self, tree, filter): for (dir, subdirs, filenames) in os.walk (tree): # Don't recurse through directories that should be skipped. - for i in xrange (len (subdirs) - 1, -1, -1): + for i in range (len (subdirs) - 1, -1, -1): if filter.skip_dir (dir, subdirs[i]): del subdirs[i] =20 @@ -593,13 +609,18 @@ class BinutilsCmdLine (CmdLine): self.add_dir ('etc') self.add_dir ('gas') self.add_dir ('gdb') + self.add_dir ('gdbserver') + self.add_dir ('gdbsupport') self.add_dir ('gold') self.add_dir ('gprof') + self.add_dir ('gprofng') self.add_dir ('include') self.add_dir ('ld', LdFilter()) + self.add_dir ('libbacktrace') self.add_dir ('libctf') self.add_dir ('libdecnumber') self.add_dir ('libiberty') + self.add_dir ('libsframe') self.add_dir ('opcodes') self.add_dir ('readline') self.add_dir ('sim') @@ -616,6 +637,7 @@ class BinutilsCmdLine (CmdLine): 'ld', 'libctf', 'libiberty', + 'libsframe', 'opcodes', ]