github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/cmd/scandeps/scandeps.cc (about) 1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <ctime> 16 #include <iostream> 17 #include <memory> 18 #include <string> 19 #include <thread> 20 21 #ifdef _WIN32 22 #define GLOG_NO_ABBREVIATED_SEVERITIES 23 #endif 24 #include <glog/logging.h> 25 26 #include "gflags/gflags.h" 27 #include "pkg/version/version.h" 28 #include "server/server.h" 29 30 #ifdef __linux__ 31 #ifndef __GLIBC_NEW__ 32 extern "C" { 33 /* 34 * getentropy is technically compiled into goma but is never actually called by 35 * anything the scandeps service does. 36 */ 37 int __wrap_getentropy(uint8_t* buffer, size_t length) { 38 LOG(FATAL) << "getentropy called; this is unimplemented. If this error is " 39 "observed then it will need to be fixed."; 40 // FATAL log will terminate the service. 41 } 42 } 43 44 #else 45 int __wrap_getentropy(uint8_t* buffer, size_t length) { 46 return __real_getentropy(buffer, length); 47 } 48 #endif // __GLIBC_NEW__ 49 #endif // __linux__ 50 51 // Threads have 5 seconds to finish before being hard terminated. 52 constexpr std::size_t kShutdown_delay = 5; 53 54 #ifdef _WIN32 // autodefined when targeting Windows (32 and 64bit) 55 // gRPC on Windows does not currently support named pipes for IPC communication 56 DEFINE_string(server_address, "127.0.0.1:8001", 57 "The address/port to listen on as TCP/IP address:" 58 "port."); 59 #else 60 DEFINE_string(server_address, "127.0.0.1:8001", 61 "The address to listen on; prepend with 'unix://' " 62 "for a named pipe, otherwise IP address:port is assumed."); 63 #endif 64 65 // log_dir is automatic from glog. 66 DEFINE_string(cache_dir, "", 67 "The directory to which the deps cache file should be written to " 68 "and from which it should be loaded from."); 69 DEFINE_int32( 70 deps_cache_max_mb, 256, 71 "Maximum size of the deps cache file (for goma input processor only)."); 72 DEFINE_bool(enable_deps_cache, false, 73 "Enables the deps cache if --cache_dir is provided"); 74 DEFINE_uint32(shutdown_delay_seconds, kShutdown_delay, 75 "Delay, in seconds, server will wait for requests to finish " 76 "during shutdown before terminating them."); 77 78 DEFINE_uint32(experimental_deadlock, 0, 79 "Indicates the number of inputs to process before simulating a " 80 "deadlock; 0 disables " 81 "(default); for debugging purposes only"); 82 DEFINE_uint32(experimental_segfault, 0, 83 "Indicates the number of inputs to process before segfaulting; 0 " 84 "disables (default); " 85 "for debugging purposes only"); 86 87 int main(int argc, char** argv) { 88 gflags::SetVersionString(RECLIENT_VERSION " " INPUT_PROCESSOR); 89 gflags::ParseCommandLineFlags(&argc, &argv, true); 90 91 std::unique_ptr<ScandepsServer> server = std::make_unique<ScandepsServer>( 92 FLAGS_server_address, FLAGS_cache_dir, FLAGS_log_dir, 93 FLAGS_deps_cache_max_mb, FLAGS_enable_deps_cache, 94 FLAGS_shutdown_delay_seconds, FLAGS_experimental_deadlock, 95 FLAGS_experimental_segfault); 96 97 auto success = 98 server.get()->RunServer(argv[0]); // Block until server is stopped 99 LOG(INFO) << "Server has been stopped."; 100 if (success) { 101 return EXIT_SUCCESS; 102 } 103 return EXIT_FAILURE; 104 }