Crafter.LintRules/project.cpp
Jorijn van der Graaf 88139fc0fc
Initial import: the house-style lint rules as a crafter-build module
Moved out of Crafter.Build's lint-rules.h so a project.cpp pulls them in
with `#pragma crafter dependency` + `import Crafter.LintRules;` instead of
copying a header. The rule bodies are unchanged; format-concat now sits
with the other transforms (it rewrites, it was registered as a report),
and the helpers are module-internal. tests/HouseRules moved along with
the rules and links crafter-build from git, or the sibling checkout with
--local.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-02 20:03:24 +02:00

40 lines
1.8 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
std::vector<std::string> depArgs(args.begin(), args.end());
const bool useLocal = std::erase(depArgs, "--local") > 0;
Configuration cfg;
cfg.path = "./";
cfg.name = "Crafter.LintRules";
cfg.outputName = "Crafter.LintRules";
cfg.type = ConfigurationType::LibraryStatic;
ApplyStandardArgs(cfg, args);
// No dependency on Crafter.Build, on purpose. The rules only ever run
// inside a crafter-build process, which provides the symbols, and a host
// build already sees the Crafter.Build modules through the PCM cache
// crafter-build keeps for its own project files — declaring the library
// here would make every consumer clone and build all of crafter-build
// just to lint.
std::array<fs::path, 1> ifaces = { "interfaces/Crafter.LintRules" };
std::array<fs::path, 0> impls = {};
cfg.GetInterfacesAndImplementations(ifaces, impls);
// The rule test compiles the module as its own interface and links
// crafter-build to run the linter in-process: from git by default, or
// the sibling checkout with `crafter-build test --local`. Host only,
// like the rules themselves.
if (cfg.target == "x86_64-pc-linux-gnu") {
Configuration* build = useLocal
? LocalProject({ .projectFile = "../Crafter.Build/project.cpp", .args = depArgs })
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Build.git" }, .args = depArgs });
cfg.AddTest("HouseRules", ifaces).Dependencies({ build });
}
return cfg;
}