Skip to content

Commit

Permalink
Add missing #pragma onces, and an automated check (#6389)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Chamayou <[email protected]>
  • Loading branch information
eddyashton and achamayou authored Jul 25, 2024
1 parent bc1d75e commit f1b6f5b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
8 changes: 5 additions & 3 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -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"):
Expand Down Expand Up @@ -61,7 +63,7 @@
}

# -----------------------------
# Options effecting formatting.
# Options affecting formatting.
# -----------------------------
with section("format"):
# How wide to allow formatted cmake files
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/ccf/endpoints/authentication/js.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/ccf/historical_queries_utils.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
64 changes: 37 additions & 27 deletions scripts/notice-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 [
Expand All @@ -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


Expand Down
2 changes: 2 additions & 0 deletions src/apps/js_generic/js_generic_base.h
Original file line number Diff line number Diff line change
@@ -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 <memory>
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/aft/test/test_common.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/node/rpc/test/frontend_test_infra.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit f1b6f5b

Please sign in to comment.