Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 5e82522

Browse files
Merge pull request #49 from Chia-Network/20220728-gentle-recompile
A more gentle recompile
2 parents 33c63dc + 28bb2ba commit 5e82522

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clvm_tools_rs"
3-
version = "0.1.20"
3+
version = "0.1.21"
44
edition = "2018"
55
authors = ["Art Yerkes <[email protected]>"]
66
description = "tools for working with chialisp language; compiler, repl, python and wasm bindings"

src/classic/clvm_tools/clvmc.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,32 +151,45 @@ pub fn compile_clvm(
151151
&mut result_stream,
152152
)?;
153153

154-
{
155-
let output_path_obj = Path::new(output_path);
156-
let output_dir = output_path_obj
157-
.parent()
158-
.map(|p| Ok(p))
159-
.unwrap_or_else(|| Err("could not get parent of output path"))?;
160-
161-
let mut temp_output_file = NamedTempFile::new_in(output_dir).map_err(|e| {
162-
format!(
163-
"error creating temporary compiler output for {}: {:?}",
164-
input_path, e
165-
)
166-
})?;
167-
168-
let _ = temp_output_file
169-
.write_all(&result_stream.get_value().hex().as_bytes())
170-
.map_err(|_| format!("failed to write to {:?}", temp_output_file.path()))?;
171-
172-
temp_output_file.persist(output_path.clone()).map_err(|e| {
173-
format!(
174-
"error persisting temporary compiler output {}: {:?}",
175-
output_path, e
176-
)
177-
})?;
154+
let output_path_obj = Path::new(output_path);
155+
let output_dir = output_path_obj
156+
.parent()
157+
.map(|p| Ok(p))
158+
.unwrap_or_else(|| Err("could not get parent of output path"))?;
159+
160+
let target_data = result_stream.get_value().hex();
161+
162+
// Try to detect whether we'd put the same output in the output file.
163+
// Don't proceed if true.
164+
if let Ok(prev_content) = fs::read_to_string(output_path.clone()) {
165+
let prev_trimmed = prev_content.trim();
166+
let trimmed = target_data.trim();
167+
if prev_trimmed == trimmed {
168+
// It's the same program, bail regardless.
169+
return Ok(output_path.to_string());
170+
}
178171
}
179-
};
172+
173+
// Make the contents appear atomically so that other test processes
174+
// won't mistake an empty file for intended output.
175+
let mut temp_output_file = NamedTempFile::new_in(output_dir).map_err(|e| {
176+
format!(
177+
"error creating temporary compiler output for {}: {:?}",
178+
input_path, e
179+
)
180+
})?;
181+
182+
let _ = temp_output_file
183+
.write_all(&target_data.as_bytes())
184+
.map_err(|_| format!("failed to write to {:?}", temp_output_file.path()))?;
185+
186+
temp_output_file.persist(output_path.clone()).map_err(|e| {
187+
format!(
188+
"error persisting temporary compiler output {}: {:?}",
189+
output_path, e
190+
)
191+
})?;
192+
}
180193

181194
Ok(output_path.to_string())
182195
}

0 commit comments

Comments
 (0)