Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
license should be from relative dir
  • Loading branch information
gilescope committed Aug 29, 2021
commit daef88a893e72c385946975d054b4a6c1fe26310
2 changes: 1 addition & 1 deletion src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ macro_rules! create_config {
if self.was_set().license_template_path() {
let lt_path = self.license_template_path();
if lt_path.len() > 0 {
match license::load_and_compile_template(&lt_path) {
match license::load_and_compile_template(self.get_ignore(), &lt_path) {
Ok(re) => self.license_template = Some(re),
Err(msg) => eprintln!("Warning for license template file {:?}: {}",
lt_path, msg),
Expand Down
11 changes: 10 additions & 1 deletion src/config/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,16 @@ impl TemplateParser {
}
}

pub(crate) fn load_and_compile_template(path: &str) -> Result<Regex, LicenseError> {
pub(crate) fn load_and_compile_template(base_dir: &str, path: &str) -> Result<Regex, LicenseError> {
let mut path = Path(path);
if path.is_relative() {
// The tempate path needs to be resolved relative to the .rustfmt config file
// rather than whatever dir cargo fmt was run from.
let current = std::env::current_dir().expect("pwd");
std::env::set_current_dir(base_dir);
path = path.canonicalize();
std::env::set_current_dir(current).expect("change pwd");
}
let mut lt_file = File::open(&path)?;
let mut lt_str = String::new();
lt_file.read_to_string(&mut lt_str)?;
Expand Down