| ... | @@ -49,6 +49,14 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -49,6 +49,14 @@ pub fn execute(args: [][]u8) !void { |
| 49 | \\} | 49 | \\} |
| 50 | }); | 50 | }); |
| 51 | try w.print("\n", .{}); | 51 | try w.print("\n", .{}); |
| | 52 | try w.print("pub const _ids = {}\n", .{".{"}); |
| | 53 | try print_ids(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| | 54 | try w.print("{}\n", .{"};"}); |
| | 55 | try w.print("\n", .{}); |
| | 56 | try w.print("pub const _paths = {}\n", .{".{"}); |
| | 57 | try print_paths(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| | 58 | try w.print("{}\n", .{"};"}); |
| | 59 | try w.print("\n", .{}); |
| 52 | try w.print("pub const packages = ", .{}); | 60 | try w.print("pub const packages = ", .{}); |
| 53 | try print_deps(w, dir, top_module, 0, true); | 61 | try print_deps(w, dir, top_module, 0, true); |
| 54 | try w.print(";\n", .{}); | 62 | try w.print(";\n", .{}); |
| ... | @@ -162,6 +170,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -162,6 +170,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 162 | .system_lib => { | 170 | .system_lib => { |
| 163 | if (d.is_for_this()) try moduledeps.append(u.Module{ | 171 | if (d.is_for_this()) try moduledeps.append(u.Module{ |
| 164 | .is_sys_lib = true, | 172 | .is_sys_lib = true, |
| | 173 | .id = "", |
| 165 | .name = d.path, | 174 | .name = d.path, |
| 166 | .only_os = d.only_os, | 175 | .only_os = d.only_os, |
| 167 | .except_os = d.except_os, | 176 | .except_os = d.except_os, |
| ... | @@ -178,6 +187,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -178,6 +187,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 178 | error.FileNotFound => { | 187 | error.FileNotFound => { |
| 179 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 188 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 180 | var mod_from = try u.Module.from(d); | 189 | var mod_from = try u.Module.from(d); |
| | 190 | mod_from.id = try u.random_string(48); |
| 181 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; | 191 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 182 | if (mod_from.is_for_this()) try moduledeps.append(mod_from); | 192 | if (mod_from.is_for_this()) try moduledeps.append(mod_from); |
| 183 | } | 193 | } |
| ... | @@ -187,6 +197,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -187,6 +197,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 187 | }; | 197 | }; |
| 188 | dd.clean_path = u.trim_prefix(moddir, dir)[1..]; | 198 | dd.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 189 | | 199 | |
| | 200 | if (dd.id.len == 0) dd.id = try u.random_string(48); |
| 190 | if (d.name.len > 0) dd.name = d.name; | 201 | if (d.name.len > 0) dd.name = d.name; |
| 191 | if (d.main.len > 0) dd.main = d.main; | 202 | if (d.main.len > 0) dd.main = d.main; |
| 192 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; | 203 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; |
| ... | @@ -201,6 +212,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -201,6 +212,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 201 | } | 212 | } |
| 202 | return u.Module{ | 213 | return u.Module{ |
| 203 | .is_sys_lib = false, | 214 | .is_sys_lib = false, |
| | 215 | .id = m.id, |
| 204 | .name = m.name, | 216 | .name = m.name, |
| 205 | .main = m.main, | 217 | .main = m.main, |
| 206 | .c_include_dirs = m.c_include_dirs, | 218 | .c_include_dirs = m.c_include_dirs, |
| ... | @@ -213,6 +225,43 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -213,6 +225,43 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 213 | }; | 225 | }; |
| 214 | } | 226 | } |
| 215 | | 227 | |
| | 228 | fn print_ids(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void { |
| | 229 | if (u.list_contains(list.items, mod.clean_path)) { |
| | 230 | return; |
| | 231 | } |
| | 232 | try list.append(mod.clean_path); |
| | 233 | // |
| | 234 | if (mod.clean_path.len == 0) { |
| | 235 | try w.print(" \"\",\n", .{}); |
| | 236 | } else { |
| | 237 | try w.print(" \"{}\",\n", .{mod.id}); |
| | 238 | } |
| | 239 | // |
| | 240 | for (mod.deps) |d| { |
| | 241 | if (d.is_sys_lib) continue; |
| | 242 | try print_ids(w, d, list); |
| | 243 | } |
| | 244 | } |
| | 245 | |
| | 246 | fn print_paths(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void { |
| | 247 | if (u.list_contains(list.items, mod.clean_path)) { |
| | 248 | return; |
| | 249 | } |
| | 250 | try list.append(mod.clean_path); |
| | 251 | // |
| | 252 | if (mod.clean_path.len == 0) { |
| | 253 | try w.print(" \"\",\n", .{}); |
| | 254 | } else { |
| | 255 | const s = std.fs.path.sep_str; |
| | 256 | try w.print(" \"{Z}{Z}{Z}\",\n", .{s, mod.clean_path, s}); |
| | 257 | } |
| | 258 | // |
| | 259 | for (mod.deps) |d| { |
| | 260 | if (d.is_sys_lib) continue; |
| | 261 | try print_paths(w, d, list); |
| | 262 | } |
| | 263 | } |
| | 264 | |
| 216 | fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) anyerror!void { | 265 | fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) anyerror!void { |
| 217 | if (m.deps.len == 0 and tabs > 0) { | 266 | if (m.deps.len == 0 and tabs > 0) { |
| 218 | try w.print("null", .{}); | 267 | try w.print("null", .{}); |
| ... | @@ -253,9 +302,9 @@ fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c | ... | @@ -253,9 +302,9 @@ fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 253 | try list.append(mod.clean_path); | 302 | try list.append(mod.clean_path); |
| 254 | for (mod.c_include_dirs) |it| { | 303 | for (mod.c_include_dirs) |it| { |
| 255 | if (!local) { | 304 | if (!local) { |
| 256 | try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it}); | 305 | try w.print(" cache ++ _paths[{}] ++ \"{Z}\",\n", .{list.items.len-1, it}); |
| 257 | } else { | 306 | } else { |
| 258 | try w.print(" \".{}/{}\",\n", .{mod.clean_path, it}); | 307 | // try w.print(" ,\n", .{mod.clean_path, it}); |
| 259 | } | 308 | } |
| 260 | } | 309 | } |
| 261 | for (mod.deps) |d| { | 310 | for (mod.deps) |d| { |
| ... | @@ -271,9 +320,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c | ... | @@ -271,9 +320,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 271 | try list.append(mod.clean_path); | 320 | try list.append(mod.clean_path); |
| 272 | for (mod.c_source_files) |it| { | 321 | for (mod.c_source_files) |it| { |
| 273 | if (!local) { | 322 | if (!local) { |
| 274 | try w.print(" {}comptime get_flags({}), cache ++ \"/{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); | 323 | try w.print(" {}_ids[{}], cache ++ _paths[{}] ++ \"{}\"{},\n", .{"[_][]const u8{", list.items.len-1, list.items.len-1, it, "}"}); |
| 275 | } else { | 324 | } else { |
| 276 | try w.print(" {}comptime get_flags({}), \".{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); | 325 | try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); |
| 277 | } | 326 | } |
| 278 | } | 327 | } |
| 279 | for (mod.deps) |d| { | 328 | for (mod.deps) |d| { |
| ... | @@ -291,7 +340,7 @@ fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([] | ... | @@ -291,7 +340,7 @@ fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([] |
| 291 | try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"}); | 340 | try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"}); |
| 292 | } | 341 | } |
| 293 | else { | 342 | else { |
| 294 | try w.print(" pub const @\"{}\" = {}", .{mod.clean_path, "&[_][]const u8{"}); | 343 | try w.print(" pub const @\"{}\" = {}", .{mod.id, "&[_][]const u8{"}); |
| 295 | for (mod.c_source_flags) |it| { | 344 | for (mod.c_source_flags) |it| { |
| 296 | try w.print("\"{Z}\",", .{it}); | 345 | try w.print("\"{Z}\",", .{it}); |
| 297 | } | 346 | } |