From b35c74ea4c9d93d6a8d90812d2066a78b9abb64e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 4 Sep 2018 23:17:38 -0400 Subject: stage1: use os_path_resolve instead of os_path_real to canonicalize imports. This means that softlinks can represent different files, but referencing the same absolute path different ways still references the same import. --- src/ir.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index bbce0af225..1b7bf8aa08 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16131,29 +16131,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi os_path_join(search_dir, import_target_path, &full_path); Buf *import_code = buf_alloc(); - Buf *abs_full_path = buf_alloc(); - int err; - if ((err = os_path_real(&full_path, abs_full_path))) { - if (err == ErrorFileNotFound) { - ir_add_error_node(ira, source_node, - buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); - return ira->codegen->builtin_types.entry_invalid; - } else { - ira->codegen->error_during_imports = true; - ir_add_error_node(ira, source_node, - buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); - return ira->codegen->builtin_types.entry_invalid; - } - } + Buf *resolved_path = buf_alloc(); + + Buf *resolve_paths[] = { &full_path, }; + *resolved_path = os_path_resolve(resolve_paths, 1); - auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path); + auto import_entry = ira->codegen->import_table.maybe_get(resolved_path); if (import_entry) { ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); out_val->data.x_import = import_entry->value; return ira->codegen->builtin_types.entry_namespace; } - if ((err = os_fetch_file_path(abs_full_path, import_code, true))) { + int err; + if ((err = os_fetch_file_path(resolved_path, import_code, true))) { if (err == ErrorFileNotFound) { ir_add_error_node(ira, source_node, buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); @@ -16164,7 +16155,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi return ira->codegen->builtin_types.entry_invalid; } } - ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, abs_full_path, import_code); + ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code); scan_import(ira->codegen, target_import); -- cgit v1.2.3