Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Fixup onefuzz-task dependencies (#3552)
Browse files Browse the repository at this point in the history
Both the bin and lib for `onefuzz-task` include the same modules, which means some code is being compiled twice, and this leads to confusing errors if you update the bin code and not the lib code (e.g. adding new modules or something similar).

Instead, make the bin code depend on the lib code.

Also remove `extern crate` and `macro_use`, which are an older way of doing things. Macros are simply imported now.
  • Loading branch information
Porges authored Oct 5, 2023
1 parent 003c9ac commit 8d957ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/agent/onefuzz-task/src/check_for_update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::process::Stdio;

use anyhow::Result;
use anyhow::{bail, Result};
use onefuzz_telemetry::info;
use serde_json::Value;

pub fn run(onefuzz_built_version: &str) -> Result<()> {
Expand Down
16 changes: 3 additions & 13 deletions src/agent/onefuzz-task/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate clap;
#[macro_use]
extern crate onefuzz_telemetry;
extern crate onefuzz;

use anyhow::Result;
use clap::{ArgMatches, Command};
use clap::{crate_version, ArgMatches, Command};

use std::io::{stdout, Write};

mod check_for_update;
mod local;
mod managed;
mod tasks;

const LICENSE_CMD: &str = "licenses";
const LOCAL_CMD: &str = "local";
Expand All @@ -37,7 +27,7 @@ fn main() -> Result<()> {
let app = Command::new("onefuzz-task")
.version(built_version)
.subcommand(managed::cmd::args(MANAGED_CMD))
.subcommand(local::cmd::args(LOCAL_CMD))
.subcommand(onefuzz_task_lib::local::cmd::args(LOCAL_CMD))
.subcommand(Command::new(LICENSE_CMD).about("display third-party licenses"))
.subcommand(
Command::new(CHECK_FOR_UPDATE)
Expand All @@ -62,7 +52,7 @@ async fn run(args: ArgMatches) -> Result<()> {

match args.subcommand() {
Some((LICENSE_CMD, _)) => licenses(),
Some((LOCAL_CMD, sub)) => local::cmd::run(sub.to_owned()).await,
Some((LOCAL_CMD, sub)) => onefuzz_task_lib::local::cmd::run(sub.to_owned()).await,
Some((MANAGED_CMD, sub)) => managed::cmd::run(sub).await,
Some((CHECK_FOR_UPDATE, _)) => check_for_update::run(ONEFUZZ_BUILT_VERSION),
_ => anyhow::bail!("No command provided. Run with 'help' to see available commands."),
Expand Down
11 changes: 6 additions & 5 deletions src/agent/onefuzz-task/src/managed/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// Licensed under the MIT License.
use std::path::PathBuf;

use anyhow::Result;
use clap::{Arg, Command};
use anyhow::{bail, Result};
use clap::{value_parser, Arg, Command};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};

use flexi_logger::{Duplicate, FileSpec, Logger, WriteMode};
use onefuzz::ipc::IpcMessageKind;
use onefuzz_telemetry::{error, info, warn};
use std::time::Duration;
use tokio::task;

use crate::tasks::config::{CommonConfig, Config};
use onefuzz_task_lib::tasks::config::{CommonConfig, Config};

const OOM_CHECK_INTERVAL: Duration = Duration::from_secs(5);

Expand Down Expand Up @@ -56,7 +57,7 @@ pub async fn run(args: &clap::ArgMatches) -> Result<()> {
IpcSender<IpcMessageKind>,
IpcReceiver<IpcMessageKind>,
) = ipc::channel()?;
info!("Conecting...");
info!("Connecting...");
let oneshot_sender = IpcSender::connect(config.common().from_agent_to_task_endpoint.clone())?;
info!("Sending sender to agent");
oneshot_sender.send(agent_sender)?;
Expand Down Expand Up @@ -104,7 +105,7 @@ pub async fn run(args: &clap::ArgMatches) -> Result<()> {
// Ignore this task if it returns due to a querying error.
Ok(oom) = check_oom => {
// Convert the OOM notification to an error, so we can log it below.
let err = format_err!("out of memory: {} bytes available, {} required", oom.available_bytes, oom.min_bytes);
let err = anyhow::format_err!("out of memory: {} bytes available, {} required", oom.available_bytes, oom.min_bytes);
Err(err)
},

Expand Down

0 comments on commit 8d957ce

Please sign in to comment.