Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Dec 18, 2024
1 parent 1609eea commit 74f2cae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/paralegal-spdg/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn get_rustup_lib_path() -> PathBuf {
rustup_lib
}

/// Helper for calculating a hash of all (modification dates of) Rust files in this crate.
fn visit_dirs(dir: &Path, hasher: &mut DefaultHasher) -> Result<()> {
if !dir.is_dir() {
return Ok(());
Expand All @@ -31,11 +32,9 @@ fn visit_dirs(dir: &Path, hasher: &mut DefaultHasher) -> Result<()> {
if path.is_dir() {
visit_dirs(&path, hasher)?;
} else if path.extension().map_or(false, |ext| ext == "rs") {
// Get the modification time
let metadata = entry.metadata()?;
let modified = metadata.modified()?;

// Convert SystemTime to duration since UNIX_EPOCH
let duration = modified.duration_since(SystemTime::UNIX_EPOCH)?;
duration.as_secs().hash(hasher);
// Tell Cargo to rerun if this source file changes
Expand All @@ -45,6 +44,7 @@ fn visit_dirs(dir: &Path, hasher: &mut DefaultHasher) -> Result<()> {
Ok(())
}

/// Calculate a hash of all (modification dates of) Rust files in this crate.
fn calculate_source_hash() -> u64 {
let mut hasher = DefaultHasher::new();

Expand All @@ -57,7 +57,6 @@ fn calculate_source_hash() -> u64 {
}

fn main() {
// Calculate the hash of modification times
let magic = calculate_source_hash();

// Emit the hash as an environment variable
Expand Down
3 changes: 3 additions & 0 deletions crates/paralegal-spdg/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ cfg_if! {
}
}

/// A magic hash number used to verify version compatibility of output
/// artifacts. Used in reading and writing the [`ProgramDescription`] See
/// build.rs for how this number is created.
fn ser_magic() -> u64 {
const SER_MAGIC: &str = env!("SER_MAGIC");
SER_MAGIC.parse().unwrap()
Expand Down

0 comments on commit 74f2cae

Please sign in to comment.