Skip to content

Commit 46c91ae

Browse files
committed
Merge branch 'devel'
2 parents 93b4d6e + dbbdcd7 commit 46c91ae

File tree

16 files changed

+203
-151
lines changed

16 files changed

+203
-151
lines changed

source/intercept/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ target_include_directories(intercept_a PUBLIC source/)
3030
target_link_libraries(intercept_a PUBLIC main_a)
3131
target_link_libraries(intercept_a PUBLIC exec_a)
3232
target_link_libraries(intercept_a PUBLIC flags_a)
33-
target_link_libraries(intercept_a PUBLIC supervise_a)
33+
target_link_libraries(intercept_a PUBLIC rpc_a)
3434
target_link_libraries(intercept_a PUBLIC sys_a)
3535
target_link_libraries(intercept_a PUBLIC report_a)
3636
target_link_libraries(intercept_a PUBLIC result_a)
@@ -44,7 +44,7 @@ add_executable(intercept
4444
target_link_libraries(intercept main_a)
4545
target_link_libraries(intercept intercept_a)
4646
target_link_libraries(intercept report_a)
47-
target_link_libraries(intercept supervise_a)
47+
target_link_libraries(intercept rpc_a)
4848
target_link_libraries(intercept sys_a)
4949
target_link_libraries(intercept flags_a)
5050
target_link_libraries(intercept exec_a)
@@ -76,7 +76,7 @@ if (ENABLE_UNIT_TESTS)
7676
target_link_libraries(intercept_unit_test exec_a)
7777
target_link_libraries(intercept_unit_test intercept_a)
7878
target_link_libraries(intercept_unit_test report_a)
79-
target_link_libraries(intercept_unit_test supervise_a)
79+
target_link_libraries(intercept_unit_test rpc_a)
8080
target_link_libraries(intercept_unit_test sys_a)
8181
target_link_libraries(intercept_unit_test flags_a)
8282
target_link_libraries(intercept_unit_test PkgConfig::GTest ${CMAKE_THREAD_LIBS_INIT})
@@ -91,7 +91,7 @@ add_library(reporter_a OBJECT
9191
)
9292

9393
target_include_directories(reporter_a PUBLIC source/)
94-
target_link_libraries(reporter_a PUBLIC supervise_a)
94+
target_link_libraries(reporter_a PUBLIC rpc_a)
9595
target_link_libraries(reporter_a PUBLIC result_a)
9696
target_link_libraries(reporter_a PUBLIC spdlog::spdlog)
9797

@@ -107,7 +107,7 @@ target_link_libraries(wrapper flags_a)
107107
target_link_libraries(wrapper reporter_a)
108108
target_link_libraries(wrapper result_a)
109109
target_link_libraries(wrapper sys_a)
110-
target_link_libraries(wrapper supervise_a)
110+
target_link_libraries(wrapper rpc_a)
111111
target_link_libraries(wrapper spdlog::spdlog)
112112

113113
install(TARGETS wrapper
@@ -160,7 +160,7 @@ target_link_libraries(er reporter_a)
160160
target_link_libraries(er result_a)
161161
target_link_libraries(er flags_a)
162162
target_link_libraries(er sys_a)
163-
target_link_libraries(er supervise_a)
163+
target_link_libraries(er rpc_a)
164164
target_link_libraries(er spdlog::spdlog)
165165

166166
install(TARGETS er

source/intercept/proto/CMakeLists.txt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,35 @@ add_custom_command(
2626
"${SUPERVISE_PROTO}"
2727
)
2828

29-
add_library(supervise_a OBJECT
29+
get_filename_component(INTERCEPT_PROTO "intercept.proto" ABSOLUTE)
30+
get_filename_component(INTERCEPT_PROTO_PATH "${SUPERVISE_PROTO}" PATH)
31+
32+
add_custom_command(
33+
COMMAND
34+
${_PROTOBUF_PROTOC}
35+
ARGS
36+
-I "${SUPERVISE_PROTO_PATH}"
37+
--grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
38+
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
39+
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
40+
"${INTERCEPT_PROTO}"
41+
WORKING_DIRECTORY
42+
"${CMAKE_CURRENT_SOURCE_DIR}"
43+
OUTPUT
44+
${CMAKE_CURRENT_BINARY_DIR}/intercept.pb.h
45+
${CMAKE_CURRENT_BINARY_DIR}/intercept.grpc.pb.h
46+
${CMAKE_CURRENT_BINARY_DIR}/intercept.pb.cc
47+
${CMAKE_CURRENT_BINARY_DIR}/intercept.grpc.pb.cc
48+
DEPENDS
49+
"${INTERCEPT_PROTO}"
50+
)
51+
52+
add_library(rpc_a OBJECT
3053
${CMAKE_CURRENT_BINARY_DIR}/supervise.pb.cc
3154
${CMAKE_CURRENT_BINARY_DIR}/supervise.grpc.pb.cc
55+
${CMAKE_CURRENT_BINARY_DIR}/intercept.pb.cc
56+
${CMAKE_CURRENT_BINARY_DIR}/intercept.grpc.pb.cc
3257
)
3358

34-
target_include_directories(supervise_a PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
35-
target_link_libraries(supervise_a PUBLIC PkgConfig::gRPC)
59+
target_include_directories(rpc_a PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
60+
target_link_libraries(rpc_a PUBLIC PkgConfig::gRPC)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright (C) 2012-2020 by László Nagy
2+
This file is part of Bear.
3+
4+
Bear is a tool to generate compilation database for clang tooling.
5+
6+
Bear is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Bear is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
syntax = "proto3";
21+
22+
package rpc;
23+
option cc_enable_arenas = true;
24+
25+
// Represents the remote sink of supervised process events.
26+
//
27+
// Events from a process execution can be sent from many actors (mostly
28+
// supervisor processes). The events are collected in a common place
29+
// in order to reconstruct of final report of a build process.
30+
service Interceptor {
31+
32+
// Register a process related events.
33+
rpc Register (Event) returns (Empty) {}
34+
}
35+
36+
// Represent a relevant life cycle event of a process.
37+
//
38+
// Currently it's only the process life cycle events (start, signal,
39+
// terminate), but can be extended later with performance related
40+
// events like monitoring the CPU usage or the memory allocation if
41+
// those information are available to the the supervisor process.
42+
message Event {
43+
44+
// Required.
45+
uint64 rid = 1;
46+
47+
// Required.
48+
uint32 pid = 2;
49+
50+
// Optional.
51+
uint32 ppid = 3;
52+
53+
// Required.
54+
// (ISO-8601 date-tie format with microsecond precision in UTC timezone)
55+
string timestamp = 4;
56+
57+
reserved 5 to 10;
58+
59+
// Required.
60+
oneof event {
61+
Started started = 11;
62+
Terminated terminated = 12;
63+
Signalled signalled = 13;
64+
}
65+
66+
// Represents a successful process execution.
67+
message Started {
68+
// All fields are required.
69+
string executable = 3;
70+
repeated string arguments = 4;
71+
string working_dir = 5;
72+
map<string, string> environment = 6;
73+
}
74+
75+
// Represents the termination of the supervised process.
76+
message Terminated {
77+
// Optional.
78+
// (Killed processes have no exit status.)
79+
int64 status = 1;
80+
}
81+
82+
// Represents the supervised process received a signal.
83+
message Signalled {
84+
// Required.
85+
int32 number = 1;
86+
}
87+
}
88+
89+
message Empty {}

source/intercept/proto/supervise.proto

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
syntax = "proto3";
2121

22-
package supervise;
22+
package rpc;
2323
option cc_enable_arenas = true;
2424

2525
// This represents a (remote) supervisor process to set up program execution.
@@ -63,69 +63,3 @@ message ResolveResponse {
6363
message Environment {
6464
map<string, string> values = 1;
6565
}
66-
67-
// Represents the remote sink of supervised process events.
68-
//
69-
// Events from a process execution can be sent from many actors (mostly
70-
// supervisor processes). The events are collected in a common place
71-
// in order to reconstruct of final report of a build process.
72-
service Interceptor {
73-
74-
// Register a process related events.
75-
rpc Register (Event) returns (Empty) {}
76-
}
77-
78-
// Represent a relevant life cycle event of a process.
79-
//
80-
// Currently it's only the process life cycle events (start, signal,
81-
// terminate), but can be extended later with performance related
82-
// events like monitoring the CPU usage or the memory allocation if
83-
// those information are available to the the supervisor process.
84-
message Event {
85-
86-
// Required.
87-
uint64 rid = 1;
88-
89-
// Required.
90-
uint32 pid = 2;
91-
92-
// Optional.
93-
uint32 ppid = 3;
94-
95-
// Required.
96-
// (ISO-8601 date-tie format with microsecond precision in UTC timezone)
97-
string timestamp = 4;
98-
99-
reserved 5 to 10;
100-
101-
// Required.
102-
oneof event {
103-
Started started = 11;
104-
Terminated terminated = 12;
105-
Signalled signalled = 13;
106-
}
107-
108-
// Represents a successful process execution.
109-
message Started {
110-
// All fields are required.
111-
string executable = 3;
112-
repeated string arguments = 4;
113-
string working_dir = 5;
114-
map<string, string> environment = 6;
115-
}
116-
117-
// Represents the termination of the supervised process.
118-
message Terminated {
119-
// Optional.
120-
// (Killed processes have no exit status.)
121-
int64 status = 1;
122-
}
123-
124-
// Represents the supervised process received a signal.
125-
message Signalled {
126-
// Required.
127-
int32 number = 1;
128-
}
129-
}
130-
131-
message Empty {}

source/intercept/source/collect/Application.cc

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "collect/Session.h"
2424
#include "intercept/Flags.h"
2525
#include "libsys/Os.h"
26-
#include "libsys/Signal.h"
2726

2827
#include <grpcpp/security/server_credentials.h>
2928
#include <grpcpp/server_builder.h>
@@ -36,27 +35,6 @@ namespace {
3635

3736
constexpr std::optional<std::string_view> DEVELOPER_GROUP = { "developer options" };
3837

39-
rust::Result<int> execute_command(const ic::Session& session, const std::vector<std::string_view>& command) {
40-
return session.supervise(command)
41-
.and_then<sys::Process>([](auto builder) {
42-
return builder.spawn();
43-
})
44-
.and_then<sys::ExitStatus>([](auto child) {
45-
sys::SignalForwarder guard(child);
46-
return child.wait();
47-
})
48-
.map<int>([](auto status) {
49-
return status.code().value_or(EXIT_FAILURE);
50-
})
51-
.map_err<std::runtime_error>([](auto error) {
52-
spdlog::warn("Command execution failed: {}", error.what());
53-
return error;
54-
})
55-
.on_success([](auto status) {
56-
spdlog::debug("Running command. [Exited with {0}]", status);
57-
});
58-
}
59-
6038
rust::Result<std::vector<std::string_view>> get_command(const flags::Arguments& args)
6139
{
6240
return args.as_string_list(ic::COMMAND)
@@ -82,12 +60,12 @@ namespace ic {
8260
.AddListeningPort("127.0.0.1:0", grpc::InsecureServerCredentials(), &port)
8361
.BuildAndStart();
8462

85-
std::string server_address = fmt::format("0.0.0.0:{}", port);
63+
std::string server_address = fmt::format("127.0.0.1:{}", port);
8664
spdlog::debug("Running gRPC server. [Listening on {0}]", server_address);
8765
// Configure the session and the reporter objects
8866
session_->set_server_address(server_address);
8967
// Execute the build command
90-
auto result = execute_command(*session_, command_);
68+
auto result = session_->execute(command_);
9169
// Stop the gRPC server
9270
spdlog::debug("Stopping gRPC server.");
9371
server->Shutdown();

source/intercept/source/collect/Reporter.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "config.h"
2121
#include "intercept/Flags.h"
2222
#include "collect/Reporter.h"
23-
#include "collect/Application.h"
2423
#include "libsys/Os.h"
2524

2625
#include <spdlog/spdlog.h>
@@ -73,7 +72,7 @@ namespace {
7372
});
7473
}
7574

76-
void update_run_with_started(report::Run& target, const supervise::Event& source)
75+
void update_run_with_started(report::Run& target, const rpc::Event& source)
7776
{
7877
spdlog::debug("Received event is merged into execution report. [pid: {}, event: start]", source.pid());
7978
auto event = report::Event {
@@ -85,7 +84,7 @@ namespace {
8584
target.events.emplace_back(event);
8685
}
8786

88-
void update_run_with_signaled(report::Run& target, const supervise::Event& source)
87+
void update_run_with_signaled(report::Run& target, const rpc::Event& source)
8988
{
9089
spdlog::debug("Received event is merged into execution report. [pid: {}, event: signal]", source.pid());
9190
auto event = report::Event {
@@ -97,7 +96,7 @@ namespace {
9796
target.events.emplace_back(event);
9897
}
9998

100-
void update_run_with_terminated(report::Run& target, const supervise::Event& source)
99+
void update_run_with_terminated(report::Run& target, const rpc::Event& source)
101100
{
102101
spdlog::debug("Received event is merged into execution report. [pid: {}, event: stop]", source.pid());
103102
auto event = report::Event {
@@ -124,7 +123,7 @@ namespace {
124123
return (value == 0 ? std::nullopt : std::make_optional(value));
125124
}
126125

127-
report::Execution init_execution(const supervise::Event& source)
126+
report::Execution init_execution(const rpc::Event& source)
128127
{
129128
const auto& started = source.started();
130129

@@ -167,7 +166,7 @@ namespace ic {
167166
{
168167
}
169168

170-
void Reporter::report(const ::supervise::Event& event)
169+
void Reporter::report(const rpc::Event& event)
171170
{
172171
const auto rid = event.rid();
173172
if (auto it = executions_.find(rid); it != executions_.end()) {

source/intercept/source/collect/Reporter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "libflags/Flags.h"
2424
#include "intercept/output/Report.h"
2525
#include "libresult/Result.h"
26-
#include "supervise.pb.h"
26+
#include "intercept.pb.h"
2727

2828
#include <filesystem>
2929
#include <memory>
@@ -39,7 +39,7 @@ namespace ic {
3939
using SharedPtr = std::shared_ptr<Reporter>;
4040
static rust::Result<Reporter::SharedPtr> from(const flags::Arguments&, const ic::Session&);
4141

42-
void report(const ::supervise::Event& request);
42+
void report(const rpc::Event& request);
4343
void flush();
4444

4545
public:

0 commit comments

Comments
 (0)