From 709472a957af0a78e6374902786eb28c9742e2af Mon Sep 17 00:00:00 2001 From: Rob Mohr Date: Fri, 17 Apr 2020 11:50:47 -0700 Subject: [PATCH] pw_env_setup: add warning when using *.bat on Linux Change-Id: I62da6ad0f14fd0563eee07c20b8fd78e38b53e28 --- activate.bat | 9 ++++++++ bootstrap.bat | 9 ++++++++ .../py/pw_presubmit/pigweed_presubmit.py | 22 +++++++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/activate.bat b/activate.bat index 0068dc372..60afac225 100644 --- a/activate.bat +++ b/activate.bat @@ -1,3 +1,4 @@ +:<<"::WINDOWS_ONLY" @echo off :: Copyright 2020 The Pigweed Authors :: @@ -12,6 +13,13 @@ :: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the :: License for the specific language governing permissions and limitations under :: the License. +::WINDOWS_ONLY +:; echo "ERROR: Attempting to run Windows .bat from a Unix/POSIX shell!" +:; echo "Instead, run the following command." +:; echo "" +:; echo " source ./activate.sh" +:; echo "" +:<<"::WINDOWS_ONLY" :: Activates a Pigweed development environment by setting the appropriate :: environment variables. bootstrap.bat must be run initially to install all @@ -21,3 +29,4 @@ set PW_SKIP_BOOTSTRAP=1 call "%~dp0\bootstrap.bat" set PW_SKIP_BOOTSTRAP= +::WINDOWS_ONLY diff --git a/bootstrap.bat b/bootstrap.bat index 871371845..7abe3a422 100644 --- a/bootstrap.bat +++ b/bootstrap.bat @@ -1,3 +1,4 @@ +:<<"::WINDOWS_ONLY" @echo off :: Copyright 2020 The Pigweed Authors :: @@ -12,6 +13,13 @@ :: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the :: License for the specific language governing permissions and limitations under :: the License. +::WINDOWS_ONLY +:; echo "ERROR: Attempting to run Windows .bat from a Unix/POSIX shell!" +:; echo "Instead, run the following command." +:; echo "" +:; echo " source ./bootstrap.sh" +:; echo "" +:<<"::WINDOWS_ONLY" :: Pigweed Windows environment setup. @@ -86,3 +94,4 @@ set PW_CARGO_PACKAGE_FILES=%_PW_OLD_CARGO_PACKAGE_FILES% call "%shell_file%" :finish +::WINDOWS_ONLY diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py index 4d5009a80..d20442703 100755 --- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py +++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py @@ -299,6 +299,14 @@ if sys.platform != 'darwin': COPYRIGHT_FIRST_LINE = re.compile( r'^(#|//| \*|REM|::) Copyright 20\d\d The Pigweed Authors$') +COPYRIGHT_FIRST_LINE_EXCEPTIONS = ( + '#!', + '/*', + '@echo off', + '# -*-', + ':', +) + COPYRIGHT_LINES = tuple("""\ Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -340,13 +348,19 @@ def copyright_notice(ctx: PresubmitContext): for path in ctx.paths: _LOG.debug('Checking %s', path) with open(path) as file: - # Skip shebang and blank lines line = file.readline() - while line and (line.startswith( - ('#!', '/*', '@echo off', '# -*-')) or not line.strip()): + first_line = None + while line: + first_line = COPYRIGHT_FIRST_LINE.match(line) + if first_line: + break + + if (line.strip() and + not line.startswith(COPYRIGHT_FIRST_LINE_EXCEPTIONS)): + break + line = file.readline() - first_line = COPYRIGHT_FIRST_LINE.match(line) if not first_line: _LOG.debug('%s: invalid first line %r', path, line) errors.append(path)