Skip to content

Commit

Permalink
Prefer arguments over command
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Dec 22, 2024
1 parent 919f547 commit f0c4204
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions bcc/compile_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ join_arguments(boost::json::array const& args)
} // namespace

compile_commands_builder&
compile_commands_builder::arguments(bool value)
compile_commands_builder::command(bool value)
{
arguments_ = value;
command_ = value;
return *this;
}

Expand Down Expand Up @@ -146,10 +146,10 @@ compile_commands_builder::build(analysis::ActionGraphContainer const& action_gra
}
auto obj = boost::json::object();
obj.insert(boost::json::object::value_type{ "directory", execution_root_.string() });
if (arguments_) {
obj.insert(boost::json::object::value_type{ "arguments", args });
} else {
if (command_) {
obj.insert(boost::json::object::value_type{ "command", join_arguments(args) });
} else {
obj.insert(boost::json::object::value_type{ "arguments", args });
}
obj.insert(boost::json::object::value_type{ "file", file.value() });
obj.insert(boost::json::object::value_type{ "output", output });
Expand Down
4 changes: 2 additions & 2 deletions bcc/compile_commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class compile_commands_builder
{
public:
/// Include `arguments` in final compile_commands.json file.
compile_commands_builder& arguments(bool value);
compile_commands_builder& command(bool value);
/// Resolve symlinks of file entries in the compile_commands.json file.
compile_commands_builder& resolve(bool value);
/// Set compiler.
Expand All @@ -31,7 +31,7 @@ class compile_commands_builder
boost::json::array build(analysis::ActionGraphContainer const& action_graph) const;

private:
bool arguments_{ false };
bool command_{ false };
bool resolve_{ false };
std::optional<std::string> compiler_{};
bcc::replacements replacements_{};
Expand Down
2 changes: 1 addition & 1 deletion bcc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ main(int argc, char** argv)
replacements.add_all(options.replace);

auto builder = bcc::compile_commands_builder();
builder.arguments(options.arguments)
builder.command(options.command)
.resolve(options.resolve)
.replacements(replacements)
.workspace_path(bazel.workspace_path())
Expand Down
5 changes: 3 additions & 2 deletions bcc/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ options::from_argv(int argc, char* argv[])
("help,h", "produce help message")
("version,V", "print version")
("verbose,v", po::bool_switch(&result.verbose), "verbose, report more information")
("arguments,a", po::bool_switch(&result.arguments), "include `arguments` array in output")
("arguments,a", "provide `arguments` array in output (enabled by default)")
("command", po::bool_switch(&result.command), "provide `command` string in output")
("resolve", po::bool_switch(&result.resolve), "resolve file symlinks when their target is inside the workspace")
("bazel-command,B", po::value(&result.bazel_command)->value_name("PATH"), "bazel command")
("bazelsupopt,s", po::value(&result.bazel_startup_options)->value_name("OPTION"), "bazel startup options")
Expand Down Expand Up @@ -143,7 +144,7 @@ std::ostream&
options::write(std::ostream& os) const
{
os << "verbose = " << this->verbose << "\n";
os << "arguments = " << this->arguments << "\n";
os << "command = " << this->command << "\n";
os << "resolve = " << this->resolve << "\n";
os << "bazel-command = " << this->bazel_command << "\n";
for (auto const& opt : bazel_startup_options) {
Expand Down
4 changes: 2 additions & 2 deletions bcc/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct options

/// Be verbose.
bool verbose{ false };
/// Include `arguments` array in the final `compile_commands.json`
bool arguments{ false };
/// Include `command` string in the final `compile_commands.json`
bool command{ false };
/// Resolve symlinks of `file` entries in the `compile_commands.json`
bool resolve{ false };
/// Bazel command.
Expand Down
4 changes: 2 additions & 2 deletions tests/self_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TEST(self_test, run)
ASSERT_THAT(bazel_path, Not(IsEmpty())) << bazel_path;
ASSERT_THAT(std::filesystem::exists(bazel_path), IsTrue()) << bazel_path;

auto const result = run(bcc_path, { "-B", bazel_path.c_str(), "-a", "-o-" });
auto const result = run(bcc_path, { "-B", bazel_path.c_str(), "-o-" });

ASSERT_THAT(result.is_array(), IsTrue());

Expand All @@ -88,7 +88,7 @@ TEST(self_test, run)

ASSERT_THAT(cu_obj.find("file"), Not(Eq(end)));
EXPECT_THAT(cu_obj.find("directory"), Not(Eq(end)));
EXPECT_THAT(cu_obj.find("command"), Not(Eq(end)));
EXPECT_THAT(cu_obj.find("arguments"), Not(Eq(end)));
EXPECT_THAT(cu_obj.find("output"), Not(Eq(end)));

auto const file = cu_obj.at("file").as_string();
Expand Down

0 comments on commit f0c4204

Please sign in to comment.