diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-02 10:38:27 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-02 10:38:27 -0500 |
| commit | 67b4de33d2729fdb21337e5a0e05f6273bce23ba (patch) | |
| tree | 2f79dc7eed0d993e82f777b3f90817731c2d5314 /src/ir.cpp | |
| parent | 764205ac13cc340ff6dcce74667c32dafe24e510 (diff) | |
| download | zig-67b4de33d2729fdb21337e5a0e05f6273bce23ba.tar.gz zig-67b4de33d2729fdb21337e5a0e05f6273bce23ba.zip | |
compile error for import outside package path
closes #2024
there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file
and a corresponding build.zig API:
foo.setMainPkgPath(path)
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 7c45a9d588..2452011d79 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17026,6 +17026,18 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio return ir_const_type(ira, &import_instruction->base, import_entry->value); } + if (source_kind == SourceKindNonRoot) { + ZigPackage *cur_scope_pkg = scope_package(import_instruction->base.scope); + Buf *pkg_root_src_dir = &cur_scope_pkg->root_src_dir; + Buf resolved_root_src_dir = os_path_resolve(&pkg_root_src_dir, 1); + if (!buf_starts_with_buf(resolved_path, &resolved_root_src_dir)) { + ir_add_error_node(ira, source_node, + buf_sprintf("import of file outside package path: '%s'", + buf_ptr(import_target_path))); + return ira->codegen->invalid_instruction; + } + } + if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { if (err == ErrorFileNotFound) { ir_add_error_node(ira, source_node, |
