File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -390,7 +390,7 @@ macro_rules! create_config {
390
390
if self . was_set( ) . license_template_path( ) {
391
391
let lt_path = self . license_template_path( ) ;
392
392
if lt_path. len( ) > 0 {
393
- match license:: load_and_compile_template( & lt_path) {
393
+ match license:: load_and_compile_template( self . get_ignore ( ) , & lt_path) {
394
394
Ok ( re) => self . license_template = Some ( re) ,
395
395
Err ( msg) => eprintln!( "Warning for license template file {:?}: {}" ,
396
396
lt_path, msg) ,
Original file line number Diff line number Diff line change @@ -211,7 +211,16 @@ impl TemplateParser {
211
211
}
212
212
}
213
213
214
- pub ( crate ) fn load_and_compile_template ( path : & str ) -> Result < Regex , LicenseError > {
214
+ pub ( crate ) fn load_and_compile_template ( base_dir : & str , path : & str ) -> Result < Regex , LicenseError > {
215
+ let mut path = Path ( path) ;
216
+ if path. is_relative ( ) {
217
+ // The tempate path needs to be resolved relative to the .rustfmt config file
218
+ // rather than whatever dir cargo fmt was run from.
219
+ let current = std:: env:: current_dir ( ) . expect ( "pwd" ) ;
220
+ std:: env:: set_current_dir ( base_dir) ;
221
+ path = path. canonicalize ( ) ;
222
+ std:: env:: set_current_dir ( current) . expect ( "change pwd" ) ;
223
+ }
215
224
let mut lt_file = File :: open ( & path) ?;
216
225
let mut lt_str = String :: new ( ) ;
217
226
lt_file. read_to_string ( & mut lt_str) ?;
You can’t perform that action at this time.
0 commit comments