| ... | @@ -2131,6 +2131,9 @@ test dirnameAllowEmpty { | ... | @@ -2131,6 +2131,9 @@ test dirnameAllowEmpty { |
| 2131 | | 2131 | |
| 2132 | /// A reference to an existing or future path. | 2132 | /// A reference to an existing or future path. |
| 2133 | pub const LazyPath = union(enum) { | 2133 | pub const LazyPath = union(enum) { |
| | 2134 | /// Deprecated; use the `path` function instead. |
| | 2135 | path: []const u8, |
| | 2136 | |
| 2134 | /// A source file path relative to build root. | 2137 | /// A source file path relative to build root. |
| 2135 | src_path: struct { | 2138 | src_path: struct { |
| 2136 | owner: *std.Build, | 2139 | owner: *std.Build, |
| ... | @@ -2165,6 +2168,12 @@ pub const LazyPath = union(enum) { | ... | @@ -2165,6 +2168,12 @@ pub const LazyPath = union(enum) { |
| 2165 | sub_path: []const u8, | 2168 | sub_path: []const u8, |
| 2166 | }, | 2169 | }, |
| 2167 | | 2170 | |
| | 2171 | /// Deprecated. Call `path` instead. |
| | 2172 | pub fn relative(p: []const u8) LazyPath { |
| | 2173 | std.log.warn("deprecated. call std.Build.path instead", .{}); |
| | 2174 | return .{ .path = p }; |
| | 2175 | } |
| | 2176 | |
| 2168 | /// Returns a lazy path referring to the directory containing this path. | 2177 | /// Returns a lazy path referring to the directory containing this path. |
| 2169 | /// | 2178 | /// |
| 2170 | /// The dirname is not allowed to escape the logical root for underlying path. | 2179 | /// The dirname is not allowed to escape the logical root for underlying path. |
| ... | @@ -2183,6 +2192,12 @@ pub const LazyPath = union(enum) { | ... | @@ -2183,6 +2192,12 @@ pub const LazyPath = union(enum) { |
| 2183 | @panic("misconfigured build script"); | 2192 | @panic("misconfigured build script"); |
| 2184 | }, | 2193 | }, |
| 2185 | } }, | 2194 | } }, |
| | 2195 | .path => |p| .{ |
| | 2196 | .path = dirnameAllowEmpty(p) orelse { |
| | 2197 | dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the build root\n", .{}) catch {}; |
| | 2198 | @panic("misconfigured build script"); |
| | 2199 | }, |
| | 2200 | }, |
| 2186 | .cwd_relative => |p| .{ | 2201 | .cwd_relative => |p| .{ |
| 2187 | .cwd_relative = dirnameAllowEmpty(p) orelse { | 2202 | .cwd_relative = dirnameAllowEmpty(p) orelse { |
| 2188 | // If we get null, it means one of two things: | 2203 | // If we get null, it means one of two things: |
| ... | @@ -2224,7 +2239,7 @@ pub const LazyPath = union(enum) { | ... | @@ -2224,7 +2239,7 @@ pub const LazyPath = union(enum) { |
| 2224 | pub fn getDisplayName(self: LazyPath) []const u8 { | 2239 | pub fn getDisplayName(self: LazyPath) []const u8 { |
| 2225 | return switch (self) { | 2240 | return switch (self) { |
| 2226 | .src_path => |sp| sp.sub_path, | 2241 | .src_path => |sp| sp.sub_path, |
| 2227 | .cwd_relative => |p| p, | 2242 | .path, .cwd_relative => |p| p, |
| 2228 | .generated => "generated", | 2243 | .generated => "generated", |
| 2229 | .generated_dirname => "generated", | 2244 | .generated_dirname => "generated", |
| 2230 | .dependency => "dependency", | 2245 | .dependency => "dependency", |
| ... | @@ -2234,7 +2249,7 @@ pub const LazyPath = union(enum) { | ... | @@ -2234,7 +2249,7 @@ pub const LazyPath = union(enum) { |
| 2234 | /// Adds dependencies this file source implies to the given step. | 2249 | /// Adds dependencies this file source implies to the given step. |
| 2235 | pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { | 2250 | pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { |
| 2236 | switch (self) { | 2251 | switch (self) { |
| 2237 | .src_path, .cwd_relative, .dependency => {}, | 2252 | .src_path, .path, .cwd_relative, .dependency => {}, |
| 2238 | .generated => |gen| other_step.dependOn(gen.step), | 2253 | .generated => |gen| other_step.dependOn(gen.step), |
| 2239 | .generated_dirname => |gen| other_step.dependOn(gen.generated.step), | 2254 | .generated_dirname => |gen| other_step.dependOn(gen.generated.step), |
| 2240 | } | 2255 | } |
| ... | @@ -2253,6 +2268,7 @@ pub const LazyPath = union(enum) { | ... | @@ -2253,6 +2268,7 @@ pub const LazyPath = union(enum) { |
| 2253 | /// run that is asking for the path. | 2268 | /// run that is asking for the path. |
| 2254 | pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { | 2269 | pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2255 | switch (self) { | 2270 | switch (self) { |
| | 2271 | .path => |p| return src_builder.pathFromRoot(p), |
| 2256 | .src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path), | 2272 | .src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path), |
| 2257 | .cwd_relative => |p| return src_builder.pathFromCwd(p), | 2273 | .cwd_relative => |p| return src_builder.pathFromCwd(p), |
| 2258 | .generated => |gen| return gen.path orelse { | 2274 | .generated => |gen| return gen.path orelse { |
| ... | @@ -2313,6 +2329,7 @@ pub const LazyPath = union(enum) { | ... | @@ -2313,6 +2329,7 @@ pub const LazyPath = union(enum) { |
| 2313 | .owner = sp.owner, | 2329 | .owner = sp.owner, |
| 2314 | .sub_path = sp.owner.dupePath(sp.sub_path), | 2330 | .sub_path = sp.owner.dupePath(sp.sub_path), |
| 2315 | } }, | 2331 | } }, |
| | 2332 | .path => |p| .{ .path = b.dupePath(p) }, |
| 2316 | .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, | 2333 | .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, |
| 2317 | .generated => |gen| .{ .generated = gen }, | 2334 | .generated => |gen| .{ .generated = gen }, |
| 2318 | .generated_dirname => |gen| .{ | 2335 | .generated_dirname => |gen| .{ |