Skip to content

Commit bc620e4

Browse files
committed
fix(cli): Windows compatibility and MSVC cleanup
2 parents 710c647 + eb60246 commit bc620e4

File tree

7 files changed

+65
-22
lines changed

7 files changed

+65
-22
lines changed

src/cache/ArtifactCache.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <vix/cli/util/Fs.hpp>
2626
#include <vix/cli/util/Strings.hpp>
27+
#include <vix/utils/Env.hpp>
2728

2829
namespace vix::cli::cache
2930
{
@@ -85,18 +86,18 @@ namespace vix::cli::cache
8586
static std::optional<std::string> user_home_dir()
8687
{
8788
#ifdef _WIN32
88-
const char *home = std::getenv("USERPROFILE");
89+
const char *home = vix::utils::vix_getenv("USERPROFILE");
8990
if (home && *home)
9091
return std::string(home);
9192

92-
const char *drive = std::getenv("HOMEDRIVE");
93-
const char *path = std::getenv("HOMEPATH");
93+
const char *drive = vix::utils::vix_getenv("HOMEDRIVE");
94+
const char *path = vix::utils::vix_getenv("HOMEPATH");
9495
if (drive && *drive && path && *path)
9596
return std::string(drive) + std::string(path);
9697

9798
return std::nullopt;
9899
#else
99-
const char *home = std::getenv("HOME");
100+
const char *home = vix::utils::vix_getenv("HOME");
100101
if (home && *home)
101102
return std::string(home);
102103

src/cmake/GlobalPackages.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Vix.cpp
1212
*/
1313
#include <vix/cli/cmake/GlobalPackages.hpp>
14+
#include <vix/utils/Env.hpp>
1415

1516
#include <algorithm>
1617
#include <cstdlib>
@@ -29,9 +30,9 @@ namespace vix::cli::build
2930
static std::optional<std::string> home_dir()
3031
{
3132
#ifdef _WIN32
32-
const char *home = std::getenv("USERPROFILE");
33+
const char *home = vix::utils::vix_getenv("USERPROFILE");
3334
#else
34-
const char *home = std::getenv("HOME");
35+
const char *home = vix::utils::vix_getenv("HOME");
3536
#endif
3637
if (!home || std::string(home).empty())
3738
return std::nullopt;

src/commands/OutdatedCommand.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include <vix/cli/commands/OutdatedCommand.hpp>
1515
#include <vix/cli/util/Ui.hpp>
16+
#include <vix/utils/Env.hpp>
1617
#include <nlohmann/json.hpp>
1718

1819
#include <algorithm>
@@ -71,9 +72,9 @@ namespace vix::commands
7172
fs::path home_dir()
7273
{
7374
#ifdef _WIN32
74-
const char *home = std::getenv("USERPROFILE");
75+
const char *home = vix::utils::vix_getenv("USERPROFILE");
7576
#else
76-
const char *home = std::getenv("HOME");
77+
const char *home = vix::utils::vix_getenv("HOME");
7778
#endif
7879
if (home == nullptr || std::string(home).empty())
7980
{

src/commands/PublishCommand.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,48 @@ namespace vix::commands
150150
out << j.dump(2) << "\n";
151151
}
152152

153+
static std::string join_for_log(
154+
const std::vector<std::string> &args)
155+
{
156+
std::ostringstream out;
157+
158+
for (std::size_t i = 0; i < args.size(); ++i)
159+
{
160+
if (i > 0)
161+
{
162+
out << ' ';
163+
}
164+
165+
const std::string &arg = args[i];
166+
const bool needsQuotes =
167+
arg.find(' ') != std::string::npos ||
168+
arg.find('\t') != std::string::npos ||
169+
arg.find('"') != std::string::npos;
170+
171+
if (!needsQuotes)
172+
{
173+
out << arg;
174+
continue;
175+
}
176+
177+
out << '"';
178+
for (char c : arg)
179+
{
180+
if (c == '"')
181+
{
182+
out << "\\\"";
183+
}
184+
else
185+
{
186+
out << c;
187+
}
188+
}
189+
out << '"';
190+
}
191+
192+
return out.str();
193+
}
194+
153195
struct ProcessResult
154196
{
155197
int exitCode{127};

src/commands/UpgradeCommand.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,18 +1190,15 @@ namespace vix::commands
11901190
fs::create_directories(extractDir, ec);
11911191

11921192
#ifdef _WIN32
1193-
if (os == "windows")
1194-
{
1195-
const std::string ps =
1196-
"powershell -NoProfile -ExecutionPolicy Bypass -Command "
1197-
"\"Expand-Archive -LiteralPath '" +
1198-
archive.string() + "' -DestinationPath '" + extractDir.string() + "' -Force\"";
1193+
const std::string ps =
1194+
"powershell -NoProfile -ExecutionPolicy Bypass -Command "
1195+
"\"Expand-Archive -LiteralPath '" +
1196+
archive.string() + "' -DestinationPath '" + extractDir.string() + "' -Force\"";
11991197

1200-
if (exec_status(ps + " >nul 2>&1") != 0)
1201-
throw std::runtime_error("failed to extract archive");
1198+
if (exec_status(ps + " >nul 2>&1") != 0)
1199+
throw std::runtime_error("failed to extract archive");
12021200

1203-
return;
1204-
}
1201+
return;
12051202
#endif
12061203

12071204
if (!have_cmd("tar"))

src/commands/run/RunScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ namespace vix::commands::RunCommand::detail
7676
auto home_dir = []() -> std::optional<std::string>
7777
{
7878
#ifdef _WIN32
79-
const char *home = std::getenv("USERPROFILE");
79+
const char *home = vix::utils::vix_getenv("USERPROFILE");
8080
#else
81-
const char *home = std::getenv("HOME");
81+
const char *home = vix::utils::vix_getenv("HOME");
8282
#endif
8383
if (!home || std::string(home).empty())
8484
return std::nullopt;

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
*/
1414
#include <vix/cli/commands/run/detail/ScriptCMake.hpp>
15+
#include <vix/utils/Env.hpp>
1516

1617
#include <fstream>
1718
#include <string>
@@ -75,9 +76,9 @@ namespace vix::commands::RunCommand::detail
7576
static std::optional<std::string> home_dir()
7677
{
7778
#ifdef _WIN32
78-
const char *home = std::getenv("USERPROFILE");
79+
const char *home = vix::utils::vix_getenv("USERPROFILE");
7980
#else
80-
const char *home = std::getenv("HOME");
81+
const char *home = vix::utils::vix_getenv("HOME");
8182
#endif
8283
if (!home || std::string(home).empty())
8384
return std::nullopt;

0 commit comments

Comments
 (0)