diff --git a/.cmake-format.py b/.cmake-format.py index 3d68ccdba5c6..afc456b82dc9 100644 --- a/.cmake-format.py +++ b/.cmake-format.py @@ -1,4 +1,6 @@ -# ---------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache 2.0 License. +# # ---------------------------------- # Options affecting listfile parsing # ---------------------------------- with section("parse"): @@ -61,7 +63,7 @@ } # ----------------------------- -# Options effecting formatting. +# Options affecting formatting. # ----------------------------- with section("format"): # How wide to allow formatted cmake files @@ -237,7 +239,7 @@ max_statements = 50 # ------------------------------- -# Options effecting file encoding +# Options affecting file encoding # ------------------------------- with section("encode"): # If true, emit the unicode byte-order mark (BOM) at the start of the file diff --git a/include/ccf/endpoints/authentication/js.h b/include/ccf/endpoints/authentication/js.h index e14afdd50a4d..2b843902094c 100644 --- a/include/ccf/endpoints/authentication/js.h +++ b/include/ccf/endpoints/authentication/js.h @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +#pragma once #include "ccf/common_auth_policies.h" #include "ccf/endpoint.h" diff --git a/include/ccf/historical_queries_utils.h b/include/ccf/historical_queries_utils.h index 133dcd10b996..825ead71ee3a 100644 --- a/include/ccf/historical_queries_utils.h +++ b/include/ccf/historical_queries_utils.h @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +#pragma once #include "ccf/historical_queries_interface.h" #include "ccf/network_identity_interface.h" diff --git a/scripts/notice-check.py b/scripts/notice-check.py index 6d046f84c6c6..2676f4784858 100644 --- a/scripts/notice-check.py +++ b/scripts/notice-check.py @@ -10,11 +10,29 @@ "Licensed under the Apache 2.0 License.", ] -PREFIXES_CCF = [ - os.linesep.join([prefix + " " + line for line in NOTICE_LINES_CCF]) - for prefix in ["//", "--", "#"] +SLASH_PREFIXED = os.linesep.join(["// " + line for line in NOTICE_LINES_CCF]) +HASH_PREFIXED = os.linesep.join(["# " + line for line in NOTICE_LINES_CCF]) + +# Must have a '#pragma once' line +HEADERS_WITH_PRAGMAS = [ + SLASH_PREFIXED + os.linesep + "#pragma once", + # Maybe there's a single blank line + SLASH_PREFIXED + os.linesep + os.linesep + "#pragma once", ] -PREFIXES_CCF.append("#!/bin/bash" + os.linesep + PREFIXES_CCF[-1]) + +PREFIX_BY_FILETYPE = { + ".c": [SLASH_PREFIXED], + ".cpp": [SLASH_PREFIXED], + ".h": HEADERS_WITH_PRAGMAS, + ".hpp": HEADERS_WITH_PRAGMAS, + ".py": [HASH_PREFIXED], + ".sh": [ + HASH_PREFIXED, + # May have a shebang before the license + "#!/bin/bash" + os.linesep + HASH_PREFIXED, + ], + ".cmake": [HASH_PREFIXED], +} def has_notice(path, prefixes): @@ -26,13 +44,6 @@ def has_notice(path, prefixes): return False -def is_src(name): - for suffix in [".c", ".cpp", ".h", ".hpp", ".py", ".sh", ".cmake"]: - if name.endswith(suffix): - return True - return False - - def submodules(): r = subprocess.run(["git", "submodule", "status"], capture_output=True, check=True) return [ @@ -42,26 +53,25 @@ def submodules(): ] -def gitignored(path): - r = subprocess.run(["git", "check-ignore", path], capture_output=True, check=False) - return r.returncode == 0 # Returns 0 for files which _are_ ignored +EXCLUDED = ["3rdparty", ".git", "build", "env"] + submodules() + + +def list_files(suffix): + cmd = f"git ls-files | grep -E -v \"{'|'.join('^' + prefix for prefix in EXCLUDED)}\" | grep -e '\{suffix}$'" + r = subprocess.run( + cmd, + capture_output=True, + shell=True, + ) + return r.stdout.decode().splitlines() def check_ccf(): missing = [] - excluded = ["3rdparty", ".git", "build", "env"] + submodules() - for root, dirs, files in os.walk("."): - for edir in excluded: - if edir in dirs: - dirs.remove(edir) - for name in files: - if name.startswith("."): - continue - if is_src(name): - path = os.path.join(root, name) - if not gitignored(path): - if not has_notice(path, PREFIXES_CCF): - missing.append(path) + for file_suffix, notice_lines in PREFIX_BY_FILETYPE.items(): + for path in list_files(file_suffix): + if not has_notice(path, notice_lines): + missing.append(path) return missing diff --git a/src/apps/js_generic/js_generic_base.h b/src/apps/js_generic/js_generic_base.h index 9693dfa03e2c..d992358fab2e 100644 --- a/src/apps/js_generic/js_generic_base.h +++ b/src/apps/js_generic/js_generic_base.h @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +#pragma once + #include "ccf/app_interface.h" #include diff --git a/src/consensus/aft/test/test_common.h b/src/consensus/aft/test/test_common.h index cbbe6810766e..463eee251a97 100644 --- a/src/consensus/aft/test/test_common.h +++ b/src/consensus/aft/test/test_common.h @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +#pragma once + #include "ccf/ds/logger.h" #include "consensus/aft/raft.h" #include "kv/test/stub_consensus.h" diff --git a/src/node/rpc/test/frontend_test_infra.h b/src/node/rpc/test/frontend_test_infra.h index 815dbb7d4264..f03accdcfcec 100644 --- a/src/node/rpc/test/frontend_test_infra.h +++ b/src/node/rpc/test/frontend_test_infra.h @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the Apache 2.0 License. +#pragma once + #define DOCTEST_CONFIG_IMPLEMENT #define DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS #include "ccf/app_interface.h"