authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-11 14:08:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-11 14:09:58-07:00
log499a202a13c2a61f3cb2535c1bd63a9b6b30bfb7
treef3f1d49043e97e7828f681b012cde639ff62ddc8
parentb30ad7490891ca3522abdd0a1ffaf809df497f3d

std.Build: revert the breaking changes only

The previous commit deleted the deprecated API and then made all the follow-up changes; this commit reverts only the breaking API changes. This commit can be reverted once 0.12.0 is tagged.

2 files changed, 20 insertions(+), 2 deletions(-)

lib/std/Build.zig+19-2
...@@ -2131,6 +2131,9 @@ test dirnameAllowEmpty {...@@ -2131,6 +2131,9 @@ test dirnameAllowEmpty {
21312131
2132/// A reference to an existing or future path.2132/// A reference to an existing or future path.
2133pub const LazyPath = union(enum) {2133pub 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 },
21672170
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| .{
lib/std/Build/Step/ConfigHeader.zig+1
...@@ -59,6 +59,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {...@@ -59,6 +59,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
59 if (options.style.getPath()) |s| default_include_path: {59 if (options.style.getPath()) |s| default_include_path: {
60 const sub_path = switch (s) {60 const sub_path = switch (s) {
61 .src_path => |sp| sp.sub_path,61 .src_path => |sp| sp.sub_path,
62 .path => |path| path,
62 .generated, .generated_dirname => break :default_include_path,63 .generated, .generated_dirname => break :default_include_path,
63 .cwd_relative => |sub_path| sub_path,64 .cwd_relative => |sub_path| sub_path,
64 .dependency => |dependency| dependency.sub_path,65 .dependency => |dependency| dependency.sub_path,