mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-28 14:15:19 -04:00
[cmake] Cleanup accross the entire build system (#5527)
Co-authored-by: Mathieu Taillefumier <mathieu.taillefumier@free.fr>
This commit is contained in:
parent
c75d734d70
commit
f50e850e17
24 changed files with 186 additions and 119 deletions
|
|
@ -93,6 +93,7 @@ FLAG_EXCEPTIONS_RE = re.compile(r"|".join(FLAG_EXCEPTIONS))
|
|||
PORTABLE_FILENAME_RE = re.compile(r"^[a-zA-Z0-9._/#~=+-]*$")
|
||||
OP_RE = re.compile(r"[\\|()!&><=*/+-]")
|
||||
NUM_RE = re.compile(r"[0-9]+[ulUL]*")
|
||||
NO_DEFAULT_PATH_RE = re.compile(r"\bNO_DEFAULT_PATH\b")
|
||||
CP2K_FLAGS_RE = re.compile(
|
||||
r"FUNCTION cp2k_flags\(\)(.*)END FUNCTION cp2k_flags", re.DOTALL
|
||||
)
|
||||
|
|
@ -309,6 +310,14 @@ def check_file(path: pathlib.Path) -> List[str]:
|
|||
f"{path}: CMake option {opt} not mentioned in docs/technologies section nor build-from-source.md"
|
||||
]
|
||||
|
||||
# NO_DEFAULT_PATH disables searching CMAKE_PREFIX_PATH and other default
|
||||
# locations, which breaks Spack, system-package, and HPC-module installs
|
||||
# unless every possible layout is hand-enumerated in PATHS/HINTS - don't use it.
|
||||
if (
|
||||
fn_ext == ".cmake" or path.name == "CMakeLists.txt"
|
||||
) and NO_DEFAULT_PATH_RE.search(content):
|
||||
warnings += [f"{path}: Found NO_DEFAULT_PATH, please remove it"]
|
||||
|
||||
# Check for DOIs that could be a bibliography reference.
|
||||
if re.match(r"docs/[^/]+/.*\.md", str(path)) and "docs/CP2K_INPUT" not in str(path):
|
||||
for line in content.splitlines():
|
||||
|
|
|
|||
27
tools/precommit/cmake-lint.yaml
Normal file
27
tools/precommit/cmake-lint.yaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
lint:
|
||||
disabled_codes:
|
||||
# Missing docstring on function/macro declaration - not CP2K's convention.
|
||||
- C0111
|
||||
# Line too long - false positive on the "#!"-style license banner that
|
||||
# every .cmake/CMakeLists.txt file starts with; cmake-format deliberately
|
||||
# does not rewrap "#!" comment lines, so they stay at their original width.
|
||||
- C0301
|
||||
# Invalid variable/argument/macro name - CP2K's convention is to prefix
|
||||
# local/private names with one or more underscores (e.g. "_package_name",
|
||||
# "__var") and to use snake_case for macros, neither of which matches
|
||||
# cmake-lint's default naming patterns. This also fires spuriously on
|
||||
# dynamically composed variable names like "CP2K_${_varname}_ROOT", which
|
||||
# no static naming pattern can ever match.
|
||||
- C0103
|
||||
# Missing COMMENT in add_custom_command()/add_custom_target() - stylistic,
|
||||
# not required by this codebase.
|
||||
- C0113
|
||||
# Bad indentation on wrapped multi-line arguments - cmake-lint's
|
||||
# indentation heuristic disagrees with cmake-format's own line-wrapping
|
||||
# in several already-formatted, correct files; not a reliable signal here.
|
||||
- C0307
|
||||
# "String looks like a variable reference missing an open tag" - false
|
||||
# positive on deliberately-escaped "\${VAR}" references inside
|
||||
# install(CODE "...") scripts, where the escaping defers expansion to
|
||||
# install time on purpose.
|
||||
- W0106
|
||||
|
|
@ -256,6 +256,7 @@ def process_file(fn: str, allow_modifications: bool) -> None:
|
|||
|
||||
if re.match(r"(.*/CMakeLists.txt)|(.*\.cmake)$", fn):
|
||||
run_remote_tool("cmakeformat", fn)
|
||||
run_remote_tool("cmakelint", fn)
|
||||
|
||||
if re.match(r"./data/.*POTENTIALS?$", fn):
|
||||
check_data_files()
|
||||
|
|
|
|||
|
|
@ -67,6 +67,18 @@ def cmakeformat():
|
|||
return run_tool(["cmake-format", "-i"], timeout=30)
|
||||
|
||||
|
||||
# ======================================================================================
|
||||
@app.route("/cmakelint", methods=["POST"])
|
||||
def cmakelint():
|
||||
# Note: the config path must be passed as a single "--flag=value" token.
|
||||
# cmake-lint's "-c"/"--config-files" option is nargs="+", so passing it as
|
||||
# two separate argv tokens ("-c", path) would greedily swallow the target
|
||||
# filename that run_tool() appends as another config file, and silently
|
||||
# scan zero files instead.
|
||||
config = f"--config-files={os.getcwd()}/cmake-lint.yaml"
|
||||
return run_tool(["cmake-lint", config], timeout=30)
|
||||
|
||||
|
||||
# ======================================================================================
|
||||
@app.route("/fortitude", methods=["POST"])
|
||||
def fortitude():
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ mypy_extensions==1.1.0
|
|||
packaging==26.0
|
||||
pathspec==1.0.4
|
||||
platformdirs==4.9.2
|
||||
pyyaml==6.0.3
|
||||
pytokens==0.4.1
|
||||
ruamel.yaml==0.19.1
|
||||
six==1.17.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue