Skip to content

Commit

Permalink
rust: intercept is part of bear
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Nov 1, 2024
1 parent ea46fca commit 2dec5ce
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 70 deletions.
3 changes: 1 addition & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

[workspace]
members = [
"bear",
"intercept"
"bear"
]
resolver = "2"

Expand Down
10 changes: 8 additions & 2 deletions rust/bear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ path = "src/lib.rs"

[[bin]]
name = "bear"
path = "src/bin/main.rs"
path = "src/bin/bear.rs"

[[bin]]
name = "wrapper"
path = "src/bin/wrapper.rs"

[dependencies]
intercept = { path = "../intercept" }
thiserror.workspace = true
anyhow.workspace = true
lazy_static.workspace = true
Expand All @@ -36,3 +39,6 @@ path-absolutize.workspace = true
shell-words.workspace = true
nom.workspace = true
regex.workspace = true
crossbeam.workspace = true
crossbeam-channel.workspace = true
rand.workspace = true
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
extern crate core;

use anyhow::{Context, Result};
use intercept::reporter::{Reporter, TcpReporter};
use intercept::KEY_DESTINATION;
use bear::intercept::reporter::{Reporter, TcpReporter};
use bear::intercept::{Event, Execution, ProcessId, KEY_DESTINATION};
use std::path::{Path, PathBuf};

/// Implementation of the wrapper process.
Expand Down Expand Up @@ -98,9 +98,9 @@ fn next_in_path(target: &Path) -> Result<PathBuf> {
.ok_or_else(|| anyhow::anyhow!("Cannot find the real executable"))
}

fn report(execution: intercept::Execution) -> Result<()> {
let event = intercept::Event {
pid: intercept::ProcessId(std::process::id() as u32),
fn report(execution: Execution) -> Result<()> {
let event = Event {
pid: ProcessId(std::process::id() as u32),
execution,
};

Expand All @@ -115,10 +115,10 @@ fn report(execution: intercept::Execution) -> Result<()> {
.with_context(|| "Sending execution failed")
}

fn into_execution(path_buf: &Path) -> Result<intercept::Execution> {
fn into_execution(path_buf: &Path) -> Result<Execution> {
std::env::current_dir()
.with_context(|| "Cannot get current directory")
.map(|working_dir| intercept::Execution {
.map(|working_dir| Execution {
executable: path_buf.to_path_buf(),
// FIXME: substitute the executable name on the first position
arguments: std::env::args().collect(),
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::io::BufReader;
use std::path::PathBuf;

use super::args;
use intercept::Execution;
use super::intercept::Execution;

/// Responsible for reading the build events from the intercept mode.
///
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions rust/bear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod args;
pub mod config;
mod fixtures;
pub mod input;
pub mod intercept;
pub mod output;
pub mod recognition;
pub mod semantic;
Expand Down
5 changes: 2 additions & 3 deletions rust/bear/src/recognition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
//! The recognition logic is implemented in the `interpreters` module.
//! Here we only handle the errors and logging them to the console.

use super::{config, semantic};
use intercept::Execution;
use super::{config, intercept, semantic};
use std::convert::TryFrom;

pub struct Recognition {
Expand Down Expand Up @@ -51,7 +50,7 @@ impl TryFrom<&config::Main> for Recognition {
impl Recognition {
/// Simple call the semantic module to recognize the execution.
/// Forward only the compiler calls, and log each recognition result.
pub fn apply(&self, execution: Execution) -> Option<semantic::CompilerCall> {
pub fn apply(&self, execution: intercept::Execution) -> Option<semantic::CompilerCall> {
match self.interpreter.recognize(&execution) {
semantic::Recognition::Success(semantic) => {
log::debug!(
Expand Down
3 changes: 1 addition & 2 deletions rust/bear/src/semantic/interpreters/combinators.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use super::super::{CompilerCall, Interpreter, Recognition};
use intercept::Execution;
use super::super::{CompilerCall, Execution, Interpreter, Recognition};

/// Represents a set of interpreters, where any of them can recognize the semantic.
/// The evaluation is done in the order of the interpreters. The first one which
Expand Down
3 changes: 1 addition & 2 deletions rust/bear/src/semantic/interpreters/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use nom::branch::alt;
use nom::multi::many1;
use nom::sequence::preceded;

use super::super::{CompilerCall, Interpreter, Recognition};
use intercept::Execution;
use super::super::{CompilerCall, Execution, Interpreter, Recognition};
use internal::Argument;

pub(super) struct Gcc {}
Expand Down
3 changes: 1 addition & 2 deletions rust/bear/src/semantic/interpreters/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use std::collections::HashSet;
use std::path::PathBuf;
use std::vec;

use super::super::{CompilerCall, CompilerPass, Interpreter, Recognition};
use super::super::{CompilerCall, CompilerPass, Execution, Interpreter, Recognition};
use super::matchers::source::looks_like_a_source_file;
use intercept::Execution;

/// A tool to recognize a compiler by executable name.
pub(super) struct Generic {
Expand Down
3 changes: 1 addition & 2 deletions rust/bear/src/semantic/interpreters/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::collections::HashSet;
use std::path::PathBuf;

use super::super::{CompilerCall, Interpreter, Recognition};
use intercept::Execution;
use super::super::{CompilerCall, Execution, Interpreter, Recognition};

/// A tool to ignore a command execution by executable name.
pub(super) struct IgnoreByPath {
Expand Down
3 changes: 1 addition & 2 deletions rust/bear/src/semantic/interpreters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ mod test {
use std::collections::HashMap;
use std::path::PathBuf;

use super::super::{CompilerCall, Recognition};
use super::super::{CompilerCall, Execution, Recognition};
use super::*;
use crate::{vec_of_pathbuf, vec_of_strings};
use intercept::Execution;

#[test]
fn test_builder() {
Expand Down
2 changes: 1 addition & 1 deletion rust/bear/src/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

pub mod interpreters;

use intercept::Execution;
use super::intercept::Execution;
use std::path::PathBuf;

/// Represents an executed command semantic.
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions rust/intercept/tests/test.rs → rust/bear/tests/intercept.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use intercept::collector::{EventCollector, EventCollectorOnTcp};
use intercept::reporter::{Reporter, TcpReporter};
use intercept::*;
use bear::intercept::collector::{EventCollector, EventCollectorOnTcp};
use bear::intercept::reporter::{Reporter, TcpReporter};
use bear::intercept::*;

mod test {
use super::*;
Expand Down Expand Up @@ -130,7 +130,7 @@ mod test {
}

mod fixtures {
use intercept::ProcessId;
use bear::intercept::ProcessId;

pub fn timestamp() -> u64 {
rand::random::<u64>()
Expand Down
40 changes: 0 additions & 40 deletions rust/intercept/Cargo.toml

This file was deleted.

0 comments on commit 2dec5ce

Please sign in to comment.