From 2e9cf63a5fd63bd5bcf16cfce67b5999042b89cb Mon Sep 17 00:00:00 2001 From: sharkdp Date: Tue, 21 Apr 2020 17:19:07 +0200 Subject: [PATCH] Fix compilation of library --- Cargo.toml | 2 +- src/assets.rs | 4 ++-- src/assets_metadata.rs | 9 ++++----- src/bin/bat/assets.rs | 2 +- src/bin/bat/main.rs | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c800a2da..030cb93a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ encoding = "0.2" shell-words = { version = "0.1.0", optional = true } unicode-width = "0.1.7" globset = "0.4" -serde = "1.0" +serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.8" semver = "0.9" diff --git a/src/assets.rs b/src/assets.rs index c75641de..f5bb7c4e 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -117,7 +117,7 @@ impl HighlightingAssets { } } - pub fn save_to_cache(&self, target_dir: &Path) -> Result<()> { + pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> { let _ = fs::create_dir_all(target_dir); let theme_set_path = target_dir.join("themes.bin"); let syntax_set_path = target_dir.join("syntaxes.bin"); @@ -150,7 +150,7 @@ impl HighlightingAssets { "Writing metadata to folder {} ... ", target_dir.to_string_lossy() ); - AssetsMetadata::new().save_to_folder(target_dir)?; + AssetsMetadata::new(current_version).save_to_folder(target_dir)?; println!("okay"); Ok(()) diff --git a/src/assets_metadata.rs b/src/assets_metadata.rs index ca5443c3..d4aaaea1 100644 --- a/src/assets_metadata.rs +++ b/src/assets_metadata.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::path::Path; use std::time::SystemTime; -use clap::crate_version; use semver::Version; use serde::{Deserialize, Serialize}; @@ -17,9 +16,9 @@ pub struct AssetsMetadata { const FILENAME: &'static str = "metadata.yaml"; impl AssetsMetadata { - pub(crate) fn new() -> AssetsMetadata { + pub(crate) fn new(current_version: &str) -> AssetsMetadata { AssetsMetadata { - bat_version: Some(crate_version!().into()), + bat_version: Some(current_version.to_owned()), creation_time: Some(SystemTime::now()), } } @@ -64,9 +63,9 @@ impl AssetsMetadata { } } - pub fn is_compatible(&self) -> bool { + pub fn is_compatible_with(&self, current_version: &str) -> bool { let current_version = - Version::parse(crate_version!()).expect("bat follows semantic versioning"); + Version::parse(current_version).expect("bat follows semantic versioning"); let stored_version = self .bat_version .as_ref() diff --git a/src/bin/bat/assets.rs b/src/bin/bat/assets.rs index 5d15ba1c..bfb3c178 100644 --- a/src/bin/bat/assets.rs +++ b/src/bin/bat/assets.rs @@ -37,7 +37,7 @@ pub fn clear_assets() { pub fn assets_from_cache_or_binary() -> Result { let cache_dir = PROJECT_DIRS.cache_dir(); if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? { - if !metadata.is_compatible() { + if !metadata.is_compatible_with(crate_version!()) { return Err(format!( "The binary caches for the user-customized syntaxes and themes \ in '{}' are not compatible with this version of bat ({}). To solve this, \ diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index ebd13a18..3b59b896 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -22,13 +22,13 @@ use crate::{ config::{config_file, generate_config_file}, }; use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir}; -use bat::Controller; +use clap::crate_version; use directories::PROJECT_DIRS; use bat::{ config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents}, errors::*, - HighlightingAssets, + Controller, HighlightingAssets, }; fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { @@ -45,7 +45,7 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { let blank = matches.is_present("blank"); let assets = HighlightingAssets::from_files(source_dir, !blank)?; - assets.save_to_cache(target_dir)?; + assets.save_to_cache(target_dir, crate_version!())?; } else if matches.is_present("clear") { clear_assets(); }