|
| 1 | +/** |
| 2 | + * |
| 3 | + * @file DevSession.hpp |
| 4 | + * @author Gaspard Kirira |
| 5 | + * |
| 6 | + * Copyright 2026, Gaspard Kirira. All rights reserved. |
| 7 | + * https://github.com/vixcpp/vix |
| 8 | + * Use of this source code is governed by a MIT license |
| 9 | + * that can be found in the License file. |
| 10 | + * |
| 11 | + * Vix.cpp |
| 12 | + * |
| 13 | + * Dev mode session orchestrator |
| 14 | + * |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef VIX_CLI_COMMANDS_RUN_DEV_DEV_SESSION_HPP |
| 18 | +#define VIX_CLI_COMMANDS_RUN_DEV_DEV_SESSION_HPP |
| 19 | + |
| 20 | +#include <chrono> |
| 21 | +#include <filesystem> |
| 22 | +#include <map> |
| 23 | +#include <string> |
| 24 | +#include <vector> |
| 25 | +#include <optional> |
| 26 | + |
| 27 | +#include <vix/cli/commands/run/RunDetail.hpp> |
| 28 | +#include <vix/cli/commands/run/dev/DevChangeClassifier.hpp> |
| 29 | +#include <vix/cli/commands/run/dev/DevRebuilder.hpp> |
| 30 | + |
| 31 | +namespace vix::commands::RunCommand::dev |
| 32 | +{ |
| 33 | + namespace fs = std::filesystem; |
| 34 | + namespace detail = vix::commands::RunCommand::detail; |
| 35 | + |
| 36 | + struct DevSessionOptions |
| 37 | + { |
| 38 | + fs::path projectDir; |
| 39 | + fs::path buildDir; |
| 40 | + std::string targetName; |
| 41 | + |
| 42 | + detail::Options runOptions; |
| 43 | + |
| 44 | + std::chrono::milliseconds pollInterval{300}; |
| 45 | + std::chrono::milliseconds debounceDelay{200}; |
| 46 | + |
| 47 | + bool quiet{false}; |
| 48 | + }; |
| 49 | + |
| 50 | + struct DevSessionResult |
| 51 | + { |
| 52 | + int exitCode{0}; |
| 53 | + std::string message; |
| 54 | + }; |
| 55 | + |
| 56 | + struct DevFileSnapshot |
| 57 | + { |
| 58 | + std::map<std::string, fs::file_time_type> files; |
| 59 | + |
| 60 | + bool empty() const; |
| 61 | + }; |
| 62 | + |
| 63 | + struct DevDetectedChange |
| 64 | + { |
| 65 | + fs::path path; |
| 66 | + DevChangeKind kind{DevChangeKind::Ignore}; |
| 67 | + |
| 68 | + bool valid() const; |
| 69 | + }; |
| 70 | + |
| 71 | + class DevSession |
| 72 | + { |
| 73 | + public: |
| 74 | + explicit DevSession(DevSessionOptions options); |
| 75 | + |
| 76 | + const DevSessionOptions &options() const; |
| 77 | + |
| 78 | + DevSessionResult run(); |
| 79 | + |
| 80 | + private: |
| 81 | + DevSessionOptions options_; |
| 82 | + DevChangeClassifier classifier_; |
| 83 | + DevRebuilder rebuilder_; |
| 84 | + |
| 85 | + DevFileSnapshot snapshot_project() const; |
| 86 | + |
| 87 | + std::vector<DevDetectedChange> detect_changes( |
| 88 | + const DevFileSnapshot &before, |
| 89 | + const DevFileSnapshot &after) const; |
| 90 | + |
| 91 | + DevChangeKind strongest_change_kind( |
| 92 | + const std::vector<DevDetectedChange> &changes) const; |
| 93 | + |
| 94 | + DevDetectedChange first_relevant_change( |
| 95 | + const std::vector<DevDetectedChange> &changes) const; |
| 96 | + |
| 97 | + DevDetectedChange wait_for_change( |
| 98 | + DevFileSnapshot &snapshot) const; |
| 99 | + |
| 100 | + int rebuild_for_change(DevChangeKind kind) const; |
| 101 | + |
| 102 | + std::optional<fs::path> executable_path() const; |
| 103 | + |
| 104 | +#ifndef _WIN32 |
| 105 | + int run_child_once(const fs::path &exePath); |
| 106 | + void stop_child(int pid) const; |
| 107 | +#endif |
| 108 | + |
| 109 | + bool should_skip_directory(const fs::path &path) const; |
| 110 | + }; |
| 111 | + |
| 112 | +} // namespace vix::commands::RunCommand::dev |
| 113 | + |
| 114 | +#endif // VIX_CLI_COMMANDS_RUN_DEV_DEV_SESSION_HPP |
0 commit comments