Skip to content

Commit 017d5d9

Browse files
committed
Merge branch 'devel' into master
2 parents 241918c + ee0d398 commit 017d5d9

File tree

18 files changed

+41
-50
lines changed

18 files changed

+41
-50
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ ExternalProject_Add(BearSource
5858
-DROOT_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
5959
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
6060
-DENABLE_UNIT_TESTS:BOOL=${ENABLE_UNIT_TESTS}
61-
BUILD_ALWAYS
62-
1
6361
TEST_BEFORE_INSTALL
6462
1
6563
TEST_COMMAND

source/bear/main.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

source/citnames/main.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ int main(int argc, char* argv[], char* envp[])
5353
spdlog::set_pattern("citnames: %v");
5454
spdlog::set_level(spdlog::level::info);
5555

56-
const flags::Parser parser("citnames", VERSION,
57-
{ { cs::Application::VERBOSE, { 0, false, "run the application verbose", std::nullopt, std::nullopt } },
56+
const flags::Parser parser("citnames", VERSION,{
5857
{ cs::Application::INPUT, { 1, false, "path of the input file", { "commands.json" }, std::nullopt } },
5958
{ cs::Application::OUTPUT, { 1, false, "path of the result file", { "compile_commands.json" }, std::nullopt } },
6059
{ cs::Application::CONFIG, { 1, false, "path of the config file", std::nullopt, std::nullopt } },
@@ -66,7 +65,7 @@ int main(int argc, char* argv[], char* envp[])
6665
return parser.parse_or_exit(argc, const_cast<const char**>(argv))
6766
// change the log verbosity if requested.
6867
.on_success([&argv, &envp](const auto& args) {
69-
if (args.as_bool(cs::Application::VERBOSE).unwrap_or(false)) {
68+
if (args.as_bool(flags::VERBOSE).unwrap_or(false)) {
7069
spdlog::set_pattern("[%H:%M:%S.%f, cs, %P] %v");
7170
spdlog::set_level(spdlog::level::debug);
7271
}

source/citnames/source/Application.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace cs {
2727

2828
class Application {
2929
public:
30-
static constexpr char VERBOSE[] = "--verbose";
3130
static constexpr char INPUT[] = "--input";
3231
static constexpr char OUTPUT[] = "--output";
3332
static constexpr char INCLUDE[] = "--include";

source/intercept/source/collect/Application.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace ic {
103103
auto server = grpc::ServerBuilder()
104104
.RegisterService(&supervisor)
105105
.RegisterService(&interceptor)
106-
.AddListeningPort("0.0.0.0:0", grpc::InsecureServerCredentials(), &port)
106+
.AddListeningPort("127.0.0.1:0", grpc::InsecureServerCredentials(), &port)
107107
.BuildAndStart();
108108

109109
std::string server_address = fmt::format("0.0.0.0:{}", port);

source/intercept/source/collect/Application.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace ic {
2929

3030
class Application {
3131
public:
32-
static constexpr char VERBOSE[] = "--verbose";
3332
static constexpr char OUTPUT[] = "--output";
3433
static constexpr char LIBRARY[] = "--library";
3534
static constexpr char EXECUTOR[] = "--executor";

source/intercept/source/collect/SessionLibrary.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace ic {
5757

5858
rust::Result<Session::SharedPtr> LibraryPreloadSession::from(const flags::Arguments& args, const char **envp)
5959
{
60-
auto verbose = args.as_bool(ic::Application::VERBOSE).unwrap_or(false);
60+
auto verbose = args.as_bool(flags::VERBOSE).unwrap_or(false);
6161
auto library = args.as_string(ic::Application::LIBRARY);
6262
auto executor = args.as_string(ic::Application::EXECUTOR);
6363
auto environment = sys::env::from(envp);

source/intercept/source/collect/SessionWrapper.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace ic {
108108

109109
rust::Result<Session::SharedPtr> WrapperSession::from(const flags::Arguments& args, const char **envp)
110110
{
111-
const bool verbose = args.as_bool(ic::Application::VERBOSE).unwrap_or(false);
111+
const bool verbose = args.as_bool(flags::VERBOSE).unwrap_or(false);
112112
auto wrapper_dir = args.as_string(ic::Application::WRAPPER);
113113
auto wrappers = wrapper_dir
114114
.and_then<std::list<fs::path>>([](auto wrapper_dir) {
@@ -122,7 +122,7 @@ namespace ic {
122122
el::Resolver resolver;
123123
for (const auto& wrapper : wrappers) {
124124
auto basename = wrapper.filename();
125-
auto candidate = resolver.from_path(basename.c_str(), const_cast<char* const*>(envp));
125+
auto candidate = resolver.from_path(basename.c_str(), envp);
126126
candidate.on_success([&result, &basename](auto candidate) {
127127
result[basename] = candidate;
128128
});
@@ -139,7 +139,7 @@ namespace ic {
139139
// FIXME: it would be more correct if we shell-split the `env_it->second`
140140
// and use only the program name, but not the argument. But then how
141141
// to deal with the errors?
142-
auto program = resolver.from_path(std::string_view(env_it), const_cast<char* const*>(envp));
142+
auto program = resolver.from_path(std::string_view(env_it), envp);
143143

144144
// find the current mapping for the program the user wants to run.
145145
// and replace the program what the wrapper will call.

source/intercept/source/collect/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ int main(int argc, char* argv[], char* envp[])
6868
spdlog::set_pattern("intercept: %v [pid: %P]");
6969
spdlog::set_level(spdlog::level::info);
7070

71-
const flags::Parser parser("intercept", VERSION,
72-
{ { ic::Application::VERBOSE, { 0, false, "run the interception verbose", std::nullopt, std::nullopt } },
71+
const flags::Parser parser("intercept", VERSION, {
7372
{ ic::Application::OUTPUT, { 1, false, "path of the result file", { "commands.json" }, std::nullopt } },
7473
{ ic::Application::FORCE_PRELOAD, { 0, false, "force to use library preload", std::nullopt, DEVELOPER_GROUP } },
7574
{ ic::Application::FORCE_WRAPPER, { 0, false, "force to use compiler wrappers", std::nullopt, DEVELOPER_GROUP } },
7675
{ ic::Application::LIBRARY, { 1, false, "path to the preload library", { LIBRARY_DEFAULT_PATH }, DEVELOPER_GROUP } },
7776
{ ic::Application::EXECUTOR, { 1, false, "path to the preload executable", { EXECUTOR_DEFAULT_PATH }, DEVELOPER_GROUP } },
7877
{ ic::Application::WRAPPER, { 1, false, "path to the wrapper directory", { WRAPPER_DEFAULT_PATH }, DEVELOPER_GROUP } },
79-
{ ic::Application::COMMAND, { -1, true, "command to execute", std::nullopt, std::nullopt } } });
78+
{ ic::Application::COMMAND, { -1, true, "command to execute", std::nullopt, std::nullopt } }
79+
});
8080
return parser.parse_or_exit(argc, const_cast<const char**>(argv))
8181
// change the log verbosity if requested.
8282
.on_success([&argv, &envp](const auto& args) {
83-
if (args.as_bool(ic::Application::VERBOSE).unwrap_or(false)) {
83+
if (args.as_bool(flags::VERBOSE).unwrap_or(false)) {
8484
spdlog::set_pattern("[%H:%M:%S.%f, ic, %P] %v");
8585
spdlog::set_level(spdlog::level::debug);
8686
}

source/intercept/source/report/libexec/Executor.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace el {
131131
CHECK_SESSION(session_);
132132
CHECK_POINTER(file);
133133

134-
if (auto executable = resolver_.from_path(file, envp); executable.is_ok()) {
134+
if (auto executable = resolver_.from_path(file, const_cast<const char **>(envp)); executable.is_ok()) {
135135
const CommandBuilder cmd(session_, executable.unwrap(), argv);
136136
const char* dst[cmd.length()];
137137
cmd.assemble(dst);
@@ -183,7 +183,7 @@ namespace el {
183183
CHECK_SESSION(session_);
184184
CHECK_POINTER(file);
185185

186-
if (auto executable = resolver_.from_path(file, envp); executable.is_ok()) {
186+
if (auto executable = resolver_.from_path(file, const_cast<const char **>(envp)); executable.is_ok()) {
187187
const CommandBuilder cmd(session_, executable.unwrap(), argv);
188188
const char* dst[cmd.length()];
189189
cmd.assemble(dst);

0 commit comments

Comments
 (0)