Skip to content

Commit 660ed9c

Browse files
committed
run: suppress duplicate runtime output and improve script feature detection
1 parent c805103 commit 660ed9c

4 files changed

Lines changed: 84 additions & 4 deletions

File tree

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ namespace vix::commands::RunCommand::detail
101101
int exitCode = 0; // normalized 0..255 or 128+signal
102102
std::string stdoutText;
103103
std::string stderrText;
104-
105104
bool failureHandled = false;
105+
bool printed_live = false;
106106
};
107107

108108
LiveRunResult run_cmd_live_filtered_capture(

src/commands/run/RunProcess.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ namespace vix::commands::RunCommand::detail
10501050
{
10511051
write_all(STDOUT_FILENO, toPrint.data(), toPrint.size());
10521052
printedSomething = true;
1053-
printedRealOutput = true; //
1053+
printedRealOutput = true;
1054+
result.printed_live = true;
10541055
lastPrintedChar = toPrint.back();
10551056
}
10561057
}

src/commands/run/RunScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ namespace vix::commands::RunCommand::detail
439439

440440
if (!handled)
441441
{
442-
std::cerr << runtimeLog << "\n";
442+
if (!rr.printed_live)
443+
std::cerr << runtimeLog << "\n";
443444
}
444445
}
445446

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
*
3+
* @file ScriptCMake.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, 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+
*/
114
#include <vix/cli/commands/run/detail/ScriptCMake.hpp>
215

316
#include <fstream>
@@ -6,6 +19,50 @@
619

720
namespace vix::commands::RunCommand::detail
821
{
22+
struct ScriptFeatures
23+
{
24+
bool usesVix = false;
25+
bool usesOrm = false;
26+
bool usesDb = false;
27+
bool usesMysql = false;
28+
};
29+
30+
static ScriptFeatures detect_script_features(const fs::path &cppPath)
31+
{
32+
ScriptFeatures f;
33+
34+
std::ifstream ifs(cppPath);
35+
if (!ifs)
36+
return f;
37+
38+
std::string line;
39+
while (std::getline(ifs, line))
40+
{
41+
auto has = [&](const char *s)
42+
{ return line.find(s) != std::string::npos; };
43+
44+
if (has("vix::") || has("Vix::") || has("#include <vix/") || has("#include \"vix/"))
45+
f.usesVix = true;
46+
47+
if (has("#include <vix/orm/") || has("vix::orm") || has("using namespace vix::orm"))
48+
f.usesOrm = true;
49+
50+
if (has("#include <vix/db/") || has("vix::db") || has("using namespace vix::db"))
51+
f.usesDb = true;
52+
53+
if (has("make_mysql_factory") || has("Engine::MySQL") || has("mysqlcppconn"))
54+
f.usesMysql = true;
55+
56+
if (!f.usesMysql && (has("tcp://") || has("3306") || has("MySQL")))
57+
f.usesMysql = true;
58+
}
59+
60+
if (f.usesOrm)
61+
f.usesDb = true;
62+
63+
return f;
64+
}
65+
966
ScriptLinkFlags parse_link_flags(const std::vector<std::string> &flags)
1067
{
1168
ScriptLinkFlags out;
@@ -101,18 +158,25 @@ namespace vix::commands::RunCommand::detail
101158
s += " set(CMAKE_BUILD_TYPE Debug CACHE STRING \"Build type\" FORCE)\n";
102159
s += "endif()\n\n";
103160

161+
auto feat = detect_script_features(cppPath);
162+
104163
// Options
105164
s += "option(VIX_ENABLE_SANITIZERS \"Enable sanitizers (dev only)\" OFF)\n";
106165
s += "set(VIX_SANITIZER_MODE \"asan_ubsan\" CACHE STRING \"Sanitizer mode: asan_ubsan or ubsan\")\n";
107166
s += "set_property(CACHE VIX_SANITIZER_MODE PROPERTY STRINGS asan_ubsan ubsan)\n";
108167
s += "option(VIX_ENABLE_LIBCXX_ASSERTS \"Enable libstdc++ debug mode (_GLIBCXX_ASSERTIONS/_GLIBCXX_DEBUG)\" OFF)\n";
109168
s += "option(VIX_ENABLE_HARDENING \"Enable extra hardening flags (non-MSVC)\" OFF)\n";
110-
s += "option(VIX_USE_ORM \"Enable Vix ORM (requires vix::orm in install)\" ON)\n\n";
169+
s += std::string("option(VIX_USE_ORM \"Enable Vix ORM (requires vix::orm)\" ") + (feat.usesOrm ? "ON" : "OFF") + ")\n";
111170

112171
// Executable
113172
s += "add_executable(" + exeName + " " + q(cppPath.string()) + ")\n\n";
114173
auto lf = parse_link_flags(scriptFlags);
115174

175+
auto hasLib = [&](const std::string &name) -> bool
176+
{
177+
return std::find(lf.libs.begin(), lf.libs.end(), name) != lf.libs.end();
178+
};
179+
116180
if (!lf.libDirs.empty())
117181
{
118182
s += "target_link_directories(" + exeName + " PRIVATE\n";
@@ -219,6 +283,20 @@ namespace vix::commands::RunCommand::detail
219283
s += " message(FATAL_ERROR \"VIX_USE_ORM=ON but DB target is not available (vix::db/Vix::db)\")\n";
220284
s += " endif()\n";
221285
s += "endif()\n\n";
286+
287+
// Auto-link MySQL connector only when needed and not already provided
288+
if (feat.usesMysql && !hasLib("mysqlcppconn8") && !hasLib("mysqlcppconn"))
289+
{
290+
s += "# Auto-link MySQL connector when script uses MySQL\n";
291+
s += "if (UNIX)\n";
292+
s += " find_library(VIX_MYSQLCPPCONN_LIB NAMES mysqlcppconn8 mysqlcppconn)\n";
293+
s += " if (VIX_MYSQLCPPCONN_LIB)\n";
294+
s += " target_link_libraries(" + exeName + " PRIVATE ${VIX_MYSQLCPPCONN_LIB})\n";
295+
s += " else()\n";
296+
s += " message(WARNING \"MySQL connector lib not found (mysqlcppconn8/mysqlcppconn). If you get undefined references, pass: -- -lmysqlcppconn8\")\n";
297+
s += " endif()\n";
298+
s += "endif()\n\n";
299+
}
222300
}
223301

224302
// Sanitizers (mode-aware)

0 commit comments

Comments
 (0)