authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 19:16:24-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 19:16:24-04:00
logff477361b005f059591e92e079d62e68153365e1
tree8b3edf357fa9b73d824753ba9ebebee158e9e8b2
parent0a0c11685fd8faf73392d88dbdee7c744cc83386
parent69c7c5de09e16e96a6ea5207ef8b3a21e9d119f9
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'emekoi-root-import'


3 files changed, 15 insertions(+), 7 deletions(-)

src/all_types.hpp+2
......@@ -1110,6 +1110,8 @@ struct ZigPackage {
11101110
11111111 // reminder: hash tables must be initialized before use
11121112 HashMap<Buf *, ZigPackage *, buf_hash, buf_eql_buf> package_table;
1113
1114 bool added_to_cache;
11131115};
11141116
11151117// Stuff that only applies to a struct which is the implicit root struct of a file
src/codegen.cpp+11-4
......@@ -180,6 +180,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
180180 g->root_package = new_package(".", "", "");
181181 }
182182
183 g->root_package->package_table.put(buf_create_from_str("root"), g->root_package);
184
183185 g->zig_std_special_dir = buf_alloc();
184186 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);
185187
......@@ -8053,6 +8055,8 @@ static Error define_builtin_compile_vars(CodeGen *g) {
80538055 g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
80548056 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
80558057 g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);
8058 g->std_package->package_table.put(buf_create_from_str("root"),
8059 g->is_test_build ? g->test_runner_package : g->root_package);
80568060 g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,
80578061 SourceKindPkgMain);
80588062
......@@ -8522,7 +8526,7 @@ static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *ba
85228526
85238527static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {
85248528 ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig", "std.special");
8525 package->package_table.put(buf_create_from_str("@root"), pkg_with_main);
8529 package->package_table.put(buf_create_from_str("root"), pkg_with_main);
85268530 return package;
85278531}
85288532
......@@ -9375,6 +9379,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
93759379static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
93769380 if (buf_len(&pkg->root_src_path) == 0)
93779381 return;
9382 pkg->added_to_cache = true;
93789383
93799384 Buf *rel_full_path = buf_alloc();
93809385 os_path_join(&pkg->root_src_dir, &pkg->root_src_path, rel_full_path);
......@@ -9386,9 +9391,7 @@ static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
93869391 if (!entry)
93879392 break;
93889393
9389 // TODO: I think we need a more sophisticated detection of
9390 // packages we have already seen
9391 if (entry->value != pkg) {
9394 if (!pkg->added_to_cache) {
93929395 cache_buf(ch, entry->key);
93939396 add_cache_pkg(g, ch, entry->value);
93949397 }
......@@ -9645,6 +9648,10 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c
96459648 if (g->std_package != nullptr) {
96469649 assert(g->compile_var_package != nullptr);
96479650 pkg->package_table.put(buf_create_from_str("std"), g->std_package);
9651
9652 ZigPackage *main_pkg = g->is_test_build ? g->test_runner_package : g->root_package;
9653 pkg->package_table.put(buf_create_from_str("root"), main_pkg);
9654
96489655 pkg->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
96499656 }
96509657 return pkg;
std/special/bootstrap.zig+2-3
......@@ -1,7 +1,6 @@
1// This file is in a package which has the root source file exposed as "@root".
2// It is included in the compilation unit when exporting an executable.
1// This file is included in the compilation unit when exporting an executable.
32
4const root = @import("@root");
3const root = @import("root");
54const std = @import("std");
65const builtin = @import("builtin");
76const assert = std.debug.assert;