diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2019-06-18 13:25:44 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-20 01:29:33 +0000 |
commit | bbe3abd8dbee0a91b5bfad214821768610b10371 (patch) | |
tree | def2a7b49fa5a19c7b7badf1ff31aebc40bebbed /util/presubmit_check.sh | |
parent | e4fdb9124042cb21ecfb3df8004f0697756bbbad (diff) | |
download | chrome-ec-bbe3abd8dbee0a91b5bfad214821768610b10371.tar.gz |
presubmit: add check for newlines in CPRINTS strings
There should be no newlines in string parameters of the CPRINTS()
macro, it adds a newline unconditionally.
BRANCH=none
BUG=none
TEST=created a failing patch and observed expected error message:
. $ ./util/presubmit_check.sh
. +++ b/chip/g/usb-stream.c
. + CPRINTS("this is a bad, bad, string\n", yes);
. error: CPRINTS strings should not include newline characters
Change-Id: I9b6338743d2493aa731dd49ae35f9de043fd860b
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1665449
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util/presubmit_check.sh')
-rwxr-xr-x | util/presubmit_check.sh | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/util/presubmit_check.sh b/util/presubmit_check.sh index 822633f0f8..ed1cbe6071 100755 --- a/util/presubmit_check.sh +++ b/util/presubmit_check.sh @@ -4,6 +4,23 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# Verify there is no CPRINTS("....\n", ...) statements added to the code. +upstream_branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} \ + 2>/dev/null)" +if [[ -z ${upstream_branch} ]]; then + echo "Current branch does not have an upstream branch" >&2 + exit 1 +fi +# This will print the offending CPRINTS invocations, if any, and the names of +# the files they are in. +if git diff "${upstream_branch}" HEAD | grep -e '^+\(.*CPRINTS(.*\\n"\|++\)' | + grep CPRINTS -B1 >&2 ; then + echo "error: CPRINTS strings should not include newline characters" >&2 + exit 1 +fi + +# Verify that all targets were built and all tests passed after the latest +# source code modification. if [[ ! -e .tests-passed ]]; then echo 'Unit tests have not passed. Please run "make buildall -j".' exit 1 |