Skip to content

Commit

Permalink
Fix relative file imports from relative sources with the CLI viewer
Browse files Browse the repository at this point in the history
Calling

    viewer ./examples/printerdemo/ui/printerdemo.60

would fail trying to resolve the relative path import "common.60" from
printerdemo.60, because we would apply the logic for resolving relative
include paths to be relative to the input file *also* for the initial
include path, derived from the main input file. That would result in a
search path

    ./examples/printerdemo/ui/./examples/printerdemo/ui

and that doesn't work :-)

So apply the resolution of relative include paths to be relative to the
input file only to those in the compiler configuration.
  • Loading branch information
tronical committed Nov 12, 2020
1 parent 3cf02e5 commit 2282697
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sixtyfps_compiler/typeloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,20 @@ impl<'a> TypeLoader<'a> {
file_to_import: &str,
) -> Option<OpenFile> {
// The directory of the current file is the first in the list of include directories.
let maybe_current_directory = referencing_file.and_then(|path| path.parent());
let maybe_current_directory =
referencing_file.and_then(|path| path.parent()).map(|p| p.to_path_buf());
maybe_current_directory
.clone()
.into_iter()
.chain(self.compiler_config.include_paths.iter().map(PathBuf::as_path))
.map(|include_path| {
if include_path.is_relative() && maybe_current_directory.is_some() {
maybe_current_directory.unwrap().join(include_path)
} else {
include_path.to_path_buf()
.chain(self.compiler_config.include_paths.iter().map(PathBuf::as_path).map({
|include_path| {
if include_path.is_relative() && maybe_current_directory.as_ref().is_some() {
maybe_current_directory.as_ref().unwrap().join(include_path)
} else {
include_path.to_path_buf()
}
}
})
}))
.find_map(|include_dir| include_dir.try_open(file_to_import))
.or_else(|| self.builtin_library.and_then(|lib| lib.try_open(file_to_import)))
.or_else(|| {
Expand Down

0 comments on commit 2282697

Please sign in to comment.