| author | |
| committer | |
| log | 779b6cc63cbf1ab0f132996506a238eae72dcbf9 |
| tree | e42c3573b14e21ceec05c9360d63dc9325a60a0e |
| parent | fc7924d393c909fef785614b8273e719398db2c1 |
progress towards #354737 files changed, 78 insertions(+), 34 deletions(-)
build.zig+1-1| ... | ... | @@ -268,7 +268,7 @@ pub fn build(b: *std.Build) !void { |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Ensure git version changes get picked up. |
| 271 | b.dependOnFileContents(b.graph.path(.build_root, ".git/HEAD")); | |
| 271 | b.dependOnFileContents(b.path(".git/HEAD")); | |
| 272 | 272 | |
| 273 | 273 | const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch }); |
| 274 | 274 |
lib/compiler/Maker.zig+50-11| ... | ... | @@ -1318,7 +1318,11 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | 1320 | for (configuration.path_deps) |path_dep| { |
| 1321 | try config_man.addPathPost(path_dep.toCachePath(&configuration, arena)); | |
| 1321 | switch (path_dep.flags.mode) { | |
| 1322 | .directory => {}, // TODO | |
| 1323 | .contents => try config_man.addPathPost(confPathDepToCachePath(graph, &configuration, path_dep)), | |
| 1324 | .metadata => {}, // TODO | |
| 1325 | } | |
| 1322 | 1326 | } |
| 1323 | 1327 | |
| 1324 | 1328 | // If it is poisoned, there is no point in moving it to cached |
| ... | ... | @@ -1825,7 +1829,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 1825 | 1829 | return process.cleanExit(io); |
| 1826 | 1830 | }, |
| 1827 | 1831 | .minimal => { |
| 1828 | writeSimpleTemplateFile(io, Package.Manifest.basename, | |
| 1832 | Templates.writeSimpleFile(io, Package.Manifest.basename, | |
| 1829 | 1833 | \\.{{ |
| 1830 | 1834 | \\ .name = .{s}, |
| 1831 | 1835 | \\ .version = "0.0.1", |
| ... | ... | @@ -1842,7 +1846,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 1842 | 1846 | else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }), |
| 1843 | 1847 | error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}), |
| 1844 | 1848 | }; |
| 1845 | writeSimpleTemplateFile(io, default_build_zig_basename, | |
| 1849 | Templates.writeSimpleFile(io, default_build_zig_basename, | |
| 1846 | 1850 | \\const std = @import("std"); |
| 1847 | 1851 | \\ |
| 1848 | 1852 | \\pub fn build(b: *std.Build) void {{ |
| ... | ... | @@ -3498,7 +3502,7 @@ fn loadManifest( |
| 3498 | 3502 | 0, |
| 3499 | 3503 | ) catch |err| switch (err) { |
| 3500 | 3504 | error.FileNotFound => { |
| 3501 | writeSimpleTemplateFile(io, Package.Manifest.basename, | |
| 3505 | Templates.writeSimpleFile(io, Package.Manifest.basename, | |
| 3502 | 3506 | \\.{{ |
| 3503 | 3507 | \\ .name = .{s}, |
| 3504 | 3508 | \\ .version = "{s}", |
| ... | ... | @@ -3658,12 +3662,47 @@ const Templates = struct { |
| 3658 | 3662 | .buffer = std.array_list.Managed(u8).init(gpa), |
| 3659 | 3663 | }; |
| 3660 | 3664 | } |
| 3665 | ||
| 3666 | fn writeSimpleFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void { | |
| 3667 | const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true }); | |
| 3668 | defer f.close(io); | |
| 3669 | var buf: [4096]u8 = undefined; | |
| 3670 | var fw = f.writer(io, &buf); | |
| 3671 | try fw.interface.print(format, args); | |
| 3672 | try fw.interface.flush(); | |
| 3673 | } | |
| 3661 | 3674 | }; |
| 3662 | fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void { | |
| 3663 | const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true }); | |
| 3664 | defer f.close(io); | |
| 3665 | var buf: [4096]u8 = undefined; | |
| 3666 | var fw = f.writer(io, &buf); | |
| 3667 | try fw.interface.print(format, args); | |
| 3668 | try fw.interface.flush(); | |
| 3675 | ||
| 3676 | fn confPathDepToCachePath(graph: *const Graph, c: *const Configuration, path_dep: Configuration.PathDep) Path { | |
| 3677 | const sub_path = path_dep.sub.slice(c); | |
| 3678 | return switch (path_dep.flags.base) { | |
| 3679 | .cwd => .{ | |
| 3680 | .root_dir = .cwd(), | |
| 3681 | .sub_path = sub_path, | |
| 3682 | }, | |
| 3683 | .local_cache => .{ | |
| 3684 | .root_dir = graph.local_cache_root, | |
| 3685 | .sub_path = sub_path, | |
| 3686 | }, | |
| 3687 | .global_cache => .{ | |
| 3688 | .root_dir = graph.global_cache_root, | |
| 3689 | .sub_path = sub_path, | |
| 3690 | }, | |
| 3691 | .build_root => .{ | |
| 3692 | .root_dir = switch (path_dep.pkg.unwrap().?) { | |
| 3693 | .root => graph.build_root_directory, | |
| 3694 | _ => @panic("TODO"), | |
| 3695 | }, | |
| 3696 | .sub_path = sub_path, | |
| 3697 | }, | |
| 3698 | .zig_lib => .{ | |
| 3699 | .root_dir = graph.zig_lib_directory, | |
| 3700 | .sub_path = sub_path, | |
| 3701 | }, | |
| 3702 | .zig_exe => @panic("TODO"), | |
| 3703 | .install_prefix => @panic("TODO"), | |
| 3704 | .install_lib => @panic("TODO"), | |
| 3705 | .install_bin => @panic("TODO"), | |
| 3706 | .install_include => @panic("TODO"), | |
| 3707 | }; | |
| 3669 | 3708 | } |
lib/compiler/Maker/Graph.zig-1| ... | ... | @@ -4,7 +4,6 @@ const Graph = @This(); |
| 4 | 4 | const std = @import("std"); |
| 5 | 5 | const Io = std.Io; |
| 6 | 6 | const Allocator = std.mem.Allocator; |
| 7 | const Configuration = std.Build.Configuration; | |
| 8 | 7 | const Path = std.Build.Cache.Path; |
| 9 | 8 | const Directory = std.Build.Cache.Directory; |
| 10 | 9 |
lib/compiler/configurer.zig+2-3| ... | ... | @@ -633,8 +633,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 633 | 633 | var s: Serialize = .{ .wc = wc, .arena = arena }; |
| 634 | 634 | |
| 635 | 635 | try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len); |
| 636 | // TODO remove this | |
| 637 | if (false) for ( | |
| 636 | for ( | |
| 638 | 637 | graph.configure_dependencies.items, |
| 639 | 638 | wc.path_deps.addManyAsSliceAssumeCapacity(graph.configure_dependencies.items.len), |
| 640 | 639 | ) |src, *dest| { |
| ... | ... | @@ -662,7 +661,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 662 | 661 | .dependency => |d| .init(try s.builderToPackage(d.dependency.builder)), |
| 663 | 662 | }, |
| 664 | 663 | }; |
| 665 | }; | |
| 664 | } | |
| 666 | 665 | |
| 667 | 666 | // Starting from all top-level steps in `b`, traverse the entire step graph |
| 668 | 667 | // and add all step dependencies implied by module graphs. |
lib/std/Build.zig+1| ... | ... | @@ -177,6 +177,7 @@ pub const Graph = struct { |
| 177 | 177 | /// A path whose components and contents are known at some point during |
| 178 | 178 | /// `Step` resolution, relative to the provided base directory. |
| 179 | 179 | pub fn path(graph: *Graph, base: Configuration.LazyPath.Relative.Base, sub_path: []const u8) LazyPath { |
| 180 | assert(base != .build_root); | |
| 180 | 181 | return .{ .relative = .{ |
| 181 | 182 | .base = base, |
| 182 | 183 | .sub_path = @This().dupePath(graph, sub_path), |
lib/std/Build/Cache.zig+23-11| ... | ... | @@ -70,6 +70,15 @@ pub const PrefixedPath = struct { |
| 70 | 70 | } |
| 71 | 71 | }; |
| 72 | 72 | |
| 73 | fn findPrefixPath(cache: *const Cache, path: Path) !PrefixedPath { | |
| 74 | const gpa = cache.gpa; | |
| 75 | const resolved_path = try std.fs.path.resolve(gpa, &.{ | |
| 76 | cache.cwd, path.root_dir.path orelse ".", path.subPathOrDot(), | |
| 77 | }); | |
| 78 | errdefer gpa.free(resolved_path); | |
| 79 | return findPrefixResolved(cache, resolved_path); | |
| 80 | } | |
| 81 | ||
| 73 | 82 | fn findPrefix(cache: *const Cache, file_path: []const u8) !PrefixedPath { |
| 74 | 83 | const gpa = cache.gpa; |
| 75 | 84 | const resolved_path = try std.fs.path.resolve(gpa, &.{file_path}); |
| ... | ... | @@ -998,13 +1007,22 @@ pub const Manifest = struct { |
| 998 | 1007 | /// This is useful for processes that don't know the all the files that are |
| 999 | 1008 | /// depended on ahead of time. For example, a source file that can import |
| 1000 | 1009 | /// other files will need to be recompiled if the imported file is changed. |
| 1001 | pub fn addFilePost(self: *Manifest, file_path: []const u8) !void { | |
| 1002 | assert(self.manifest_file != null); | |
| 1003 | const gpa = self.cache.gpa; | |
| 1004 | const prefixed_path = try self.cache.findPrefix(file_path); | |
| 1010 | pub fn addFilePost(man: *Manifest, file_path: []const u8) !void { | |
| 1011 | assert(man.manifest_file != null); | |
| 1012 | const gpa = man.cache.gpa; | |
| 1013 | const prefixed_path = try man.cache.findPrefix(file_path); | |
| 1005 | 1014 | var keep = false; |
| 1006 | 1015 | defer if (!keep) gpa.free(prefixed_path.sub_path); |
| 1007 | keep = try addPrefixedPathPost(self, prefixed_path); | |
| 1016 | keep = try addPrefixedPathPost(man, prefixed_path); | |
| 1017 | } | |
| 1018 | ||
| 1019 | pub fn addPathPost(man: *Manifest, path: Path) !void { | |
| 1020 | assert(man.manifest_file != null); | |
| 1021 | const gpa = man.cache.gpa; | |
| 1022 | const prefixed_path: PrefixedPath = try man.cache.findPrefixPath(path); | |
| 1023 | var keep = false; | |
| 1024 | defer if (!keep) gpa.free(prefixed_path.sub_path); | |
| 1025 | keep = try addPrefixedPathPost(man, prefixed_path); | |
| 1008 | 1026 | } |
| 1009 | 1027 | |
| 1010 | 1028 | /// Low level function. `prefixed_path` references cloned memory. Returns |
| ... | ... | @@ -1034,12 +1052,6 @@ pub const Manifest = struct { |
| 1034 | 1052 | return true; |
| 1035 | 1053 | } |
| 1036 | 1054 | |
| 1037 | pub fn addPathPost(man: *Manifest, path: Path) !void { | |
| 1038 | _ = man; | |
| 1039 | _ = path; | |
| 1040 | std.log.err("TODO Build.Cache.addPathPost", .{}); | |
| 1041 | } | |
| 1042 | ||
| 1043 | 1055 | /// Like `addFilePost` but when the file contents have already been loaded from disk. |
| 1044 | 1056 | pub fn addFilePostContents( |
| 1045 | 1057 | self: *Manifest, |
lib/std/Build/Configuration.zig+1-7| ... | ... | @@ -1557,6 +1557,7 @@ pub const LazyPath = union(@This().Tag) { |
| 1557 | 1557 | cwd, |
| 1558 | 1558 | local_cache, |
| 1559 | 1559 | global_cache, |
| 1560 | /// Must not be used with Relative since package index is missing. | |
| 1560 | 1561 | build_root, |
| 1561 | 1562 | zig_exe, |
| 1562 | 1563 | zig_lib, |
| ... | ... | @@ -1876,13 +1877,6 @@ pub const PathDep = extern struct { |
| 1876 | 1877 | }; |
| 1877 | 1878 | |
| 1878 | 1879 | pub const Mode = enum(u8) { directory, contents, metadata }; |
| 1879 | ||
| 1880 | pub fn toCachePath(path: PathDep, c: *const Configuration, arena: Allocator) std.Build.Cache.Path { | |
| 1881 | _ = c; | |
| 1882 | _ = arena; | |
| 1883 | _ = path; | |
| 1884 | if (true) @panic("TODO Configuration.PathDep.toCachePath"); | |
| 1885 | } | |
| 1886 | 1880 | }; |
| 1887 | 1881 | |
| 1888 | 1882 | pub const InstallDestDir = enum(u32) { |