|
| 1 | +/** |
| 2 | + * @file ModulesContent.hpp |
| 3 | + * @author Gaspard Kirira |
| 4 | + * |
| 5 | + * Copyright 2025, Gaspard Kirira. All rights reserved. |
| 6 | + * https://github.com/vixcpp/vix |
| 7 | + * Use of this source code is governed by a MIT license |
| 8 | + * that can be found in the License file. |
| 9 | + * |
| 10 | + * Module naming / validation, CMake and C++ content generators, |
| 11 | + * and static analysis helpers for `vix modules`. |
| 12 | + */ |
| 13 | +#ifndef VIX_CLI_MODULES_CONTENT_HPP |
| 14 | +#define VIX_CLI_MODULES_CONTENT_HPP |
| 15 | + |
| 16 | +#include <filesystem> |
| 17 | +#include <set> |
| 18 | +#include <string> |
| 19 | +#include <unordered_set> |
| 20 | + |
| 21 | +namespace vix::commands::modules_cmd::content |
| 22 | +{ |
| 23 | + /// Replaces '-' with '_' and trims the name. |
| 24 | + std::string normalize_module_id(std::string name); |
| 25 | + |
| 26 | + /// Returns "<project>_<normalized_module>" (CMake target name). |
| 27 | + std::string module_target_name(const std::string &project, const std::string &module); |
| 28 | + |
| 29 | + /// Returns "<project>::<normalized_module>" (CMake alias / link name). |
| 30 | + std::string module_alias_name(const std::string &project, const std::string &module); |
| 31 | + |
| 32 | + // ------------------------------------------------------------------ |
| 33 | + // Validation |
| 34 | + // ------------------------------------------------------------------ |
| 35 | + |
| 36 | + /// Accepts [A-Za-z0-9_-], non-empty. |
| 37 | + bool is_valid_module_name(const std::string &name); |
| 38 | + |
| 39 | + /// Returns true if name conflicts with a well-known tool/library name. |
| 40 | + bool is_reserved_module_name(std::string name); |
| 41 | + |
| 42 | + // ------------------------------------------------------------------ |
| 43 | + // CMake content generators |
| 44 | + // ------------------------------------------------------------------ |
| 45 | + |
| 46 | + /// cmake/vix_modules.cmake — the central include file added by `init`. |
| 47 | + std::string cmake_vix_modules_cmake_app_first(); |
| 48 | + |
| 49 | + /// modules/<m>/CMakeLists.txt for a new module. |
| 50 | + std::string module_cmakelists_txt_app_first(const std::string &project, const std::string &module); |
| 51 | + |
| 52 | + // ------------------------------------------------------------------ |
| 53 | + // C++ content generators |
| 54 | + // ------------------------------------------------------------------ |
| 55 | + |
| 56 | + /// modules/<m>/include/<m>/api.hpp stub. |
| 57 | + std::string module_public_header_app_first(const std::string &project, const std::string &module); |
| 58 | + |
| 59 | + /// modules/<m>/src/<m>.cpp stub. |
| 60 | + std::string module_impl_cpp_app_first(const std::string &project, const std::string &module); |
| 61 | + |
| 62 | + // ------------------------------------------------------------------ |
| 63 | + // CMakeLists.txt patching |
| 64 | + // ------------------------------------------------------------------ |
| 65 | + |
| 66 | + /// Inserts the vix_modules.cmake include block after the project() call |
| 67 | + /// (idempotent via begin/end markers). |
| 68 | + bool patch_root_cmakelists_include(const std::filesystem::path &root); |
| 69 | + |
| 70 | + /// Inserts a conditional target_link_libraries block for the given module |
| 71 | + /// inside the VIX_MODULE_LINKS section (idempotent per-module). |
| 72 | + bool patch_root_cmakelists_link_module( |
| 73 | + const std::filesystem::path &root, |
| 74 | + const std::string &project, |
| 75 | + const std::string &module); |
| 76 | + |
| 77 | + // ------------------------------------------------------------------ |
| 78 | + // Static analysis helpers (used by cmd_check) |
| 79 | + // ------------------------------------------------------------------ |
| 80 | + |
| 81 | + /// Extracts all "<project>::<mod>" aliases declared in a module's |
| 82 | + /// CMakeLists.txt as explicit dependencies. |
| 83 | + std::unordered_set<std::string> parse_declared_deps_from_module_cmake( |
| 84 | + const std::filesystem::path &moduleCmake, |
| 85 | + const std::string &project); |
| 86 | + |
| 87 | + /// Returns module names referenced via "#include <other/...>" in a |
| 88 | + /// public header, filtering to modules that actually exist on disk. |
| 89 | + std::set<std::string> parse_public_includes_for_cross_module( |
| 90 | + const std::filesystem::path &publicHeader, |
| 91 | + const std::filesystem::path &modulesDir); |
| 92 | + |
| 93 | + /// Returns true if a public header includes a private src/ path. |
| 94 | + bool header_includes_private_impl( |
| 95 | + const std::filesystem::path &publicHeader, |
| 96 | + const std::filesystem::path &moduleDir); |
| 97 | + |
| 98 | +} // namespace vix::commands::modules_cmd::content |
| 99 | + |
| 100 | +#endif |
0 commit comments