Skip to content

Commit

Permalink
create helper fn hex_encode and remove hex dependency
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Dec 16, 2023
1 parent 9d49eb7 commit 3ea3c38
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
7 changes: 0 additions & 7 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dependencies = [
"cmake",
"fd-lock",
"filetime",
"hex",
"home",
"ignore",
"junction",
Expand Down Expand Up @@ -313,12 +312,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"

[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"

[[package]]
name = "home"
version = "0.5.4"
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ clap = { version = "4.4.7", default-features = false, features = ["std", "usage"
clap_complete = "4.4.3"
cmake = "0.1.38"
filetime = "0.2"
hex = "0.4"
home = "0.5.4"
ignore = "0.4.10"
libc = "0.2.150"
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::t;
use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
use crate::utils::helpers::hex_encode;
use crate::Config;
use sha2::Digest;
use std::env::consts::EXE_SUFFIX;
Expand Down Expand Up @@ -566,7 +567,7 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<bool> {
if let Ok(current) = fs::read_to_string(&vscode_settings) {
let mut hasher = sha2::Sha256::new();
hasher.update(&current);
let hash = hex::encode(hasher.finalize().as_slice());
let hash = hex_encode(hasher.finalize().as_slice());
if hash == *current_hash {
return Ok(true);
} else if historical_hashes.contains(&hash.as_str()) {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{
use build_helper::ci::CiEnv;
use xz2::bufread::XzDecoder;

use crate::core::build_steps::llvm::detect_llvm_sha;
use crate::core::config::RustfmtMetadata;
use crate::utils::helpers::{check_run, exe, program_out_of_date};
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
use crate::{t, Config};

static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
Expand Down Expand Up @@ -342,7 +342,7 @@ impl Config {
reader.consume(l);
}

let checksum = hex::encode(hasher.finalize().as_slice());
let checksum = hex_encode(hasher.finalize().as_slice());
let verified = checksum == expected;

if !verified {
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use filetime::FileTime;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;
use utils::helpers::hex_encode;

use crate::core::builder;
use crate::core::builder::Kind;
Expand Down Expand Up @@ -1871,7 +1872,7 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
hasher.update(status);
hasher.update(additional_input);

hex::encode(hasher.finalize().as_slice())
hex_encode(hasher.finalize().as_slice())
}

/// Ensures that the behavior dump directory is properly initialized.
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{RUST_ANALYZER_SETTINGS, SETTINGS_HASHES};
use crate::utils::helpers::hex_encode;
use sha2::Digest;

#[test]
fn check_matching_settings_hash() {
let mut hasher = sha2::Sha256::new();
hasher.update(&RUST_ANALYZER_SETTINGS);
let hash = hex::encode(hasher.finalize().as_slice());
let hash = hex_encode(hasher.finalize().as_slice());
assert_eq!(
&hash,
SETTINGS_HASHES.last().unwrap(),
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,11 @@ pub fn add_rustdoc_cargo_linker_args(
cmd.env("RUSTDOCFLAGS", flags);
}
}

/// Converts `T` into a hexadecimal `String`.
pub fn hex_encode<T>(input: T) -> String
where
T: AsRef<[u8]>,
{
input.as_ref().iter().map(|x| format!("{:02x}", x)).collect()
}

0 comments on commit 3ea3c38

Please sign in to comment.