on master help sign in
Fix compilation of library
2e9cf63sharkdp
Cargo.toml+1−1
@@ -48,7 +48,7 @@ encoding = "0.2"
48shell-words = { version = "0.1.0", optional = true }
48shell-words = { version = "0.1.0", optional = true }
49unicode-width = "0.1.7"
49unicode-width = "0.1.7"
50globset = "0.4"
50globset = "0.4"
51−serde = "1.0"
51+serde = { version = "1.0", features = ["derive"] }
52serde_yaml = "0.8"
52serde_yaml = "0.8"
53semver = "0.9"
53semver = "0.9"
54
54
src/assets.rs+2−2
@@ -117,7 +117,7 @@ impl HighlightingAssets {
117 }
117 }
118 }
118 }
119
119
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<()> {
121 let _ = fs::create_dir_all(target_dir);
121 let _ = fs::create_dir_all(target_dir);
122 let theme_set_path = target_dir.join("themes.bin");
122 let theme_set_path = target_dir.join("themes.bin");
123 let syntax_set_path = target_dir.join("syntaxes.bin");
123 let syntax_set_path = target_dir.join("syntaxes.bin");
@@ -150,7 +150,7 @@ impl HighlightingAssets {
150 "Writing metadata to folder {} ... ",
150 "Writing metadata to folder {} ... ",
151 target_dir.to_string_lossy()
151 target_dir.to_string_lossy()
152 );
152 );
153− AssetsMetadata::new().save_to_folder(target_dir)?;
153+ AssetsMetadata::new(current_version).save_to_folder(target_dir)?;
154 println!("okay");
154 println!("okay");
155
155
156 Ok(())
156 Ok(())
src/assets_metadata.rs+4−5
@@ -2,7 +2,6 @@ use std::fs::File;
2use std::path::Path;
2use std::path::Path;
3use std::time::SystemTime;
3use std::time::SystemTime;
4
4
5−use clap::crate_version;
6use semver::Version;
5use semver::Version;
7use serde::{Deserialize, Serialize};
6use serde::{Deserialize, Serialize};
8
7
@@ -17,9 +16,9 @@ pub struct AssetsMetadata {
17const FILENAME: &'static str = "metadata.yaml";
16const FILENAME: &'static str = "metadata.yaml";
18
17
19impl AssetsMetadata {
18impl AssetsMetadata {
20− pub(crate) fn new() -> AssetsMetadata {
19+ pub(crate) fn new(current_version: &str) -> AssetsMetadata {
21 AssetsMetadata {
20 AssetsMetadata {
22− bat_version: Some(crate_version!().into()),
21+ bat_version: Some(current_version.to_owned()),
23 creation_time: Some(SystemTime::now()),
22 creation_time: Some(SystemTime::now()),
24 }
23 }
25 }
24 }
@@ -64,9 +63,9 @@ impl AssetsMetadata {
64 }
63 }
65 }
64 }
66
65
67− pub fn is_compatible(&self) -> bool {
66+ pub fn is_compatible_with(&self, current_version: &str) -> bool {
68 let current_version =
67 let current_version =
69− Version::parse(crate_version!()).expect("bat follows semantic versioning");
68+ Version::parse(current_version).expect("bat follows semantic versioning");
70 let stored_version = self
69 let stored_version = self
71 .bat_version
70 .bat_version
72 .as_ref()
71 .as_ref()
src/bin/bat/assets.rs+1−1
@@ -37,7 +37,7 @@ pub fn clear_assets() {
37pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
37pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
38 let cache_dir = PROJECT_DIRS.cache_dir();
38 let cache_dir = PROJECT_DIRS.cache_dir();
39 if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
39 if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
40− if !metadata.is_compatible() {
40+ if !metadata.is_compatible_with(crate_version!()) {
41 return Err(format!(
41 return Err(format!(
42 "The binary caches for the user-customized syntaxes and themes \
42 "The binary caches for the user-customized syntaxes and themes \
43 in '{}' are not compatible with this version of bat ({}). To solve this, \
43 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::{
22 config::{config_file, generate_config_file},
22 config::{config_file, generate_config_file},
23};
23};
24use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
24use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
25−use bat::Controller;
25+use clap::crate_version;
26use directories::PROJECT_DIRS;
26use directories::PROJECT_DIRS;
27
27
28use bat::{
28use bat::{
29 config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents},
29 config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents},
30 errors::*,
30 errors::*,
31− HighlightingAssets,
31+ Controller, HighlightingAssets,
32};
32};
33
33
34fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
34fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
@@ -45,7 +45,7 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
45 let blank = matches.is_present("blank");
45 let blank = matches.is_present("blank");
46
46
47 let assets = HighlightingAssets::from_files(source_dir, !blank)?;
47 let assets = HighlightingAssets::from_files(source_dir, !blank)?;
48− assets.save_to_cache(target_dir)?;
48+ assets.save_to_cache(target_dir, crate_version!())?;
49 } else if matches.is_present("clear") {
49 } else if matches.is_present("clear") {
50 clear_assets();
50 clear_assets();
51 }
51 }