authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 14:22:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:36-07:00
log860d5ab9c41fd64c5150bd7d9f5b87cbcda9f281
treee812eef3624f133b8bfd5b0d5848e8290638a393
parent35ee3747ebe344b619c66b23053d3f2495956423

Maker: implement relativePath with non-empty subpath for zig_exe


2 files changed, 16 insertions(+), 8 deletions(-)

lib/compiler/Maker.zig+6-4
...@@ -1706,7 +1706,7 @@ pub fn resolveLazyPath(...@@ -1706,7 +1706,7 @@ pub fn resolveLazyPath(
1706 const c = &maker.scanned_config.configuration;1706 const c = &maker.scanned_config.configuration;
1707 return switch (lazy_path) {1707 return switch (lazy_path) {
1708 .source_path => |sp| try packagePath(maker, arena, sp.owner, sp.sub_path.slice(c)),1708 .source_path => |sp| try packagePath(maker, arena, sp.owner, sp.sub_path.slice(c)),
1709 .relative => |relative| relativePath(maker, relative),1709 .relative => |relative| relativePath(maker, arena, relative),
1710 .generated => |gen| {1710 .generated => |gen| {
1711 const base = generatedPath(maker, gen.index).*;1711 const base = generatedPath(maker, gen.index).*;
1712 var file_path = base;1712 var file_path = base;
...@@ -1785,11 +1785,10 @@ pub fn packagePath(...@@ -1785,11 +1785,10 @@ pub fn packagePath(
1785 };1785 };
1786}1786}
17871787
1788pub fn relativePath(maker: *const Maker, relative: Configuration.LazyPath.Relative) Path {1788pub fn relativePath(maker: *const Maker, arena: Allocator, relative: Configuration.LazyPath.Relative) Allocator.Error!Path {
1789 const graph = maker.graph;1789 const graph = maker.graph;
1790 const c = &maker.scanned_config.configuration;1790 const c = &maker.scanned_config.configuration;
1791 const sub_path = relative.sub_path.slice(c);1791 const sub_path = relative.sub_path.slice(c);
1792 if (relative.flags.base == .zig_exe and sub_path.len != 0) @panic("TODO relativePath zig_exe");
1793 return switch (relative.flags.base) {1792 return switch (relative.flags.base) {
1794 .cwd => .{1793 .cwd => .{
1795 .root_dir = .cwd(),1794 .root_dir = .cwd(),
...@@ -1809,7 +1808,10 @@ pub fn relativePath(maker: *const Maker, relative: Configuration.LazyPath.Relati...@@ -1809,7 +1808,10 @@ pub fn relativePath(maker: *const Maker, relative: Configuration.LazyPath.Relati
1809 },1808 },
1810 .zig_exe => .{1809 .zig_exe => .{
1811 .root_dir = .cwd(),1810 .root_dir = .cwd(),
1812 .sub_path = graph.zig_exe,1811 .sub_path = if (sub_path.len == 0)
1812 graph.zig_exe
1813 else
1814 try Io.Dir.path.join(arena, &.{ graph.zig_exe, sub_path }),
1813 },1815 },
1814 .zig_lib => .{1816 .zig_lib => .{
1815 .root_dir = graph.zig_lib_directory,1817 .root_dir = graph.zig_lib_directory,
lib/compiler/Maker/Step.zig+10-4
...@@ -785,7 +785,10 @@ pub fn addWatchInput(step: *Step, maker: *Maker, arena: Allocator, lazy_file: La...@@ -785,7 +785,10 @@ pub fn addWatchInput(step: *Step, maker: *Maker, arena: Allocator, lazy_file: La
785 const pkg_path = try maker.packagePath(arena, source_path.owner, sub_path);785 const pkg_path = try maker.packagePath(arena, source_path.owner, sub_path);
786 try addWatchInputPath(step, maker, pkg_path);786 try addWatchInputPath(step, maker, pkg_path);
787 },787 },
788 .relative => |relative| try addWatchInputPath(step, maker, maker.relativePath(relative)),788 .relative => |relative| {
789 const resolved_path = try maker.relativePath(arena, relative);
790 try addWatchInputPath(step, maker, resolved_path);
791 },
789 // Nothing to watch because this dependency edge is modeled instead via `dependants`.792 // Nothing to watch because this dependency edge is modeled instead via `dependants`.
790 .generated => {},793 .generated => {},
791 }794 }
...@@ -799,16 +802,19 @@ pub fn addWatchInput(step: *Step, maker: *Maker, arena: Allocator, lazy_file: La...@@ -799,16 +802,19 @@ pub fn addWatchInput(step: *Step, maker: *Maker, arena: Allocator, lazy_file: La
799/// `addDirectoryWatchInputFromPath` if and only if this function returns802/// `addDirectoryWatchInputFromPath` if and only if this function returns
800/// `true`.803/// `true`.
801pub fn addDirectoryWatchInput(step: *Step, maker: *Maker, lazy_directory: LazyPath) Allocator.Error!bool {804pub fn addDirectoryWatchInput(step: *Step, maker: *Maker, lazy_directory: LazyPath) Allocator.Error!bool {
805 const graph = maker.graph;
806 const arena = graph.arena; // TODO don't leak into the process arena
802 switch (lazy_directory) {807 switch (lazy_directory) {
803 .source_path => |source_path| {808 .source_path => |source_path| {
804 const conf = &maker.scanned_config.configuration;809 const conf = &maker.scanned_config.configuration;
805 const graph = maker.graph;
806 const arena = graph.arena; // TODO don't leak into the process arena
807 const sub_path = source_path.sub_path.slice(conf);810 const sub_path = source_path.sub_path.slice(conf);
808 const pkg_path = try maker.packagePath(arena, source_path.owner, sub_path);811 const pkg_path = try maker.packagePath(arena, source_path.owner, sub_path);
809 try addDirectoryWatchInputFromPath(step, maker, pkg_path);812 try addDirectoryWatchInputFromPath(step, maker, pkg_path);
810 },813 },
811 .relative => |relative| try addDirectoryWatchInputFromPath(step, maker, maker.relativePath(relative)),814 .relative => |relative| {
815 const resolved_path = try maker.relativePath(arena, relative);
816 try addDirectoryWatchInputFromPath(step, maker, resolved_path);
817 },
812 // Nothing to watch because this dependency edge is modeled instead via `dependants`.818 // Nothing to watch because this dependency edge is modeled instead via `dependants`.
813 .generated => return false,819 .generated => return false,
814 }820 }