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

chore(stageleft): use same hashing library everywhere #1590

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 2 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions hydroflow_plus/src/deploy/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ pub fn create_graph_trybuild(
}
});

let mut hasher = Sha256::new();
hasher.update(&source);
let hash = format!("{:X}", hasher.finalize())
let hash = format!("{:X}", Sha256::digest(&source))
.chars()
.take(8)
.collect::<String>();
Expand Down
2 changes: 1 addition & 1 deletion stageleft_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ quote = "1.0.35"
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit" ] }
proc-macro2 = "1.0.74"
proc-macro-crate = "1.0.0"
sha256 = "1.0.0"
sha2 = "0.10.0"

[dev-dependencies]
insta = "1.39"
Expand Down
4 changes: 3 additions & 1 deletion stageleft_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use proc_macro2::{Punct, Spacing, Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
use sha2::{Digest, Sha256};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{AngleBracketedGenericArguments, Token, Type};
Expand Down Expand Up @@ -339,7 +340,7 @@ pub fn entry(
.chars()
.filter(|c| c.is_alphanumeric())
.collect::<String>();
let input_hash = "macro_".to_string() + &sha256::digest(input_contents);
let input_hash = "macro_".to_string() + &format!("{:X}", Sha256::digest(input_contents));
let input_hash_ident = syn::Ident::new(&input_hash, Span::call_site());
let input_hash_impl_ident = syn::Ident::new(&(input_hash + "_impl"), Span::call_site());

Expand All @@ -353,6 +354,7 @@ pub fn entry(

#[cfg_attr(not(stageleft_macro), allow(unused))]
#[cfg_attr(not(stageleft_macro), doc(hidden))]
#[allow(non_snake_case)]
pub(crate) fn #input_hash_impl_ident(input: #root::internal::TokenStream) -> #root::internal::TokenStream {
let input_parsed = #root::internal::syn::parse::Parser::parse(
#root::internal::syn::punctuated::Punctuated::<#root::internal::syn::Expr, #root::internal::syn::Token![,]>::parse_terminated,
Expand Down
2 changes: 1 addition & 1 deletion stageleft_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ syn-inline-mod = "0.6.0"
quote = "1.0.35"
syn = { version = "2.0.46", features = [ "parsing", "extra-traits", "visit" ] }
proc-macro2 = "1.0.74"
sha256 = "1.0.0"
sha2 = "0.10.0"
5 changes: 3 additions & 2 deletions stageleft_tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{env, fs};

use proc_macro2::Span;
use quote::ToTokens;
use sha2::{Digest, Sha256};
use syn::visit::Visit;
use syn::visit_mut::VisitMut;
use syn::{parse_quote, UsePath};
Expand Down Expand Up @@ -41,7 +42,7 @@ impl<'a> Visit<'a> for GenMacroVistor {
.chars()
.filter(|c| c.is_alphanumeric())
.collect::<String>();
let contents_hash = sha256::digest(contents);
let contents_hash = format!("{:X}", Sha256::digest(contents));
self.exported_macros
.insert((contents_hash, cur_path.to_token_stream().to_string()));
}
Expand Down Expand Up @@ -72,7 +73,7 @@ pub fn gen_macro(staged_path: &Path, crate_name: &str) {

let proc_macro_wrapper: syn::ItemFn = parse_quote!(
#[proc_macro]
#[expect(unused_qualifications, reason = "generated code")]
#[expect(unused_qualifications, non_snake_case, reason = "generated code")]
pub fn #underscored_path(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStream {
let input = ::stageleft::internal::TokenStream::from(input);
let out = #exported_from_parsed::#underscored_path_impl(input);
Expand Down
Loading