netlink: use features for slog and agent handler

Use features to enable/disable slog and agent handler on demand.
This helps to reduce dependency chains if slog/agent handler is unused.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
Liu Jiang
2020-05-31 03:17:12 +08:00
parent bbd40203d4
commit 710932df06
4 changed files with 29 additions and 14 deletions

2
src/agent/Cargo.lock generated
View File

@@ -257,8 +257,6 @@ dependencies = [
"protocols", "protocols",
"scan_fmt", "scan_fmt",
"slog", "slog",
"slog-async",
"slog-json",
"slog-scope", "slog-scope",
] ]

View File

@@ -9,10 +9,13 @@ edition = "2018"
[dependencies] [dependencies]
libc = "0.2.58" libc = "0.2.58"
nix = "0.17.0" nix = "0.17.0"
protobuf = "=2.14.0"
protocols = { path = "../protocols" } protobuf = { version = "=2.14.0", optional = true }
slog = { version = "2.5.2", features = ["dynamic-keys", "max_level_trace", "release_max_level_info"] } protocols = { path = "../protocols", optional = true }
slog-json = "2.3.0" slog = { version = "2.5.2", features = ["dynamic-keys", "max_level_trace", "release_max_level_info"], optional = true }
slog-async = "2.3.0" slog-scope = { version = "4.1.2", optional = true }
slog-scope = "4.1.2"
scan_fmt = "0.2.3" scan_fmt = "0.2.3"
[features]
with-log = ["slog", "slog-scope"]
with-agent-handler = ["protobuf", "protocols"]

View File

@@ -9,6 +9,7 @@
use protobuf::RepeatedField; use protobuf::RepeatedField;
use protocols::types::{ARPNeighbor, IPAddress, IPFamily, Interface, Route}; use protocols::types::{ARPNeighbor, IPAddress, IPFamily, Interface, Route};
#[cfg(feature = "with-log")]
// Convenience macro to obtain the scope logger // Convenience macro to obtain the scope logger
macro_rules! sl { macro_rules! sl {
() => { () => {

View File

@@ -9,17 +9,18 @@
#![allow(unused_parens)] #![allow(unused_parens)]
#![allow(unused_unsafe)] #![allow(unused_unsafe)]
mod agent_handler;
extern crate libc; extern crate libc;
extern crate nix; extern crate nix;
#[cfg(feature = "with-agent-handler")]
extern crate protobuf; extern crate protobuf;
#[cfg(feature = "with-agent-handler")]
extern crate protocols; extern crate protocols;
#[cfg(feature = "with-log")]
#[macro_use] #[macro_use]
extern crate slog; extern crate slog;
extern crate slog_async; #[cfg(feature = "with-log")]
extern crate slog_json;
extern crate slog_scope; extern crate slog_scope;
#[macro_use] #[macro_use]
@@ -33,8 +34,7 @@ use std::mem;
use std::net::{Ipv4Addr, Ipv6Addr}; use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::FromStr; use std::str::FromStr;
type Result<T> = std::result::Result<T, nix::Error>; #[cfg(feature = "with-log")]
// Convenience macro to obtain the scope logger // Convenience macro to obtain the scope logger
macro_rules! sl { macro_rules! sl {
() => { () => {
@@ -42,6 +42,19 @@ macro_rules! sl {
}; };
} }
#[cfg(not(feature = "with-log"))]
#[macro_export]
macro_rules! info {
($l:expr, #$tag:expr, $($args:tt)*) => {};
($l:expr, $($args:tt)*) => {};
}
#[cfg(feature = "with-agent-handler")]
mod agent_handler;
/// Specialized version of std::result::Result for Netlink related operations.
pub type Result<T> = std::result::Result<T, nix::Error>;
// define the struct, const, etc needed by netlink operations // define the struct, const, etc needed by netlink operations
pub type __s8 = libc::c_char; pub type __s8 = libc::c_char;