Update cargo-px generator to avoid unnecessary regeneration

korrat
May 10, 2023, 6:01 PM
WDTZGPLRXG3N6UGLUQQUZ7V2ZSWD3J5RBIZNXL6AOTVKSRXRCT2AC

Dependencies

  • [2] 6MR76MLL Replace build script with cargo-px
  • [3] ONRIF4V7 add basic snapshot test for pretty printer
  • [4] 5S4MZHL5 pretty print decimals using icu
  • [5] UESS5YZE migrate dependencies into workspace manifest
  • [6] KBSTC23N Clean up testing using new builder methods on types
  • [*] QRIJE4AQ add a simple pretty printer for beancount directives
  • [*] I2P2FTLE add basic parser for german decimals

Change contents

  • edit in generators/src/bin/icu-data.rs at line 2
    [2.118]
    [2.118]
    use std::fs;
  • edit in generators/src/bin/icu-data.rs at line 4
    [2.119]
    [2.119]
    use camino::Utf8Path;
    use camino::Utf8PathBuf;
  • edit in generators/src/bin/icu-data.rs at line 15
    [2.401]
    [2.401]
    let current_checksum = compute_checksum();
    let manifest_path = Utf8PathBuf::try_from(cargo_px_env::generated_pkg_manifest_path()?)?;
    let mut manifest = load_manifest(&manifest_path)?;
    let old_checksum = &mut manifest["package"]["metadata"]["px"]["source"]["checksum"];
    if let Some(old_checksum) = old_checksum.as_str() {
    if old_checksum == current_checksum {
    return Ok(());
    }
    }
  • replacement in generators/src/bin/icu-data.rs at line 33
    [2.637][2.637:836]()
    let mut package_path = cargo_px_env::generated_pkg_manifest_path()?;
    package_path.pop();
    package_path.push("src");
    package_path.push("icu_data");
    package_path
    [2.637]
    [2.836]
    let mut path = manifest_path.clone();
    path.pop();
    path.push("src");
    path.push("icu_data");
    path.canonicalize()?
  • edit in generators/src/bin/icu-data.rs at line 61
    [2.1264]
    [2.1264]
    // Update checksum
    *old_checksum = toml_edit::value(current_checksum);
    save_manifest(&manifest_path, manifest)?;
  • edit in generators/src/bin/icu-data.rs at line 67
    [2.1275]
    [2.1275]
    }
    fn save_manifest(path: &Utf8Path, manifest: toml_edit::Document) -> Result<(), std::io::Error> {
    fs::write(path, manifest.to_string())
    }
    fn load_manifest(path: &Utf8Path) -> Result<toml_edit::Document, toml_edit::TomlError> {
    // Read the contents of the Cargo.toml file
    let toml_content = fs::read_to_string(path).expect("Failed to read Cargo.toml");
    // Parse it
    toml_content.parse::<toml_edit::Document>()
    }
    fn compute_checksum() -> String {
    let version_tag = format!(
    "{}:{}",
    SourceData::LATEST_TESTED_CLDR_TAG,
    SourceData::LATEST_TESTED_ICUEXPORT_TAG
    );
    let current_checksum = xxhash_rust::xxh3::xxh3_128(version_tag.as_bytes());
    format!("{current_checksum:x}")
  • edit in generators/Cargo.toml at line 19
    [2.1723]
    toml_edit.workspace = true
    xxhash-rust.workspace = true
  • edit in common/beancount-pretty-printer/Cargo.toml at line 9
    [8.5244]
    [8.5244]
    [package.metadata.px.generate]
    # The generator is a binary in the current workspace.
    # It's the only generator type we support at the moment.
    generator_type = "cargo_workspace_binary"
    # The name of the binary.
    generator_name = "icu-data"
    [package.metadata.px.source]
    checksum = "396f9a15499d1e3de0eb8765ab1e3ce"
  • edit in common/beancount-pretty-printer/Cargo.toml at line 43
    [2.2348][3.874:875](),[3.2286][3.874:875](),[3.875][2.2349:2588]()
    [package.metadata.px.generate]
    # The generator is a binary in the current workspace.
    # It's the only generator type we support at the moment.
    generator_type = "cargo_workspace_binary"
    # The name of the binary.
    generator_name = "icu-data"
  • edit in Cargo.toml at line 49
    [2.3762]
    [2.3762]
    toml_edit = "0.19.8"