From bbe3abd8dbee0a91b5bfad214821768610b10371 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Tue, 18 Jun 2019 13:25:44 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1665449 Reviewed-by: Daisuke Nojiri --- util/presubmit_check.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 -- cgit v1.2.1