Skip to content

Commit

Permalink
fix: mod relative path dir read
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Jan 11, 2024
1 parent 4665223 commit 359b311
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
23 changes: 1 addition & 22 deletions kclvm/config/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
//! The real path of `${my_pkg:KCL_MOD}/xxx/main.k` is `/usr/my_pkg/sub/main.k`.
use anyhow::Result;
use pcre2::bytes::Regex;
use std::path::{Path, PathBuf};

use crate::modfile::KCL_FILE_SUFFIX;
use std::path::PathBuf;

#[derive(Clone, Debug, Default)]
/// [`ModRelativePath`] is a path that is relative to the root package path.
Expand Down Expand Up @@ -146,25 +144,6 @@ impl ModRelativePath {
},
))
}

/// [`is_dir`] returns true if the path is a directory.
///
/// # Examples
///
/// ```rust
/// use kclvm_config::path::ModRelativePath;
/// let path = ModRelativePath::new("${name:KCL_MOD}/src/path".to_string());
/// assert_eq!(path.is_dir(), true);
/// let path = ModRelativePath::new("${name:KCL_MOD}/src/path/main.k".to_string());
/// assert_eq!(path.is_dir(), false);
/// ```
pub fn is_dir(&self) -> bool {
if self.path.is_empty() {
false
} else {
Path::new(&self.path).is_dir() || !self.path.ends_with(KCL_FILE_SUFFIX)
}
}
}

#[cfg(test)]
Expand Down
6 changes: 1 addition & 5 deletions kclvm/parser/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,9 @@ pub fn get_compile_entries_from_paths(
}
let mut result = Entries::default();
let mut k_code_queue = VecDeque::from(opts.k_code_list.clone());
for (i, s) in file_paths.iter().enumerate() {
for s in file_paths {
let path = ModRelativePath::from(s.to_string());

if path.is_dir() && opts.k_code_list.len() > i {
return Err(anyhow::anyhow!("Invalid code list with path {}", s));
}

// If the path is a [`ModRelativePath`] with prefix '${<package_name>:KCL_MOD}',
// calculate the real path and the package name.
if let Some((pkg_name, pkg_path)) = path.get_root_pkg_name()?.and_then(|name| {
Expand Down

0 comments on commit 359b311

Please sign in to comment.