xref: /aosp_15_r20/external/zucchini/zucchini_main.cc (revision a03ca8b91e029cd15055c20c78c2e087c84792e4)
1*a03ca8b9SKrzysztof Kosiński // Copyright 2017 The Chromium Authors. All rights reserved.
2*a03ca8b9SKrzysztof Kosiński // Use of this source code is governed by a BSD-style license that can be
3*a03ca8b9SKrzysztof Kosiński // found in the LICENSE file.
4*a03ca8b9SKrzysztof Kosiński 
5*a03ca8b9SKrzysztof Kosiński #include <iostream>
6*a03ca8b9SKrzysztof Kosiński 
7*a03ca8b9SKrzysztof Kosiński #include "base/command_line.h"
8*a03ca8b9SKrzysztof Kosiński #include "base/logging.h"
9*a03ca8b9SKrzysztof Kosiński #include "base/process/memory.h"
10*a03ca8b9SKrzysztof Kosiński #include "build/build_config.h"
11*a03ca8b9SKrzysztof Kosiński #include "components/zucchini/main_utils.h"
12*a03ca8b9SKrzysztof Kosiński 
13*a03ca8b9SKrzysztof Kosiński #if defined(OS_WIN)
14*a03ca8b9SKrzysztof Kosiński #include "base/win/process_startup_helper.h"
15*a03ca8b9SKrzysztof Kosiński #endif  // defined(OS_WIN)
16*a03ca8b9SKrzysztof Kosiński 
17*a03ca8b9SKrzysztof Kosiński namespace {
18*a03ca8b9SKrzysztof Kosiński 
InitLogging()19*a03ca8b9SKrzysztof Kosiński void InitLogging() {
20*a03ca8b9SKrzysztof Kosiński   logging::LoggingSettings settings;
21*a03ca8b9SKrzysztof Kosiński   settings.logging_dest =
22*a03ca8b9SKrzysztof Kosiński       logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
23*a03ca8b9SKrzysztof Kosiński   settings.log_file_path = nullptr;
24*a03ca8b9SKrzysztof Kosiński   settings.lock_log = logging::DONT_LOCK_LOG_FILE;
25*a03ca8b9SKrzysztof Kosiński   settings.delete_old = logging::APPEND_TO_OLD_LOG_FILE;
26*a03ca8b9SKrzysztof Kosiński   bool logging_res = logging::InitLogging(settings);
27*a03ca8b9SKrzysztof Kosiński   CHECK(logging_res);
28*a03ca8b9SKrzysztof Kosiński }
29*a03ca8b9SKrzysztof Kosiński 
InitErrorHandling(const base::CommandLine & command_line)30*a03ca8b9SKrzysztof Kosiński void InitErrorHandling(const base::CommandLine& command_line) {
31*a03ca8b9SKrzysztof Kosiński   base::EnableTerminationOnHeapCorruption();
32*a03ca8b9SKrzysztof Kosiński   base::EnableTerminationOnOutOfMemory();
33*a03ca8b9SKrzysztof Kosiński #if defined(OS_WIN)
34*a03ca8b9SKrzysztof Kosiński   base::win::RegisterInvalidParamHandler();
35*a03ca8b9SKrzysztof Kosiński   base::win::SetupCRT(command_line);
36*a03ca8b9SKrzysztof Kosiński #endif  // defined(OS_WIN)
37*a03ca8b9SKrzysztof Kosiński }
38*a03ca8b9SKrzysztof Kosiński 
39*a03ca8b9SKrzysztof Kosiński }  // namespace
40*a03ca8b9SKrzysztof Kosiński 
main(int argc,const char * argv[])41*a03ca8b9SKrzysztof Kosiński int main(int argc, const char* argv[]) {
42*a03ca8b9SKrzysztof Kosiński   // Initialize infrastructure from base.
43*a03ca8b9SKrzysztof Kosiński   base::CommandLine::Init(argc, argv);
44*a03ca8b9SKrzysztof Kosiński   const base::CommandLine& command_line =
45*a03ca8b9SKrzysztof Kosiński       *base::CommandLine::ForCurrentProcess();
46*a03ca8b9SKrzysztof Kosiński   InitLogging();
47*a03ca8b9SKrzysztof Kosiński   InitErrorHandling(command_line);
48*a03ca8b9SKrzysztof Kosiński   zucchini::status::Code status =
49*a03ca8b9SKrzysztof Kosiński       RunZucchiniCommand(command_line, std::cout, std::cerr);
50*a03ca8b9SKrzysztof Kosiński   if (!(status == zucchini::status::kStatusSuccess ||
51*a03ca8b9SKrzysztof Kosiński         status == zucchini::status::kStatusInvalidParam)) {
52*a03ca8b9SKrzysztof Kosiński     std::cerr << "Failed with code " << static_cast<int>(status) << std::endl;
53*a03ca8b9SKrzysztof Kosiński   }
54*a03ca8b9SKrzysztof Kosiński   return static_cast<int>(status);
55*a03ca8b9SKrzysztof Kosiński }
56