Function dirname [src]

Returns a lazy path referring to the directory containing this path. The dirname is not allowed to escape the logical root for underlying path. For example, if the path is relative to the build root, the dirname is not allowed to traverse outside of the build root. Similarly, if the path is a generated file inside zig-cache, the dirname is not allowed to traverse outside of zig-cache.

Prototype

pub fn dirname(lazy_path: LazyPath) LazyPath

Parameters

lazy_path: LazyPath

Source

pub fn dirname(lazy_path: LazyPath) LazyPath { return switch (lazy_path) { .src_path => |sp| .{ .src_path = .{ .owner = sp.owner, .sub_path = dirnameAllowEmpty(sp.sub_path) orelse { dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the build root\n", .{}) catch {}; @panic("misconfigured build script"); }, } }, .generated => |generated| .{ .generated = if (dirnameAllowEmpty(generated.sub_path)) |sub_dirname| .{ .file = generated.file, .up = generated.up, .sub_path = sub_dirname, } else .{ .file = generated.file, .up = generated.up + 1, .sub_path = "", } }, .cwd_relative => |rel_path| .{ .cwd_relative = dirnameAllowEmpty(rel_path) orelse { // If we get null, it means one of two things: // - rel_path was absolute, and is now root // - rel_path was relative, and is now "" // In either case, the build script tried to go too far // and we should panic. if (fs.path.isAbsolute(rel_path)) { dumpBadDirnameHelp(null, null, \\dirname() attempted to traverse outside the root. \\No more directories left to go up. \\ , .{}) catch {}; @panic("misconfigured build script"); } else { dumpBadDirnameHelp(null, null, \\dirname() attempted to traverse outside the current working directory. \\ , .{}) catch {}; @panic("misconfigured build script"); } }, }, .dependency => |dep| .{ .dependency = .{ .dependency = dep.dependency, .sub_path = dirnameAllowEmpty(dep.sub_path) orelse { dumpBadDirnameHelp(null, null, \\dirname() attempted to traverse outside the dependency root. \\ , .{}) catch {}; @panic("misconfigured build script"); }, } }, }; }