Skip to content

Commit

Permalink
Fix path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Dec 15, 2023
1 parent 8ab9b69 commit d6171de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ void Driver::init() {
* Initialize the cli options based on the input of the user
*/
void Driver::enrich() {
// Make path of given main source file canonical and relative
cliOptions.mainSourceFile = std::filesystem::canonical(cliOptions.mainSourceFile);
cliOptions.mainSourceFile = std::filesystem::path(cliOptions.mainSourceFile);

// Propagate llvm args to llvm
if (!cliOptions.llvmArgs.empty()) {
const std::vector<std::string> result = CommonUtil::split("llvm " + cliOptions.llvmArgs);
Expand Down
4 changes: 3 additions & 1 deletion src/importcollector/ImportCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ std::any ImportCollector::visitImportStmt(ImportStmtNode *node) {
basePath = sourceFile->filePath.parent_path() / node->importPath;
}
basePath.make_preferred();
basePath = std::filesystem::relative(std::filesystem::weakly_canonical(basePath));
basePath = std::filesystem::weakly_canonical(basePath).lexically_relative(std::filesystem::current_path());
if (!basePath.native().starts_with('.'))
basePath = "." / basePath;

// Format: /dir/to/path/file.spice
std::filesystem::path defaultPath = basePath;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Error|Semantic] test-files/typechecker/imports/error-circular-import/source2.spice:1:1:
[Error|Semantic] ./test-files/typechecker/imports/error-circular-import/source2.spice:1:1:
Circular import detected: Circular import detected while importing 'source.spice'

1 import "source" as s;
Expand Down

0 comments on commit d6171de

Please sign in to comment.