Skip to content

Commit

Permalink
Use Build::getenv instead of env::var* in anywhere that makes sen…
Browse files Browse the repository at this point in the history
…se (#1103)
  • Loading branch information
NobodyXu authored Jun 25, 2024
1 parent 6fa9ea6 commit 4cb5b94
Show file tree
Hide file tree
Showing 10 changed files with 622 additions and 420 deletions.
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
disallowed-methods = [
{ path = "std::env::var_os", reason = "Please use Build::getenv" },
{ path = "std::env::var", reason = "Please use Build::getenv" },
]
2 changes: 2 additions & 0 deletions dev-tools/cc-test/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]

use std::env;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down
1 change: 1 addition & 0 deletions src/bin/gcc-shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! It is not intended for users and is not published with the library code to crates.io.
#![cfg_attr(test, allow(dead_code))]
#![allow(clippy::disallowed_methods)]

use std::env;
use std::fs::File;
Expand Down
1 change: 1 addition & 0 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) struct CargoOutput {

impl CargoOutput {
pub(crate) fn new() -> Self {
#[allow(clippy::disallowed_methods)]
Self {
metadata: true,
warnings: true,
Expand Down
664 changes: 354 additions & 310 deletions src/lib.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
process::{Command, Stdio},
sync::Mutex,
sync::RwLock,
};

use crate::{
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct Tool {
impl Tool {
pub(crate) fn new(
path: PathBuf,
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
cargo_output: &CargoOutput,
out_dir: Option<&Path>,
) -> Self {
Expand All @@ -57,7 +57,7 @@ impl Tool {
pub(crate) fn with_clang_driver(
path: PathBuf,
clang_driver: Option<&str>,
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
cargo_output: &CargoOutput,
out_dir: Option<&Path>,
) -> Self {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Tool {
path: PathBuf,
clang_driver: Option<&str>,
cuda: bool,
cached_compiler_family: &Mutex<HashMap<Box<Path>, ToolFamily>>,
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
cargo_output: &CargoOutput,
out_dir: Option<&Path>,
) -> Self {
Expand Down Expand Up @@ -186,13 +186,13 @@ impl Tool {
}
}
let detect_family = |path: &Path| -> Result<ToolFamily, Error> {
if let Some(family) = cached_compiler_family.lock().unwrap().get(path) {
if let Some(family) = cached_compiler_family.read().unwrap().get(path) {
return Ok(*family);
}

let family = detect_family_inner(path, cargo_output, out_dir)?;
cached_compiler_family
.lock()
.write()
.unwrap()
.insert(path.into(), family);
Ok(family)
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let len = self.slice.len();
for (index, os_str) in self.slice.into_iter().enumerate() {
for (index, os_str) in self.slice.iter().enumerate() {
// TODO: Use OsStr::display once it is stablised,
// Path and OsStr has the same `Display` impl
write!(f, "{}", Path::new(os_str).display())?;
Expand Down
Loading

0 comments on commit 4cb5b94

Please sign in to comment.