pre-upload: don't require a particular comment style for license
License headers can be used in, e.g., plain text, or some other source
file format that doesn't require a leading space for other stylistic
reasons (e.g., .../platform2/shill/TESTING). So don't require it.
BUG=none
TEST=unit tests; also run against shill directory
Change-Id: I6a37b96485f03d649af7651724c18fb71bbd2f8b
Reviewed-on: https://chromium-review.googlesource.com/1247639
Commit-Ready: Ben Chan <benchan@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index 716c83b..9ffa89c 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -1053,18 +1053,18 @@
"""
# For older years, be a bit more flexible as our policy says leave them be.
LICENSE_HEADER = (
- r'.* Copyright( \(c\))? 20[-0-9]{2,7} The Chromium OS Authors\. '
+ r'.*Copyright( \(c\))? 20[-0-9]{2,7} The Chromium OS Authors\. '
r'All rights reserved\.' r'\n'
- r'.* Use of this source code is governed by a BSD-style license that can '
+ r'.*Use of this source code is governed by a BSD-style license that can '
r'be\n'
- r'.* found in the LICENSE file\.'
+ r'.*found in the LICENSE file\.'
r'\n'
)
license_re = re.compile(LICENSE_HEADER, re.MULTILINE)
# For newer years, be stricter.
COPYRIGHT_LINE = (
- r'.* Copyright \(c\) 20(1[5-9]|[2-9][0-9]) The Chromium OS Authors\. '
+ r'.*Copyright \(c\) 20(1[5-9]|[2-9][0-9]) The Chromium OS Authors\. '
r'All rights reserved\.' r'\n'
)
copyright_re = re.compile(COPYRIGHT_LINE)
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 4091fca..115da98 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -754,6 +754,19 @@
self.content_mock.return_value = header
self.assertNotEqual(None, 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.assertEqual(None, pre_upload._check_cros_license('proj', 'sha1'))
+
def testIgnoreExcludedPaths(self):
"""Ignores excluded paths for license checks."""
self.file_mock.return_value = ['foo/OWNERS']