@@ -1615,7 +1615,7 @@ namespace vix::commands::BuildCommand
16151615 {
16161616 o.debug = true ;
16171617 }
1618- else if (a == " --debug-log" || a == " --log " )
1618+ else if (a == " --debug-log" )
16191619 {
16201620 auto v = util::take_value (args, i);
16211621 if (!v)
@@ -1625,22 +1625,27 @@ namespace vix::commands::BuildCommand
16251625 return o;
16261626 }
16271627 const std::string value (*v);
1628- const bool debugLog = a == " --debug-log" ;
1629- const bool valid = debugLog
1630- ? (value == " cache" || value == " graph" || value == " configure" || value == " process" || value == " toolchain" || value == " all" )
1631- : (value == " build" || value == " configure" || value == " all" );
1628+ const bool valid = value == " cache" || value == " graph" || value == " configure" || value == " process" || value == " toolchain" || value == " all" ;
16321629 if (!valid)
16331630 {
16341631 error (" Invalid value for " + a + " : " + value);
1635- hint (debugLog ? " Valid values: cache, graph, configure, process, toolchain, all"
1636- : " Valid values: build, configure, all" );
1632+ hint (" Valid values: cache, graph, configure, process, toolchain, all" );
16371633 exitCode = 2 ;
16381634 return o;
16391635 }
1640- if (debugLog)
1641- o.debugLogScope = value;
1642- else
1643- o.logScope = value;
1636+ o.debugLogScope = value;
1637+ }
1638+ else if (a == " --log" )
1639+ {
1640+ o.showLog = true ;
1641+ if (i + 1 < args.size () && !args[i + 1 ].empty () && args[i + 1 ][0 ] != ' -' )
1642+ {
1643+ const std::string value = args[++i];
1644+ if (value == " build" || value == " configure" || value == " all" )
1645+ o.logScope = value;
1646+ else
1647+ o.logPath = value;
1648+ }
16441649 }
16451650 else if (a == " --heartbeat" )
16461651 {
@@ -5195,7 +5200,7 @@ namespace vix::commands::BuildCommand
51955200 return 1 ;
51965201 }
51975202
5198- if (!opt_.warnings && opt_.logScope . empty () &&
5203+ if (!opt_.warnings && ! opt_.showLog &&
51995204 can_use_native_vix_app_build (opt_, loadResult.manifest ))
52005205 {
52015206 return run_native_vix_app_build (
@@ -5239,7 +5244,7 @@ namespace vix::commands::BuildCommand
52395244 plan_);
52405245 }
52415246
5242- if (! opt_.logScope . empty () )
5247+ if (opt_.showLog )
52435248 {
52445249 const auto print_log = [](const fs::path &path, const std::string &label) -> bool
52455250 {
@@ -5254,9 +5259,44 @@ namespace vix::commands::BuildCommand
52545259 };
52555260
52565261 bool found = false ;
5257- if (opt_.logScope == " configure" || opt_.logScope == " all" )
5262+ if (!opt_.logPath .empty ())
5263+ {
5264+ const fs::path requested = opt_.logPath ;
5265+ std::error_code ec;
5266+ if (!fs::exists (requested, ec) || ec)
5267+ {
5268+ error (" Build log path not found: " + requested.string ());
5269+ return 1 ;
5270+ }
5271+ if (fs::is_regular_file (requested, ec))
5272+ found = print_log (requested, " Build" );
5273+ else if (fs::is_directory (requested, ec))
5274+ {
5275+ fs::path newest;
5276+ fs::file_time_type newestTime{};
5277+ for (const auto &entry : fs::directory_iterator (requested, ec))
5278+ {
5279+ if (ec || !entry.is_regular_file (ec) || entry.path ().extension () != " .log" )
5280+ continue ;
5281+ const auto time = entry.last_write_time (ec);
5282+ if (!ec && (newest.empty () || time > newestTime))
5283+ {
5284+ newest = entry.path ();
5285+ newestTime = time;
5286+ }
5287+ }
5288+ if (!newest.empty ())
5289+ found = print_log (newest, " Build" );
5290+ if (!found)
5291+ {
5292+ error (" No build logs found in " + requested.string ());
5293+ return 1 ;
5294+ }
5295+ }
5296+ }
5297+ else if (opt_.logScope == " configure" || opt_.logScope == " all" )
52585298 found = print_log (plan_.configureLog , " Configure" ) || found;
5259- if (opt_.logScope == " build" || opt_.logScope == " all" )
5299+ if (opt_.logScope . empty () || opt_. logScope == " build" || opt_.logScope == " all" )
52605300 found = print_log (plan_.buildLog , " Build" ) || found;
52615301 if (!found)
52625302 {
@@ -6245,27 +6285,43 @@ namespace vix::commands::BuildCommand
62456285
62466286 if (opt.listTargets )
62476287 {
6248- const std::vector<std::string> known = {
6249- " aarch64-linux-gnu" ,
6250- " arm-linux-gnueabihf" ,
6251- " riscv64-linux-gnu" ,
6252- " x86_64-windows-gnu" ,
6253- " aarch64-windows-gnu" };
6288+ std::map<std::string, std::string> detected;
6289+ if (const char *pathEnv = std::getenv (" PATH" ); pathEnv && *pathEnv)
6290+ {
6291+ #ifdef _WIN32
6292+ const char separator = ' ;' ;
6293+ #else
6294+ const char separator = ' :' ;
6295+ #endif
6296+ std::istringstream paths (pathEnv);
6297+ std::string directory;
6298+ while (std::getline (paths, directory, separator))
6299+ {
6300+ std::error_code ec;
6301+ for (const auto &entry : fs::directory_iterator (directory, ec))
6302+ {
6303+ if (ec || !entry.is_regular_file (ec))
6304+ continue ;
6305+ const std::string name = entry.path ().filename ().string ();
6306+ const std::string suffix = " -g++" ;
6307+ if (name.size () > suffix.size () && name.rfind (suffix) == name.size () - suffix.size ())
6308+ detected.emplace (name.substr (0 , name.size () - suffix.size ()), name);
6309+ }
6310+ }
6311+ }
62546312
62556313 info (" Available targets" );
62566314 step (" native" );
62576315 if (opt.verbose )
62586316 step (" status: native" );
62596317
6260- for (const std::string & target : known )
6318+ for (const auto &[ target, compiler] : detected )
62616319 {
6262- const std::string compiler = target + " -g++" ;
6263- const bool available = util::executable_on_path (compiler);
6264- step (target + (available ? " available" : " unavailable" ));
6320+ step (target + " available" );
62656321 if (opt.verbose )
62666322 {
6267- step (" status: " + std::string ( available ? " available " : " unavailable " ) );
6268- step (" compiler: " + compiler + (available ? " " : " (not found) " ) );
6323+ step (" status: available" );
6324+ step (" compiler: " + compiler);
62696325 }
62706326 }
62716327 step (" Use: vix build --target <target>" );
@@ -7465,7 +7521,7 @@ namespace vix::commands::BuildCommand
74657521 out << " -v, --verbose Show additional useful build information\n " ;
74667522 out << " --debug Show internal Vix build diagnostics\n " ;
74677523 out << " --debug-log <scope> Debug cache, graph, configure, process, toolchain, or all\n " ;
7468- out << " --log <scope> Show captured log: build, configure, or all \n " ;
7524+ out << " --log [path] Show the current build log or a log file/directory \n " ;
74697525 out << " --cmake-verbose Stream raw CMake, Ninja and compiler output\n " ;
74707526 out << " -q, --quiet Minimal output\n " ;
74717527 out << " -h, --help Show this help\n\n " ;
@@ -7522,7 +7578,9 @@ namespace vix::commands::BuildCommand
75227578 out << " vix build main.cpp --target x86_64-windows-gnu --out app.exe\n " ;
75237579 out << " vix build --linker lld -- -DVIX_SYNC_BUILD_TESTS=ON\n " ;
75247580 out << " vix build --debug\n " ;
7525- out << " vix build --log build\n " ;
7581+ out << " vix build --log\n " ;
7582+ out << " vix build --log ./build/\n " ;
7583+ out << " vix build --log build-ninja/build.log\n " ;
75267584 out << " vix build --target aarch64-linux-gnu --sysroot /opt/sysroots/aarch64\n\n " ;
75277585
75287586 return 0 ;
0 commit comments