!= std::end(debug_options);
}
+bool
+is_msvc_show_includes_option(std::string_view arg)
+{
+ return arg == "-showIncludes"
+ || arg == "/showIncludes"
+ // clang-cl:
+ || arg == "-showIncludes:user" || arg == "/showIncludes:user";
+}
+
// Returns std::nullopt if the option wasn't recognized, otherwise the error
// code (with Statistic::none for "no error").
std::optional<Statistic>
return Statistic::none;
}
- if (arg == "-showIncludes"
- // clang-cl:
- || arg == "-showIncludes:user") {
+ if (is_msvc_show_includes_option(arg)) {
+ args_info.generating_includes = true;
+ state.add_compiler_only_arg(args[i]);
+ return Statistic::none;
+ }
+
+ if (ctx.config.compiler_type() == CompilerType::nvcc
+ && (arg == "-Xcompiler" || arg == "--compiler-options")
+ && i < args.size() - 1 && is_msvc_show_includes_option(args[i + 1])) {
args_info.generating_includes = true;
state.add_compiler_only_arg(args[i]);
+ state.add_compiler_only_arg(args[i + 1]);
+ ++i;
return Statistic::none;
}
state.add_compiler_only_arg_no_hash(*diagnostics_color_arg);
}
- if (ctx.config.depend_mode() && !args_info.generating_includes
- && ctx.config.compiler_type() == CompilerType::msvc) {
- ctx.auto_depend_mode = true;
- args_info.generating_includes = true;
- state.add_compiler_only_arg_no_hash("/showIncludes");
+ if (ctx.config.depend_mode() && !args_info.generating_includes) {
+ if (ctx.config.compiler_type() == CompilerType::msvc) {
+ ctx.auto_depend_mode = true;
+ args_info.generating_includes = true;
+ state.add_compiler_only_arg_no_hash("/showIncludes");
+ }
+#ifdef _WIN32
+ else if (ctx.config.compiler_type() == CompilerType::nvcc) {
+ ctx.auto_depend_mode = true;
+ args_info.generating_includes = true;
+ state.add_compiler_only_arg_no_hash("-Xcompiler");
+ state.add_compiler_only_arg_no_hash("/showIncludes");
+ }
+#endif
}
if (state.found_c_opt) {
using Mode = Tokenizer::Mode;
using IncludeDelimiter = Tokenizer::IncludeDelimiter;
- if (stdout_data.empty() || !ctx.auto_depend_mode
- || ctx.config.compiler_type() != CompilerType::msvc) {
+ const bool strip_auto_includes =
+ ctx.auto_depend_mode
+ && (ctx.config.compiler_type() == CompilerType::msvc
+ || ctx.config.compiler_type() == CompilerType::nvcc);
+
+ if (stdout_data.empty() || !strip_auto_includes) {
return std::move(stdout_data);
}
== "nvcc --Werror all-warnings -Xcompiler -Werror -c");
}
+TEST_CASE("nvcc_show_includes_via_host_compiler_option")
+{
+ TestContext test_context;
+ Context ctx;
+ ctx.config.set_compiler_type(CompilerType::nvcc);
+ ctx.config.set_depend_mode(true);
+ ctx.orig_args = Args::from_string("nvcc -c foo.cu -Xcompiler /showIncludes");
+ REQUIRE(util::write_file("foo.cu", ""));
+ const auto result = process_args(ctx);
+
+ CHECK(result);
+ CHECK(ctx.args_info.generating_includes);
+ CHECK(result->preprocessor_args.to_string() == "nvcc");
+ CHECK(result->extra_args_to_hash.to_string() == "-Xcompiler /showIncludes");
+ CHECK(result->compiler_args.to_string()
+ == "nvcc -Xcompiler /showIncludes -c");
+}
+
+TEST_CASE("nvcc_auto_depend_mode")
+{
+ TestContext test_context;
+ Context ctx;
+ ctx.config.set_compiler_type(CompilerType::nvcc);
+ ctx.config.set_depend_mode(true);
+ ctx.orig_args = Args::from_string("nvcc -c foo.cu");
+ REQUIRE(util::write_file("foo.cu", ""));
+ const auto result = process_args(ctx);
+
+ CHECK(result);
+#ifdef _WIN32
+ CHECK(ctx.auto_depend_mode);
+ CHECK(ctx.args_info.generating_includes);
+ CHECK(result->preprocessor_args.to_string() == "nvcc");
+ CHECK(result->extra_args_to_hash.to_string() == "");
+ CHECK(result->compiler_args.to_string()
+ == "nvcc -Xcompiler /showIncludes -c");
+#else
+ CHECK(!ctx.auto_depend_mode);
+ CHECK(!ctx.args_info.generating_includes);
+ CHECK(result->preprocessor_args.to_string() == "nvcc");
+ CHECK(result->extra_args_to_hash.to_string() == "");
+ CHECK(result->compiler_args.to_string() == "nvcc -c");
+#endif
+}
+
TEST_CASE("-Xclang")
{
TestContext test_context;
"Third custom line\n"));
CHECK(result == util::to_span("First\nSecond\nThird custom line\n"));
}
+
+ SUBCASE("NVCC auto depend mode")
+ {
+ ctx.config.set_compiler_type(CompilerType::nvcc);
+ const util::Bytes result =
+ compiler::strip_includes_from_msvc_show_includes(ctx, util::Bytes(input));
+ CHECK(result == util::to_span("First\nSecond\n"));
+ }
+
+ SUBCASE("NVCC explicit showIncludes")
+ {
+ ctx.auto_depend_mode = false;
+ ctx.config.set_compiler_type(CompilerType::nvcc);
+ ctx.config.set_depend_mode(true);
+ ctx.args_info.generating_includes = true;
+ const util::Bytes result =
+ compiler::strip_includes_from_msvc_show_includes(ctx, util::Bytes(input));
+ CHECK(result == input);
+ }
}
TEST_SUITE_END();