Change tint emission for multiple entry points. Currently, if you provide an output file like `-o foo.hlsl` and the given `wgsl` we change the name of the output file to inject the entry point name (so you may get `foo.main.hlsl` output instead). This behaviour is confusing, instead, if `-o` is provided but `--ep` is not and there are multiple entry points, we emit an error and require an entry point to be provided. This does not effect emitting to stdout, you'll still get all of the entry points emitted. It also does not require `--ep` if there is only a single entry point in the WGSL file. Bug: 473791193 Change-Id: I849b722e83bd35b44a4cc56f53e59a68ed2fa213 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/283659 Commit-Queue: James Price <jrprice@google.com> Auto-Submit: dan sinclair <dsinclair@chromium.org> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/cmd/tint/main.cc b/src/tint/cmd/tint/main.cc index a30fc1b..a9b18ee4 100644 --- a/src/tint/cmd/tint/main.cc +++ b/src/tint/cmd/tint/main.cc
@@ -1497,22 +1497,32 @@ return GenerateWgsl(options, inspector, info.program) ? 0 : 1; } - if (inspector.GetEntryPoints().empty()) { + auto entry_points = inspector.GetEntryPoints(); + if (entry_points.empty()) { std::cerr << "no entry point found, entry point required\n"; return 1; } + if (!tint::cmd::IsStdout(options.output_file) && !options.emit_single_entry_point) { + if (entry_points.size() > 1) { + std::cerr + << "Emitting to a file but the module has multiple entry points. Please provide " + "the `--ep <name>` option to specific the entry point to emit\n"; + return 1; + } + + // Set the emitted entry point to the name from the inspector + options.ep_name = entry_points.front().name; + options.emit_single_entry_point = true; + } + bool success = true; - std::string outfile_name = options.output_file; - auto entry_points = inspector.GetEntryPoints(); for (auto& entry_point : entry_points) { if (options.emit_single_entry_point && entry_point.name != options.ep_name) { continue; } - // If we're emitting to stdout, add a separator between the entry points. If we're going - // to a file, and we aren't emitting a single entry point, add the entry point name into - // the output file name. + // If we're emitting to stdout, add a separator between the entry points. if (tint::cmd::IsStdout(options.output_file)) { if (entry_points.size() > 1) { if (options.format == Format::kSpvAsm) { @@ -1527,14 +1537,6 @@ std::cout << "//\n"; } } - } else if (!options.emit_single_entry_point) { - auto pos = outfile_name.rfind("."); - if (pos == std::string_view::npos) { - options.output_file = outfile_name + "." + entry_point.name; - } else { - options.output_file = outfile_name.substr(0, pos) + "." + entry_point.name + "." + - outfile_name.substr(pos + 1); - } } options.ep_name = entry_point.name;