@@ -38,7 +38,6 @@ namespace {
3838 constexpr std::optional<std::string_view> ADVANCED_GROUP = { " advanced options" };
3939 constexpr std::optional<std::string_view> DEVELOPER_GROUP = { " developer options" };
4040
41- constexpr char VERBOSE[] = " --verbose" ;
4241 constexpr char APPEND[] = " --append" ;
4342 constexpr char OUTPUT[] = " --output" ;
4443 constexpr char CITNAMES[] = " --citnames" ;
@@ -96,7 +95,7 @@ namespace {
9695 auto library = arguments.as_string (LIBRARY);
9796 auto executor = arguments.as_string (EXECUTOR);
9897 auto wrapper = arguments.as_string (WRAPPER);
99- auto verbose = arguments.as_bool (VERBOSE).unwrap_or (false );
98+ auto verbose = arguments.as_bool (flags:: VERBOSE).unwrap_or (false );
10099 auto force_wrapper = arguments.as_bool (FORCE_WRAPPER).unwrap_or (false );
101100 auto force_preload = arguments.as_bool (FORCE_PRELOAD).unwrap_or (false );
102101
@@ -136,7 +135,7 @@ namespace {
136135 auto program = arguments.as_string (CITNAMES);
137136 auto output = arguments.as_string (OUTPUT);
138137 auto append = arguments.as_bool (APPEND).unwrap_or (false );
139- auto verbose = arguments.as_bool (VERBOSE).unwrap_or (false );
138+ auto verbose = arguments.as_bool (flags:: VERBOSE).unwrap_or (false );
140139 auto include = arguments.as_string_list (INCLUDE).unwrap_or ({});
141140 auto exclude = arguments.as_string_list (EXCLUDE).unwrap_or ({});
142141
@@ -170,14 +169,6 @@ namespace {
170169 });
171170 }
172171
173- void remove_commands_file (const fs::path &commands) {
174- std::error_code error_code;
175- auto removed = fs::remove (commands, error_code);
176- if (!removed) {
177- spdlog::debug (" remove command file failed: {}" , commands.c_str ());
178- }
179- }
180-
181172 rust::Result<int > run (const flags::Arguments& arguments, const sys::env::Vars& environment)
182173 {
183174 auto commands = arguments.as_string (OUTPUT)
@@ -193,8 +184,12 @@ namespace {
193184 .and_then <int >([&commands](auto tuple) {
194185 const auto & [intercept, citnames] = tuple;
195186 auto result = execute (intercept, " intercept" );
196- execute (citnames, " citnames" );
197- remove_commands_file (commands);
187+
188+ std::error_code error_code;
189+ if (fs::exists (commands, error_code)) {
190+ execute (citnames, " citnames" );
191+ fs::remove (commands, error_code);
192+ }
198193 return result;
199194 });
200195 }
@@ -206,8 +201,7 @@ int main(int argc, char* argv[], char* envp[])
206201 spdlog::set_pattern (" bear: %v [pid: %P]" );
207202 spdlog::set_level (spdlog::level::info);
208203
209- const flags::Parser parser (" bear" , VERSION,
210- { { VERBOSE, { 0 , false ," run the interception verbose" , std::nullopt , std::nullopt } },
204+ const flags::Parser parser (" bear" , VERSION,{
211205 { OUTPUT, { 1 , false , " path of the result file" , { " compile_commands.json" }, std::nullopt } },
212206 { APPEND, { 0 , false , " append result to an existing output file" , std::nullopt , ADVANCED_GROUP } },
213207 { INCLUDE, { 1 , false , " directory where from source file shall be in the output" , std::nullopt , ADVANCED_GROUP } },
@@ -219,11 +213,12 @@ int main(int argc, char* argv[], char* envp[])
219213 { WRAPPER, { 1 , false , " path to the wrapper directory" , { WRAPPER_DEFAULT_PATH }, DEVELOPER_GROUP } },
220214 { CITNAMES, { 1 , false , " path to the citnames executable" , { CITNAMES_DEFAULT_PATH }, DEVELOPER_GROUP } },
221215 { INTERCEPT, { 1 , false , " path to the intercept executable" , { INTERCEPT_DEFAULT_PATH }, DEVELOPER_GROUP } },
222- { COMMAND, { -1 , true , " command to execute" , std::nullopt , std::nullopt } } });
216+ { COMMAND, { -1 , true , " command to execute" , std::nullopt , std::nullopt } }
217+ });
223218 return parser.parse_or_exit (argc, const_cast <const char **>(argv))
224219 // change the log verbosity if requested.
225220 .on_success ([&argv, &envp](const auto & args) {
226- if (args.as_bool (VERBOSE).unwrap_or (false )) {
221+ if (args.as_bool (flags:: VERBOSE).unwrap_or (false )) {
227222 spdlog::set_pattern (" [%H:%M:%S.%f, br, %P] %v" );
228223 spdlog::set_level (spdlog::level::debug);
229224 }
0 commit comments