Escape solibs in case the output name contains a space character.
Bug: chromium:1197495
Change-Id: I464c1a507294ced04c6274149d33b3b9615801e4
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/11500
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Dirk Pranke <dpranke@google.com>
diff --git a/src/gn/ninja_c_binary_target_writer.cc b/src/gn/ninja_c_binary_target_writer.cc
index ddff182..b52475f 100644
--- a/src/gn/ninja_c_binary_target_writer.cc
+++ b/src/gn/ninja_c_binary_target_writer.cc
@@ -861,7 +861,10 @@
return;
out_ << " " << label << " =";
- path_output_.WriteFiles(out_, libs);
+ PathOutput output(path_output_.current_dir(),
+ settings_->build_settings()->root_path_utf8(),
+ ESCAPE_NINJA_COMMAND);
+ output.WriteFiles(out_, libs);
out_ << std::endl;
}
diff --git a/src/gn/ninja_c_binary_target_writer_unittest.cc b/src/gn/ninja_c_binary_target_writer_unittest.cc
index 35d9841..ef40173 100644
--- a/src/gn/ninja_c_binary_target_writer_unittest.cc
+++ b/src/gn/ninja_c_binary_target_writer_unittest.cc
@@ -1920,3 +1920,59 @@
EXPECT_EQ(expected, out_str) << expected << "\n" << out_str;
}
}
+
+TEST_F(NinjaCBinaryTargetWriterTest, SolibsEscaping) {
+ Err err;
+ TestWithScope setup;
+
+ Toolchain toolchain_with_toc(
+ setup.settings(), Label(SourceDir("//toolchain_with_toc/"), "with_toc"));
+ TestWithScope::SetupToolchain(&toolchain_with_toc, true);
+
+ // Create a shared library with a space in the output name.
+ Target shared_lib(setup.settings(),
+ Label(SourceDir("//rocket"), "space_cadet"));
+ shared_lib.set_output_type(Target::SHARED_LIBRARY);
+ shared_lib.set_output_name("Space Cadet");
+ shared_lib.set_output_prefix_override("");
+ shared_lib.SetToolchain(&toolchain_with_toc);
+ shared_lib.visibility().SetPublic();
+ ASSERT_TRUE(shared_lib.OnResolved(&err));
+
+ // Set up an executable to depend on it.
+ Target target(setup.settings(), Label(SourceDir("//launchpad"), "main"));
+ target.sources().push_back(SourceFile("//launchpad/main.cc"));
+ target.set_output_type(Target::EXECUTABLE);
+ target.private_deps().push_back(LabelTargetPair(&shared_lib));
+ target.SetToolchain(&toolchain_with_toc);
+ ASSERT_TRUE(target.OnResolved(&err));
+
+ std::ostringstream out;
+ NinjaCBinaryTargetWriter writer(&target, out);
+ writer.Run();
+
+ const char expected[] = R"(defines =
+include_dirs =
+root_out_dir = .
+target_out_dir = obj/launchpad
+target_output_name = main
+
+build obj/launchpad/main.main.o: cxx ../../launchpad/main.cc
+
+build ./main: link obj/launchpad/main.main.o | ./Space$ Cadet.so.TOC
+ ldflags =
+ libs =
+ frameworks =
+ swiftmodules =
+ output_extension =
+ output_dir =
+)"
+#if defined(OS_WIN)
+ " solibs = \"./Space$ Cadet.so\"\n";
+#else
+ " solibs = ./Space\\$ Cadet.so\n";
+#endif
+
+ std::string out_str = out.str();
+ EXPECT_EQ(expected, out_str) << expected << "\n" << out_str;
+}