Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Build::getenv instead of env::var* in anywhere that makes sense #1103

Merged
merged 22 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3138001
Optimize `prefix_for_target`
NobodyXu Jun 23, 2024
8a7ccdd
Refactor `envflags`
NobodyXu Jun 23, 2024
90fae8e
Optimize perf: Use `RwLock` instead of `Mutex`
NobodyXu Jun 23, 2024
b1a3027
Use `self.getenv` for `SDKROOT` and in `apple_deployment_version()`
NobodyXu Jun 23, 2024
905a7e3
Optimize `apple_sdk_root``
NobodyXu Jun 23, 2024
bad5c9c
Optimize `apple_deployment_version`
NobodyXu Jun 23, 2024
918a216
Optimize `apple_sdk_root`
NobodyXu Jun 23, 2024
a90e3be
Refactor and optimize `apple_sdk_root_inner`
NobodyXu Jun 23, 2024
a48587b
Use `Build::getenv` in `rustc_wrapper_fallback`
NobodyXu Jun 23, 2024
bdf29f5
Optimize src/lib.rs
NobodyXu Jun 24, 2024
6e485a7
Fix cargo fmt i src/lib.rs
NobodyXu Jun 24, 2024
8d3c02a
Disallow `std::env::var(_os)` using clippy lints
NobodyXu Jun 24, 2024
f122d2d
Update `windows::find_tools` to use geneirc `get_env`
NobodyXu Jun 24, 2024
765dc58
Use `Build::getenv` for `windows_registry::find` used in `Build`
NobodyXu Jun 24, 2024
94733ca
Optimize: Put test_android_clang_compiler_uses_target_arg_internally
NobodyXu Jun 24, 2024
14c8382
FIx clippy lints
NobodyXu Jun 24, 2024
f3aec09
Rm clippy disallowed-methods rules that do not work
NobodyXu Jun 24, 2024
c8a3476
Optimize `windows_registry`: Rm generic parameters
NobodyXu Jun 25, 2024
a468aaa
Put `#[inline(always)]` on very simple/trivial function
NobodyXu Jun 25, 2024
db71e85
Remove generics in `windows_registry`
NobodyXu Jun 25, 2024
8fe16d4
Refactor and optimize `find_vs_version`
NobodyXu Jun 25, 2024
d2df335
Optimize `get_sdk10_dir`: Use `From<Env> for PathBuf`
NobodyXu Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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