diff options
author | Matthias Maennich <maennich@google.com> | 2021-11-24 14:41:35 +0000 |
---|---|---|
committer | Matthias Maennich <maennich@google.com> | 2021-11-24 14:41:35 +0000 |
commit | de9ce22247b6130722945e1317f88704fb6ae574 (patch) | |
tree | 11898c1cdf7138bf40533f1b037f74e3a8525423 | |
parent | 6b8cd44d1c73ad55a078ce92c8e799bdd86cab52 (diff) | |
download | build-tools-de9ce22247b6130722945e1317f88704fb6ae574.tar.gz |
interceptor: consistently use curly braces for all statements
Signed-off-by: Matthias Maennich <maennich@google.com>
Change-Id: I80b2773557ec561b944d63dd826fa5a08c0bb849
-rw-r--r-- | interceptor/analysis.cc | 27 | ||||
-rw-r--r-- | interceptor/interceptor.cc | 19 | ||||
-rw-r--r-- | interceptor/main.cc | 19 |
3 files changed, 46 insertions, 19 deletions
diff --git a/interceptor/analysis.cc b/interceptor/analysis.cc index 05564c7..e230096 100644 --- a/interceptor/analysis.cc +++ b/interceptor/analysis.cc @@ -57,18 +57,22 @@ static Options parse_args(int argc, char* argv[]) { while (true) { int ix; int c = getopt_long(argc, argv, "-l:t:o:", opts, &ix); - if (c == -1) break; + if (c == -1) { + break; + } switch (c) { case 'l': result.command_log = fs::absolute(optarg); break; case 't': - if (strcmp(optarg, "text") == 0) + if (strcmp(optarg, "text") == 0) { result.output_format = OutputFormat::TEXT; - if (strcmp(optarg, "compdb") == 0) + } + if (strcmp(optarg, "compdb") == 0) { result.output_format = OutputFormat::COMPDB; - else + } else { usage(); + } break; case 'o': result.output = fs::absolute(optarg); @@ -130,7 +134,9 @@ void compdb_to_file(const interceptor::Log& log, const fs::path& output) { for (const auto& command : log.commands()) { // skip anything that is not a compiler invocation - if (!COMPILERS.count(fs::path(command.args(0)).filename().native())) continue; + if (!COMPILERS.count(fs::path(command.args(0)).filename().native())) { + continue; + } // determine if we have a uniquely identifyable output const std::string single_output = [&]() { @@ -145,21 +151,26 @@ void compdb_to_file(const interceptor::Log& log, const fs::path& output) { }(); // skip preprocessor invocations - if (std::find(command.args().cbegin(), command.args().cend(), "-E") != command.args().cend()) + if (std::find(command.args().cbegin(), command.args().cend(), "-E") != command.args().cend()) { continue; + } // now iterate over all inputs, emitting an entry for each source file for (const auto& input : command.inputs()) { // skip anything that does not look like a source file (object files, // force included headers, etc.) - if (!COMPILE_EXTENSIONS.count(fs::path(input).extension().native())) continue; + if (!COMPILE_EXTENSIONS.count(fs::path(input).extension().native())) { + continue; + } // ok, now we have a new command auto& compile_command = *compdb.add_commands(); compile_command.set_directory(fs::path(log.root_dir()) / command.current_dir()); compile_command.set_file(input); - if (!single_output.empty()) compile_command.set_output(single_output); + if (!single_output.empty()) { + compile_command.set_output(single_output); + } *compile_command.mutable_arguments() = {command.args().cbegin(), command.args().cend()}; } } diff --git a/interceptor/interceptor.cc b/interceptor/interceptor.cc index fb7f3f3..1acb7b2 100644 --- a/interceptor/interceptor.cc +++ b/interceptor/interceptor.cc @@ -95,15 +95,21 @@ static void make_relative(Command* command) { std::string root_dir; if (auto it = command->env_vars().find(ENV_root_dir); it != command->env_vars().cend()) { root_dir = it->second; - if (root_dir[root_dir.size() - 1] != '/') root_dir += '/'; + if (root_dir[root_dir.size() - 1] != '/') { + root_dir += '/'; + } } else { return; } // determine the relative path to ROOT_DIR from the current working dir std::string rel_root = fs::relative(root_dir); - if (rel_root[rel_root.size() - 1] != '/') rel_root += '/'; - if (rel_root == "./") rel_root.clear(); + if (rel_root[rel_root.size() - 1] != '/') { + rel_root += '/'; + } + if (rel_root == "./") { + rel_root.clear(); + } // TODO: This is generally bad as this means we can't make anything relative. // This happens if the out dir is outside of the root. @@ -155,8 +161,9 @@ std::ostream& operator<<(std::ostream& os, const interceptor::Command& command) std::ostringstream cmd; cmd << command.program(); - for (auto I = std::next(command.args().cbegin()), E = command.args().cend(); I != E; ++I) + for (auto I = std::next(command.args().cbegin()), E = command.args().cend(); I != E; ++I) { cmd << ' ' << escape(*I); + } os << cmd.str(); return os; @@ -242,7 +249,9 @@ static AnalysisResult analyze_compiler_linker(const std::string&, const ArgVec& static AnalysisResult analyze_archiver(const std::string&, const ArgVec& args, const EnvMap&) { AnalysisResult result; - if (args.size() < 3) return result; + if (args.size() < 3) { + return result; + } // skip args[0] as this is the program itself // skip args[1] are the archiver flags // args[2] is the output diff --git a/interceptor/main.cc b/interceptor/main.cc index 49d33d2..36cb1bd 100644 --- a/interceptor/main.cc +++ b/interceptor/main.cc @@ -47,7 +47,9 @@ static Options parse_args(int argc, char* argv[]) { auto c = getopt_long(argc, argv, "l:", long_options, &option_index); /* Detect the end of the options. */ - if (c == -1) break; + if (c == -1) { + break; + } switch (c) { case 'l': @@ -78,8 +80,9 @@ static Options parse_args(int argc, char* argv[]) { static void setup_interceptor_library_path() { auto interceptor_library = fs::read_symlink("/proc/self/exe").parent_path().parent_path() / "lib64" / "libinterceptor.so"; - while (fs::is_symlink(interceptor_library)) + while (fs::is_symlink(interceptor_library)) { interceptor_library = fs::read_symlink(interceptor_library); + } if (!fs::is_regular_file(interceptor_library)) { std::cerr << "Interceptor library could not be found!\n"; exit(EX_CONFIG); @@ -90,10 +93,11 @@ static void setup_interceptor_library_path() { static fs::path setup_root_dir() { const auto root_dir = getenv("ROOT_DIR"); fs::path result; - if (root_dir != nullptr) + if (root_dir != nullptr) { result = root_dir; - else + } else { result = fs::current_path(); + } setenv(ENV_root_dir, result.c_str(), 1); @@ -130,9 +134,12 @@ class CommandLog { interceptor::Message message; while (true) { if (!google::protobuf::util::ParseDelimitedFromZeroCopyStream(&message, &input_stream, - nullptr)) + nullptr)) { break; - if (message.has_command()) log.add_commands()->Swap(message.release_command()); + } + if (message.has_command()) { + log.add_commands()->Swap(message.release_command()); + } } } std::ofstream command_log(command_log_file_->c_str(), std::ios_base::binary); |