Skip to content

Commit d319ae2

Browse files
authored
feat: report bad extractions as an error (#119)
* use absolute paths for vs extract batch * in unreal the temp directory passed to the CLI on windows uses '/' which caused the batch file to not be found
1 parent 8e2b101 commit d319ae2

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

ecsact/cli/commands/build/cc_compiler.cc

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "ecsact/cli/commands/build/cc_compiler.hh"
22

33
#include <filesystem>
4-
#include <cstddef>
4+
#include <string>
5+
#include <string_view>
56
#include <fstream>
67
#include <boost/process.hpp>
78
#include "nlohmann/json.hpp"
8-
#include "magic_enum.hpp"
99
#include "ecsact/cli/commands/build/cc_compiler.hh"
1010
#include "ecsact/cli/commands/build/cc_compiler_util.hh"
1111
#include "ecsact/cli/report.hh"
@@ -115,13 +115,16 @@ static auto vsdevcmd_env_var(
115115
const fs::path& vsdevcmd_path,
116116
const std::string& env_var_name
117117
) -> std::vector<std::string> {
118+
auto proc_env = boost::this_process::environment();
118119
auto result = std::vector<std::string>{};
119-
auto is = bp::ipstream{};
120+
auto std_is = bp::ipstream{};
121+
auto err_is = bp::ipstream{};
120122
auto extract_script_proc = bp::child{
121-
vsdevcmd_path.string(),
123+
fs::absolute(vsdevcmd_path).string(),
122124
bp::args({env_var_name}),
123-
bp::std_out > is,
124-
bp::std_err > bp::null,
125+
bp::std_out > std_is,
126+
bp::std_err > err_is,
127+
bp::std_in < bp::null,
125128
};
126129

127130
auto subcommand_id =
@@ -132,21 +135,29 @@ static auto vsdevcmd_env_var(
132135
.arguments = {env_var_name},
133136
});
134137

135-
for(;;) {
136-
std::string var;
137-
std::getline(is, var, ';');
138-
boost::trim_right(var);
139-
if(var.empty()) {
140-
break;
138+
auto line = std::string{};
139+
while(std::getline(std_is, line, ';')) {
140+
boost::trim_right(line);
141+
if(!line.empty()) {
142+
result.emplace_back(line);
141143
}
142-
result.emplace_back(std::move(var));
143144
}
144145

145-
extract_script_proc.detach();
146+
while(std::getline(err_is, line)) {
147+
boost::trim(line);
148+
if(!line.empty()) {
149+
ecsact::cli::report(ecsact::cli::subcommand_stderr_message{
150+
.id = subcommand_id,
151+
.line = line
152+
});
153+
}
154+
}
155+
156+
extract_script_proc.wait();
146157

147158
ecsact::cli::report(subcommand_end_message{
148159
.id = subcommand_id,
149-
.exit_code = 0, // We detached, so we don't have an exit code
160+
.exit_code = extract_script_proc.exit_code(),
150161
});
151162

152163
return result;
@@ -288,7 +299,16 @@ static auto cc_vswhere( //
288299
};
289300

290301
auto standard_include_paths = vsdevcmd_env_varl("INCLUDE");
302+
if(standard_include_paths.empty()) {
303+
ecsact::cli::report_error("Extracted INCLUDE paths is empty");
304+
return {};
305+
}
306+
291307
auto standard_lib_paths = vsdevcmd_env_varl("LIB");
308+
if(standard_lib_paths.empty()) {
309+
ecsact::cli::report_error("Extracted LIB paths is empty");
310+
return {};
311+
}
292312

293313
// https://github.com/microsoft/vswhere/wiki/Find-VC
294314
auto version_text_path = std::format(

0 commit comments

Comments
 (0)