Skip to content

Commit

Permalink
fix run dependency bug and upgrade packages (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistonight authored Oct 8, 2024
1 parent 2a32265 commit 77d18f2
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 171 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 0.2.4
- Fixed bug where `run` directives still executed when dependency is not built yet

## 0.2.2
- New `after` directive to specify dependency explicitly

Expand Down
54 changes: 30 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "txtpp"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
description = "A simple-to-use general purpose preprocessor for text files."
repository = "https://github.com/Pistonite/txtpp"
license = "GPL-3.0"
authors = ["Pistonight <terrabyte100k@gmail.com>"]
authors = ["Pistonight <pistonknight@outlook.com>"]
keywords = ["preprocessor", "tool", "template", "macro", "include"]
categories = ["development-tools::build-utils", "template-engine"]
exclude = [
Expand All @@ -17,13 +17,13 @@ exclude = [

[dependencies]
which = "^5.0.0"
error-stack = "^0.3.1"
termcolor = "^1.2.0"
threadpool = "^1.8.1"
error-stack = "0.5.0"
termcolor = "1.4.1"
threadpool = "1.8.1"
clap = { version = "^4.4.7", features = ["cargo", "derive"], optional = true }
log = "^0.4.17"
env_logger = "^0.10.0"
derivative = "^2.2.0"
log = "0.4.22"
env_logger = "0.11.5"
derivative = "2.2.0"

[features]
default = ["cli"]
Expand Down
15 changes: 8 additions & 7 deletions src/core/execute/pp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::{Mode, TagState};
use crate::error::{PpError, PpErrorKind};
use crate::fs::{AbsPath, IOCtx, Shell, TxtppPath};
use error_stack::{IntoReport, Report, Result};
use error_stack::{Report, Result, ResultExt};
use std::path::PathBuf;

mod directive;
Expand Down Expand Up @@ -244,12 +244,9 @@ impl<'a> Pp<'a> {
.attach_printable(format!("could not open include file: `{arg}`"))
})?;
let output = std::fs::read_to_string(&include_file)
.into_report()
.map_err(|e| {
e.change_context(self.context.make_error(PpErrorKind::Directive))
.attach_printable(format!(
"could not read include file: `{include_file}`"
))
.change_context_lazy(|| self.context.make_error(PpErrorKind::Directive))
.attach_printable_lazy(|| {
format!("could not read include file: `{include_file}`")
})?;
log::debug!("include file content: {output:?}");
Some(output)
Expand Down Expand Up @@ -316,6 +313,10 @@ impl<'a> Pp<'a> {
return Ok(None);
}
}
// if we are already collecting deps, don't execute the directive
if let PpMode::CollectDeps(_) = self.pp_mode {
return Ok(None);
}
Ok(Some(d))
}

Expand Down
17 changes: 8 additions & 9 deletions src/core/execute/scan_dir.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use crate::error::PathError;
use crate::fs::{AbsPath, Directory, TxtppPath};
use error_stack::{IntoReport, Result};
use error_stack::{Result, ResultExt};

pub fn scan_dir(dir: &AbsPath, recursive: bool) -> Result<Directory, PathError> {
let dir_path = dir.as_path_buf();
let entries = dir_path.read_dir().into_report().map_err(|e| {
e.change_context(PathError::from(&dir_path))
.attach_printable("failed to read directory")
})?;
let entries = dir_path
.read_dir()
.change_context_lazy(|| PathError::from(&dir_path))
.attach_printable("failed to read directory")?;

let mut directory = Directory::new();

for entry in entries {
let entry = entry.into_report().map_err(|e| {
e.change_context(PathError::from(&dir_path))
.attach_printable("failed to read directory")
})?;
let entry = entry
.change_context_lazy(|| PathError::from(&dir_path))
.attach_printable("failed to read directory entry")?;
let path = entry.path();

if path.is_file() {
Expand Down
Loading

0 comments on commit 77d18f2

Please sign in to comment.