#include #include #include #include #include #include #include #include namespace { std::filesystem::path FindRepoRoot() { std::filesystem::path current = std::filesystem::current_path(); while (!current.empty()) { if (std::filesystem::exists(current / "xmake.lua") && std::filesystem::exists( current / "libs/wire/include/remote_action.h") && std::filesystem::exists( current / "apps/desktop/xmake/targets.lua")) { return current; } current = current.parent_path(); } return {}; } std::string ReadFile(const std::filesystem::path& path) { std::ifstream file(path, std::ios::binary); if (!file) { return {}; } std::ostringstream contents; contents << file.rdbuf(); return contents.str(); } bool IsCheckedWireFile(const std::filesystem::path& path) { static constexpr std::array kExtensions = { ".h", ".hpp", ".c", ".cc", ".cpp", ".m", ".mm", ".lua"}; const std::string extension = path.extension().string(); for (std::string_view candidate : kExtensions) { if (extension == candidate) { return true; } } return false; } bool CheckWireBoundary(const std::filesystem::path& repo_root) { static constexpr std::array kForbiddenReferences = { "apps/desktop", "../desktop", "platform/common", "", "", "(character))) { compact_call.push_back(character); } } if (call.find(kPlatformPath) != std::string_view::npos && compact_call.find("public=true") != std::string::npos) { std::cerr << "platform implementation include directory is public: " << call << '\n'; ok = false; } cursor = call_end + 1; } return ok; } bool CheckWireLayout(const std::filesystem::path& repo_root) { static constexpr std::array kForbiddenPaths = { "libs/wire/include/crossdesk", "libs/wire/xmake.lua", "libs/wire/.xmake", "xmake.protocol.lua", "xmake.wire.lua"}; bool ok = true; for (std::string_view relative_path : kForbiddenPaths) { if (!std::filesystem::exists(repo_root / relative_path)) { continue; } std::cerr << "forbidden legacy layer, standalone project, or wire cache: " << relative_path << '\n'; ok = false; } return ok; } } // namespace int main() { const std::filesystem::path repo_root = FindRepoRoot(); if (repo_root.empty()) { std::cerr << "failed to locate repository root\n"; return 1; } bool ok = true; static constexpr std::array kLegacyRootDirectories = { "src", "ios", "scripts", "icons", "tests", "xmake", "shared", "platforms", "wire", "submodules", "thirdparty"}; for (std::string_view directory : kLegacyRootDirectories) { if (!std::filesystem::exists(repo_root / directory)) { continue; } std::cerr << "legacy root directory still exists: " << directory << '\n'; ok = false; } ok &= CheckWireBoundary(repo_root); ok &= CheckPlatformIncludesArePrivate(repo_root); ok &= CheckWireLayout(repo_root); return ok ? 0 : 1; }