on master help sign in
Fix compilation of library
commit2e9cf63a5fd63bd5bcf16cfce67b5999042b89cb authorsharkdp <davidpeter@web.de> dateTue 21 Apr 2020, 17:19 (7 years ago) parent886b22e
5 files changed+11−12
Cargo.toml+1−1 src/assets.rs+2−2 src/assets_metadata.rs+4−5 src/bin/bat/assets.rs+1−1 src/bin/bat/main.rs+3−3
Cargo.toml+1−1
@@ -48,7 +48,7 @@ encoding = "0.2"
4848shell-words = { version = "0.1.0", optional = true }
4949unicode-width = "0.1.7"
5050globset = "0.4"
51−serde = "1.0"
51+serde = { version = "1.0", features = ["derive"] }
5252serde_yaml = "0.8"
5353semver = "0.9"
5454
src/assets.rs+2−2
@@ -117,7 +117,7 @@ impl HighlightingAssets {
117117 }
118118 }
119119
120− pub fn save_to_cache(&self, target_dir: &Path) -> Result<()> {
120+ pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {
121121 let _ = fs::create_dir_all(target_dir);
122122 let theme_set_path = target_dir.join("themes.bin");
123123 let syntax_set_path = target_dir.join("syntaxes.bin");
@@ -150,7 +150,7 @@ impl HighlightingAssets {
150150 "Writing metadata to folder {} ... ",
151151 target_dir.to_string_lossy()
152152 );
153− AssetsMetadata::new().save_to_folder(target_dir)?;
153+ AssetsMetadata::new(current_version).save_to_folder(target_dir)?;
154154 println!("okay");
155155
156156 Ok(())
src/assets_metadata.rs+4−5
@@ -2,7 +2,6 @@ use std::fs::File;
22use std::path::Path;
33use std::time::SystemTime;
44
5−use clap::crate_version;
65use semver::Version;
76use serde::{Deserialize, Serialize};
87
@@ -17,9 +16,9 @@ pub struct AssetsMetadata {
1716const FILENAME: &'static str = "metadata.yaml";
1817
1918impl AssetsMetadata {
20− pub(crate) fn new() -> AssetsMetadata {
19+ pub(crate) fn new(current_version: &str) -> AssetsMetadata {
2120 AssetsMetadata {
22− bat_version: Some(crate_version!().into()),
21+ bat_version: Some(current_version.to_owned()),
2322 creation_time: Some(SystemTime::now()),
2423 }
2524 }
@@ -64,9 +63,9 @@ impl AssetsMetadata {
6463 }
6564 }
6665
67− pub fn is_compatible(&self) -> bool {
66+ pub fn is_compatible_with(&self, current_version: &str) -> bool {
6867 let current_version =
69− Version::parse(crate_version!()).expect("bat follows semantic versioning");
68+ Version::parse(current_version).expect("bat follows semantic versioning");
7069 let stored_version = self
7170 .bat_version
7271 .as_ref()
src/bin/bat/assets.rs+1−1
@@ -37,7 +37,7 @@ pub fn clear_assets() {
3737pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
3838 let cache_dir = PROJECT_DIRS.cache_dir();
3939 if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
40− if !metadata.is_compatible() {
40+ if !metadata.is_compatible_with(crate_version!()) {
4141 return Err(format!(
4242 "The binary caches for the user-customized syntaxes and themes \
4343 in '{}' are not compatible with this version of bat ({}). To solve this, \
src/bin/bat/main.rs+3−3
@@ -22,13 +22,13 @@ use crate::{
2222 config::{config_file, generate_config_file},
2323};
2424use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
25−use bat::Controller;
25+use clap::crate_version;
2626use directories::PROJECT_DIRS;
2727
2828use bat::{
2929 config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents},
3030 errors::*,
31− HighlightingAssets,
31+ Controller, HighlightingAssets,
3232};
3333
3434fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
@@ -45,7 +45,7 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
4545 let blank = matches.is_present("blank");
4646
4747 let assets = HighlightingAssets::from_files(source_dir, !blank)?;
48− assets.save_to_cache(target_dir)?;
48+ assets.save_to_cache(target_dir, crate_version!())?;
4949 } else if matches.is_present("clear") {
5050 clear_assets();
5151 }