Skip to content

Commit

Permalink
removed build_env code; separated this into a separate branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cwshugg committed Oct 16, 2024
1 parent 2e88c5f commit 14a64ac
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ use std::{

const DEFAULT_FUZZ_DIR: &str = "fuzz";

/// The name of the environment variable that is exposed to indicate a
/// cargo-fuzz build is occurring.
const BUILD_ENV_FLAG: &str = "CARGO_FUZZ";

/// The name of the environment variable that exposes the cargo fuzz manifest
/// path during builds.
const BUILD_ENV_MANIFEST_DIR: &str = "CARGO_FUZZ_MANIFEST";

pub struct FuzzProject {
/// The project with fuzz targets
fuzz_dir: PathBuf,
Expand Down Expand Up @@ -343,39 +335,6 @@ impl FuzzProject {
}
}

// Helper function for `exec_build()` used to expose cargo-fuzz information
// via environment variables. Such environment variables can be used by fuzz
// target dependencies' build scripts to detect whether or not cargo-fuzz is
// responsible for the build.
//
// This is called directly before the `cargo build ...` command is executed.
fn build_env_expose(
&self,
_mode: options::BuildMode,
_build: &options::BuildOptions,
_fuzz_target: Option<&str>,
) -> Result<()> {
// expose a flag environment variable to allow the detection of cargo-fuzz
env::set_var(BUILD_ENV_FLAG, "1");

// expose the path to the cargo-fuzz manifest
let manifest_path = self.manifest_path();
env::set_var(BUILD_ENV_MANIFEST_DIR, manifest_path.as_os_str());

Ok(())
}

// Helper function for `exec_build()` used to un-expose cargo-fuzz
// information that was previously exposed in environment variables during
// `build_env_expose()`.
//
// This is called directly after the `cargo build ...` command is executed.
fn build_env_unexpose(&self) -> Result<()> {
env::remove_var(BUILD_ENV_FLAG);
env::remove_var(BUILD_ENV_MANIFEST_DIR);
Ok(())
}

pub fn exec_build(
&self,
mode: options::BuildMode,
Expand All @@ -398,22 +357,13 @@ impl FuzzProject {
cmd.arg("--target-dir").arg(target_dir);
}

// expose build information via environment variables, before executing
// the build command
self.build_env_expose(mode, build, fuzz_target)
.expect("Failed to set cargo-fuzz build environment variables.");

let status = cmd
.status()
.with_context(|| format!("failed to execute: {:?}", cmd))?;
if !status.success() {
bail!("failed to build fuzz script: {:?}", cmd);
}

// un-expose build information, after the command has finished
self.build_env_unexpose()
.expect("Failed to un-set cargo-fuzz build environment variables.");

Ok(())
}

Expand Down

0 comments on commit 14a64ac

Please sign in to comment.