Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.bfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ prog_opts = package('boost', 'program_options', version='>=1.55')
compile_opts = [opts.define('METTLE_VERSION', '"{}"'.format(mettle_version))]
if argv.safe_exit:
compile_opts.append(opts.define('METTLE_SAFE_EXIT'))
if env.target_platform.family == 'windows':
compile_opts.append(opts.define('UNICODE'))

includes = header_directory('include', include='**/*.hpp')

Expand Down
15 changes: 8 additions & 7 deletions src/libmettle/windows/subprocess_test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ namespace mettle {
!log_pipe.set_write_inherit(true))
return METTLE_FAILED();

char file[_MAX_PATH];
if(GetModuleFileNameA(nullptr, file, sizeof(file)) == sizeof(file))
TCHAR file[_MAX_PATH];
DWORD result = GetModuleFileName(nullptr, file, _countof(file));
if (result == 0 || result >= _countof(file))
return METTLE_FAILED();

std::ostringstream args;
args << file << " --test-id " << test.id << " --log-fd "
std::basic_ostringstream<TCHAR> args;
args << file << TEXT(" --test-id ") << test.id << TEXT(" --log-fd ")
<< log_pipe.write_handle.handle();

STARTUPINFOA startup_info = { sizeof(STARTUPINFOA) };
STARTUPINFO startup_info = { sizeof(STARTUPINFO) };
startup_info.dwFlags = STARTF_USESTDHANDLES;
startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startup_info.hStdOutput = stdout_pipe.write_handle;
Expand All @@ -80,8 +81,8 @@ namespace mettle {
return METTLE_FAILED();
}

if(!CreateProcessA(
file, const_cast<char*>(args.str().c_str()), nullptr, nullptr, true,
if(!CreateProcess(
nullptr, const_cast<PTCHAR>(args.str().c_str()), nullptr, nullptr, true,
CREATE_SUSPENDED, nullptr, nullptr, &startup_info, &proc_info
)) {
return METTLE_FAILED();
Expand Down
30 changes: 24 additions & 6 deletions src/mettle/windows/run_test_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,31 @@ namespace mettle::windows {
const std::string &str_;
};

std::string
template<typename T>
struct arg_converter {
static std::basic_string<T> convert(std::string_view arg) {
return arg;
}
};

template<>
struct arg_converter<wchar_t> {
static std::wstring convert(std::string_view arg) {
std::wstring result(arg.size(), L'\0');
int len = MultiByteToWideChar(CP_UTF8, 0, arg.data(), arg.size(),
result.data(), result.size());
result.resize(len);
return result;
}
};

std::basic_string<TCHAR>
make_command(const std::vector<std::string> &argv) {
std::ostringstream ss;
ss << quoted_arg(argv[0]);
for(std::size_t i = 1; i != argv.size(); i++)
ss << " " << quoted_arg(argv[i]);
return ss.str();
return arg_converter<TCHAR>::convert(ss.str());
}
}

Expand All @@ -94,13 +112,13 @@ namespace mettle::windows {
std::ostringstream ss;
ss << message_pipe.write_handle.handle();
args.insert(args.end(), { "--output-fd", ss.str() });
std::string command = make_command(args);
std::basic_string<TCHAR> command = make_command(args);

STARTUPINFOA startup_info = { sizeof(STARTUPINFOA) };
STARTUPINFO startup_info = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION proc_info;

if(!CreateProcessA(
args[0].c_str(), const_cast<char*>(command.c_str()), nullptr,
if(!CreateProcess(
nullptr, const_cast<PTCHAR>(command.c_str()), nullptr,
nullptr, true, 0, nullptr, nullptr, &startup_info, &proc_info
)) {
return METTLE_FAILED();
Expand Down