From 23b6896f5f662a45d013199a39c5404e2261f655 Mon Sep 17 00:00:00 2001 From: Artur Harasimiuk Date: Thu, 20 Sep 2018 14:27:16 +0200 Subject: [PATCH] fix copyright checker properly handle files starting with #include or #pragma Change-Id: I89b438ef36d796c2e005bb2241a97bf5e4d9e48c Signed-off-by: Artur Harasimiuk --- scripts/lint/set_copyright.py | 22 +++++++++++++++++----- scripts/tests/copyright/in/file6.cpp | 3 +++ scripts/tests/copyright/in/file7.cpp | 3 +++ scripts/tests/copyright/out/file6.cpp | 10 ++++++++++ scripts/tests/copyright/out/file7.cpp | 10 ++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 scripts/tests/copyright/in/file6.cpp create mode 100644 scripts/tests/copyright/in/file7.cpp create mode 100644 scripts/tests/copyright/out/file6.cpp create mode 100644 scripts/tests/copyright/out/file7.cpp diff --git a/scripts/lint/set_copyright.py b/scripts/lint/set_copyright.py index a11164ab54..95432e5dcf 100644 --- a/scripts/lint/set_copyright.py +++ b/scripts/lint/set_copyright.py @@ -53,6 +53,11 @@ banned_paths = [ 'scripts/tests/copyright/out' ] +cpp_sharp_lines = [ + '#pragma', + '#include' +] + def isBanned(path): path_ok = False for banned_path in banned_paths: @@ -120,11 +125,18 @@ for path in sys.argv: line = f.readline() # check whether comment type is '#' - if first_line or line.startswith('#'): - header_start = '#' - header_end = '\n' - header = header_bash_style - comment_char = "#" + try: + if first_line or line.startswith('#'): + for a in cpp_sharp_lines: + print "a: %s ~ %s" % (a, line) + if line.startswith(a): + raise "c++" + header_start = '#' + header_end = '\n' + header = header_bash_style + comment_char = "#" + except: + pass curr_comment = list() diff --git a/scripts/tests/copyright/in/file6.cpp b/scripts/tests/copyright/in/file6.cpp new file mode 100644 index 0000000000..633a521486 --- /dev/null +++ b/scripts/tests/copyright/in/file6.cpp @@ -0,0 +1,3 @@ +#pragma once + +// header file with # in first line diff --git a/scripts/tests/copyright/in/file7.cpp b/scripts/tests/copyright/in/file7.cpp new file mode 100644 index 0000000000..573e043978 --- /dev/null +++ b/scripts/tests/copyright/in/file7.cpp @@ -0,0 +1,3 @@ +#include + +// header file with # in first line diff --git a/scripts/tests/copyright/out/file6.cpp b/scripts/tests/copyright/out/file6.cpp new file mode 100644 index 0000000000..60a179b819 --- /dev/null +++ b/scripts/tests/copyright/out/file6.cpp @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +// header file with # in first line diff --git a/scripts/tests/copyright/out/file7.cpp b/scripts/tests/copyright/out/file7.cpp new file mode 100644 index 0000000000..0b4f757508 --- /dev/null +++ b/scripts/tests/copyright/out/file7.cpp @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include + +// header file with # in first line