1
0
mirror of https://github.com/sharkdp/bat.git synced 2024-10-05 18:31:06 +01:00

Fix compilation of library

This commit is contained in:
sharkdp 2020-04-21 17:19:07 +02:00 committed by David Peter
parent 886b22e0ee
commit 2e9cf63a5f
5 changed files with 11 additions and 12 deletions

View File

@ -48,7 +48,7 @@ encoding = "0.2"
shell-words = { version = "0.1.0", optional = true } shell-words = { version = "0.1.0", optional = true }
unicode-width = "0.1.7" unicode-width = "0.1.7"
globset = "0.4" globset = "0.4"
serde = "1.0" serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8" serde_yaml = "0.8"
semver = "0.9" semver = "0.9"

View File

@ -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 _ = fs::create_dir_all(target_dir);
let theme_set_path = target_dir.join("themes.bin"); let theme_set_path = target_dir.join("themes.bin");
let syntax_set_path = target_dir.join("syntaxes.bin"); let syntax_set_path = target_dir.join("syntaxes.bin");
@ -150,7 +150,7 @@ impl HighlightingAssets {
"Writing metadata to folder {} ... ", "Writing metadata to folder {} ... ",
target_dir.to_string_lossy() target_dir.to_string_lossy()
); );
AssetsMetadata::new().save_to_folder(target_dir)?; AssetsMetadata::new(current_version).save_to_folder(target_dir)?;
println!("okay"); println!("okay");
Ok(()) Ok(())

View File

@ -2,7 +2,6 @@ use std::fs::File;
use std::path::Path; use std::path::Path;
use std::time::SystemTime; use std::time::SystemTime;
use clap::crate_version;
use semver::Version; use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -17,9 +16,9 @@ pub struct AssetsMetadata {
const FILENAME: &'static str = "metadata.yaml"; const FILENAME: &'static str = "metadata.yaml";
impl AssetsMetadata { impl AssetsMetadata {
pub(crate) fn new() -> AssetsMetadata { pub(crate) fn new(current_version: &str) -> AssetsMetadata {
AssetsMetadata { AssetsMetadata {
bat_version: Some(crate_version!().into()), bat_version: Some(current_version.to_owned()),
creation_time: Some(SystemTime::now()), 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 = 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 let stored_version = self
.bat_version .bat_version
.as_ref() .as_ref()

View File

@ -37,7 +37,7 @@ pub fn clear_assets() {
pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> { pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
let cache_dir = PROJECT_DIRS.cache_dir(); let cache_dir = PROJECT_DIRS.cache_dir();
if let Some(metadata) = AssetsMetadata::load_from_folder(&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!( return Err(format!(
"The binary caches for the user-customized syntaxes and themes \ "The binary caches for the user-customized syntaxes and themes \
in '{}' are not compatible with this version of bat ({}). To solve this, \ in '{}' are not compatible with this version of bat ({}). To solve this, \

View File

@ -22,13 +22,13 @@ use crate::{
config::{config_file, generate_config_file}, config::{config_file, generate_config_file},
}; };
use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir}; 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 directories::PROJECT_DIRS;
use bat::{ use bat::{
config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents}, config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents},
errors::*, errors::*,
HighlightingAssets, Controller, HighlightingAssets,
}; };
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { 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 blank = matches.is_present("blank");
let assets = HighlightingAssets::from_files(source_dir, !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") { } else if matches.is_present("clear") {
clear_assets(); clear_assets();
} }