pre-upload: lock down copyright checks

We're doing a tree-wide update to handle all the copyright changes.
So there's no need to allow old styles anymore.

BUG=chromium:1098010
TEST=./pre-upload_unittest.py passes

Change-Id: Id8db836a31375085d15b579729a06da9147961d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/repohooks/+/3876909
Commit-Queue: Cindy Lin <xcl@google.com>
Reviewed-by: Cindy Lin <xcl@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 59ef72d..62b3488 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -1833,7 +1833,7 @@
   LICENSE_HEADER = (
       # Line 1 - copyright.
       r'.*Copyright(?P<copyright> \(c\))? (?P<year>20[0-9]{2})(?:-20[0-9]{2})? '
-      r'The Chromium(?P<chromium_space_os> )?OS Authors\.'
+      r'The Chromium(?P<chromium_space_os> )?OS Authors(?P<period>\.)?'
       r'(?P<rights_reserved> All rights reserved\.)?\n'
       # Line 2 - License.
       r'.*Use of this source code is governed by a BSD-style license that can '
@@ -1850,6 +1850,7 @@
   bad_year_files = []
   bad_chromiumos_files = []
   bad_rights_reserved_files = []
+  bad_period_files = []
 
   files = _filter_files(
       _get_affected_files(commit, relative=True),
@@ -1871,17 +1872,16 @@
     else:
       new_file = f not in existing_files
       year = int(license_match.group('year'))
-      if license_match.group('copyright') and year >= 2015:
-        # Forbid "(c)" in all files since 2015.
+      if license_match.group('copyright'):
         bad_copyright_files.append(f)
       if new_file and year != current_year:
         bad_year_files.append(f)
-      if (license_match.group('chromium_space_os') and
-          (new_file or year >= 2023)):
+      if license_match.group('chromium_space_os'):
         bad_chromiumos_files.append(f)
-      if (license_match.group('rights_reserved') and
-          (new_file or year >= 2023)):
+      if license_match.group('rights_reserved'):
         bad_rights_reserved_files.append(f)
+      if license_match.group('period'):
+        bad_period_files.append(f)
 
   errors = []
   if bad_files:
@@ -1890,17 +1890,20 @@
         'Found a bad header in these files:')
     errors.append(HookFailure(msg, bad_files))
   if bad_copyright_files:
-    msg = 'Do not use (c) in copyright headers in new files:'
+    msg = 'Do not use (c) in copyright headers:'
     errors.append(HookFailure(msg, bad_copyright_files))
   if bad_year_files:
     msg = 'Use current year (%s) in copyright headers in new files:' % (
         current_year)
     errors.append(HookFailure(msg, bad_year_files))
   if bad_chromiumos_files:
-    msg = 'Use ChromiumOS instead of Chromium OS in new files:'
+    msg = 'Use ChromiumOS instead of Chromium OS:'
     errors.append(HookFailure(msg, bad_chromiumos_files))
   if bad_rights_reserved_files:
-    msg = 'Do not include "All rights reserved." in new files:'
+    msg = 'Do not include "All rights reserved.":'
+    errors.append(HookFailure(msg, bad_rights_reserved_files))
+  if bad_period_files:
+    msg = 'Do not include period after "ChromiumOS Authors":'
     errors.append(HookFailure(msg, bad_rights_reserved_files))
 
   return errors
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 4f7c783..de24ea8 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -1424,33 +1424,15 @@
     self.file_mock = self.PatchObject(pre_upload, '_get_affected_files')
     self.content_mock = self.PatchObject(pre_upload, '_get_file_content')
 
-  def testOldHeaders(self):
-    """Accept old header styles."""
-    HEADERS = (
-        ('#!/bin/sh\n'
-         '# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.\n'
-         '# Use of this source code is governed by a BSD-style license that'
-         ' can be\n'
-         '# found in the LICENSE file.\n'),
-        ('// Copyright 2010-2013 The Chromium OS Authors. All rights reserved.'
-         '\n// Use of this source code is governed by a BSD-style license that'
-         ' can be\n'
-         '// found in the LICENSE file.\n'),
-    )
-    self.file_mock.return_value = ['file']
-    for header in HEADERS:
-      self.content_mock.return_value = header
-      self.assertFalse(pre_upload._check_cros_license('proj', 'sha1'))
-
   def testNewFileYear(self):
     """Added files should have the current year in license header."""
     year = datetime.datetime.now().year
     HEADERS = (
-        ('// Copyright 2016 The ChromiumOS Authors.\n'
+        ('// Copyright 2016 The ChromiumOS Authors\n'
          '// Use of this source code is governed by a BSD-style license that'
          ' can be\n'
          '// found in the LICENSE file.\n'),
-        ('// Copyright %d The ChromiumOS Authors.\n'
+        ('// Copyright %d The ChromiumOS Authors\n'
          '// Use of this source code is governed by a BSD-style license that'
          ' can be\n'
          '// found in the LICENSE file.\n') % year,
@@ -1472,7 +1454,7 @@
         self.assertFalse(pre_upload._check_cros_license('proj', 'sha1'))
 
   def testRejectC(self):
-    """Reject the (c) in newer headers."""
+    """Reject the (c) in headers."""
     HEADERS = (
         ('// Copyright (c) 2015 The Chromium OS Authors. All rights reserved.'
          '\n'
@@ -1491,13 +1473,13 @@
       self.assertTrue(pre_upload._check_cros_license('proj', 'sha1'))
 
   def testRejectChromiumSpaceOs(self):
-    """Reject Chromium OS in newer headers."""
+    """Reject Chromium OS in headers."""
     HEADERS = (
-        ('// Copyright 2023 The Chromium OS Authors.\n'
+        ('// Copyright 2023 The Chromium OS Authors\n'
          '// Use of this source code is governed by a BSD-style license that'
          ' can be\n'
          '// found in the LICENSE file.\n'),
-        ('// Copyright 2030 The Chromium OS Authors.\n'
+        ('// Copyright 2030 The Chromium OS Authors\n'
          '// Use of this source code is governed by a BSD-style license that'
          ' can be\n'
          '// found in the LICENSE file.\n'),
@@ -1508,7 +1490,7 @@
       self.assertTrue(pre_upload._check_cros_license('proj', 'sha1'))
 
   def testRejectAllRightsReserved(self):
-    """Reject all rights reserved in newer headers."""
+    """Reject all rights reserved in headers."""
     HEADERS = (
         ('// Copyright 2023 The ChromiumOS Authors. All rights reserved.\n'
          '// Use of this source code is governed by a BSD-style license that'
@@ -1524,19 +1506,6 @@
       self.content_mock.return_value = header
       self.assertTrue(pre_upload._check_cros_license('proj', 'sha1'))
 
-  def testNoLeadingSpace(self):
-    """Allow headers without leading space (e.g., not a source comment)"""
-    HEADERS = (
-        ('Copyright 2018 The Chromium OS Authors. All rights reserved.\n'
-         'Use of this source code is governed by a BSD-style license that '
-         'can be\n'
-         'found in the LICENSE file.\n'),
-    )
-    self.file_mock.return_value = ['file']
-    for header in HEADERS:
-      self.content_mock.return_value = header
-      self.assertFalse(pre_upload._check_cros_license('proj', 'sha1'))
-
   def testNoExcludedGolang(self):
     """Don't exclude .go files for license checks."""
     self.file_mock.return_value = ['foo/main.go']