Skip to content

Commit

Permalink
chore: skip compare cache when building the document
Browse files Browse the repository at this point in the history
  • Loading branch information
romzhong committed Dec 2, 2024
1 parent fb10eb1 commit 64afba4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
6 changes: 6 additions & 0 deletions float-pigment-css-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ repository.workspace = true
[lib]
proc-macro = true

[features]
skip_compare_cache = []

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
Expand All @@ -24,3 +27,6 @@ rustc-hash = "1.1.0"

[lints]
workspace = true

[profile.release]
doc = { features = ["skip_compare_cache"] }
44 changes: 25 additions & 19 deletions float-pigment-css-macro/src/compatibility_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn file_creator(
name: &str,
extension: &str,
truncate: bool,
write: bool,
) -> std::result::Result<std::fs::File, std::io::Error> {
let mut path_buffer = PathBuf::new();
path_buffer.push(std::env::var("CARGO_MANIFEST_DIR").unwrap());
Expand All @@ -26,7 +27,7 @@ fn file_creator(
let mut options = OpenOptions::new();
let file = options
.read(true)
.write(true)
.write(write)
.truncate(truncate)
.create(true)
.open(&path_buffer);
Expand Down Expand Up @@ -293,7 +294,7 @@ pub(crate) fn compare_enum_cache(
pb.push("publish");
pb.push("enum");
let folder = pb.to_str().unwrap();
let file = file_creator(folder, &enum_name, EXTENSION, false);
let file = file_creator(folder, &enum_name, EXTENSION, false, false);
if let Ok(file) = file {
let mut reader = BufReader::new(&file);
let mut string = String::new();
Expand Down Expand Up @@ -441,14 +442,17 @@ pub(crate) fn compare_enum_cache(
}
}
let next_cache_toml = toml::to_string(&next_cache).unwrap();
let mut file = file_creator("enum", &enum_name, EXTENSION, true).unwrap();
file.write_all(next_cache_toml.as_bytes())
.unwrap_or_else(|_| {
panic!(
"[CompatibilityEnumCheck] {:?}.{:?}: write cache error",
enum_name, EXTENSION
)
});
if !cfg!(feature = "skip_compare_cache") {
let mut file = file_creator("enum", &enum_name, EXTENSION, true, true).unwrap();
file.write_all(next_cache_toml.as_bytes())
.unwrap_or_else(|_| {
panic!(
"[CompatibilityEnumCheck] {:?}.{:?}: write cache error",
enum_name, EXTENSION
)
});
}

Ok(token)
}

Expand Down Expand Up @@ -503,7 +507,7 @@ pub(crate) fn compare_struct_cache(
pb.push("publish");
pb.push("struct");
let folder = pb.to_str().unwrap();
let file = file_creator(folder, &struct_name, EXTENSION, false);
let file = file_creator(folder, &struct_name, EXTENSION, false, false);
if let Ok(file) = file {
let mut reader = BufReader::new(&file);
let mut string = String::new();
Expand Down Expand Up @@ -542,14 +546,16 @@ pub(crate) fn compare_struct_cache(
}
}
let next_cache_toml = toml::to_string(&next_cache).unwrap();
let mut file = file_creator("struct", &struct_name, EXTENSION, true).unwrap();
file.write_all(next_cache_toml.as_bytes())
.unwrap_or_else(|_| {
panic!(
"[CompatibilityStructCheck] {:?}.{:?}: write cache error",
struct_name, EXTENSION
)
});
if !cfg!(feature = "skip_compare_cache") {
let mut file = file_creator("struct", &struct_name, EXTENSION, true, true).unwrap();
file.write_all(next_cache_toml.as_bytes())
.unwrap_or_else(|_| {
panic!(
"[CompatibilityStructCheck] {:?}.{:?}: write cache error",
struct_name, EXTENSION
)
});
}
Ok(token)
}

Expand Down

0 comments on commit 64afba4

Please sign in to comment.