Skip to content

Commit

Permalink
Windows: fix native test wrapper's arg. escaping
Browse files Browse the repository at this point in the history
The native test wrapper now correctly escapes the
arguments for the subprocess, using
bazel::launcher::WindowsEscapeArg2 from the native
launcher.

Fixes bazelbuild#7956
Unblocks bazelbuild#6622
  • Loading branch information
laszlocsomor committed Apr 5, 2019
1 parent afeb8d0 commit ad754b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/tools/launcher/util/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility = ["//src/tools/launcher:__subpackages__"])

load("//src/tools/launcher:win_rules.bzl", "cc_library", "cc_binary", "cc_test")
load("//src/tools/launcher:win_rules.bzl", "cc_binary", "cc_library", "cc_test")

filegroup(
name = "srcs",
Expand All @@ -19,6 +19,10 @@ cc_library(
name = "util",
srcs = ["launcher_util.cc"],
hdrs = ["launcher_util.h"],
visibility = [
"//src/tools/launcher:__subpackages__",
"//tools/test:__pkg__",
],
deps = ["//src/main/cpp/util:filesystem"],
)

Expand Down
1 change: 1 addition & 0 deletions tools/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cc_library(
"//src/main/cpp/util:strings",
"//src/main/native/windows:lib-file",
"//src/main/native/windows:lib-util",
"//src/tools/launcher/util",
"//third_party/ijar:zip",
"@bazel_tools//tools/cpp/runfiles",
],
Expand Down
19 changes: 10 additions & 9 deletions tools/test/windows/tw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "src/main/cpp/util/strings.h"
#include "src/main/native/windows/file.h"
#include "src/main/native/windows/util.h"
#include "src/tools/launcher/util/launcher_util.h"
#include "third_party/ijar/common.h"
#include "third_party/ijar/platform_utils.h"
#include "third_party/ijar/zip.h"
Expand Down Expand Up @@ -1118,7 +1119,7 @@ bool AddCommandLineArg(const wchar_t* arg, const size_t arg_size,
}

bool CreateCommandLine(const Path& path,
const std::vector<const wchar_t*>& args,
const std::vector<std::wstring>& args,
std::unique_ptr<WCHAR[]>* result) {
// kMaxCmdline value: see lpCommandLine parameter of CreateProcessW.
static constexpr size_t kMaxCmdline = 32767;
Expand All @@ -1132,9 +1133,9 @@ bool CreateCommandLine(const Path& path,
return false;
}

for (const auto arg : args) {
if (!AddCommandLineArg(arg, wcslen(arg), false, result->get(), kMaxCmdline,
&total_len)) {
for (const std::wstring& arg : args) {
if (!AddCommandLineArg(arg.c_str(), arg.size(), false, result->get(),
kMaxCmdline, &total_len)) {
return false;
}
}
Expand All @@ -1145,7 +1146,7 @@ bool CreateCommandLine(const Path& path,
return true;
}

bool StartSubprocess(const Path& path, const std::vector<const wchar_t*>& args,
bool StartSubprocess(const Path& path, const std::vector<std::wstring>& args,
const Path& outerr, std::unique_ptr<Tee>* tee,
LARGE_INTEGER* start_time,
bazel::windows::AutoHandle* process) {
Expand Down Expand Up @@ -1342,7 +1343,7 @@ bool CreateUndeclaredOutputsAnnotations(const Path& undecl_annot_dir,

bool ParseArgs(int argc, wchar_t** argv, Path* out_argv0,
std::wstring* out_test_path_arg,
std::vector<const wchar_t*>* out_args) {
std::vector<std::wstring>* out_args) {
if (!out_argv0->Set(argv[0])) {
return false;
}
Expand All @@ -1358,7 +1359,7 @@ bool ParseArgs(int argc, wchar_t** argv, Path* out_argv0,
out_args->clear();
out_args->reserve(argc - 1);
for (int i = 1; i < argc; i++) {
out_args->push_back(argv[i]);
out_args->push_back(bazel::launcher::WindowsEscapeArg2(argv[i]));
}
return true;
}
Expand Down Expand Up @@ -1434,7 +1435,7 @@ bool TeeImpl::MainFunc() const {
}

int RunSubprocess(const Path& test_path,
const std::vector<const wchar_t*>& args,
const std::vector<std::wstring>& args,
const Path& test_outerr, Duration* test_duration) {
std::unique_ptr<Tee> tee;
bazel::windows::AutoHandle process;
Expand Down Expand Up @@ -1871,7 +1872,7 @@ int TestWrapperMain(int argc, wchar_t** argv) {
std::wstring test_path_arg;
Path test_path, exec_root, srcdir, tmpdir, test_outerr, xml_log;
UndeclaredOutputs undecl;
std::vector<const wchar_t*> args;
std::vector<std::wstring> args;
if (!ParseArgs(argc, argv, &argv0, &test_path_arg, &args) ||
!PrintTestLogStartMarker() ||
!FindTestBinary(argv0, test_path_arg, &test_path) ||
Expand Down

0 comments on commit ad754b4

Please sign in to comment.