authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-07 11:35:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-08 16:54:31-07:00
loge86b7fcca3e522bede8bab06d669b75d0dca2038
tree178158aae5560d38d666de6477a27baa72e7381b
parent4eb7b61daae4fe43b218eaaac0614f6bee1915d8

fix detection of build.zig file inside packages


2 files changed, 40 insertions(+), 6 deletions(-)

src/Package.zig+10
......@@ -83,6 +83,16 @@ pub const Path = struct {
8383 return p.root_dir.handle.atomicFile(joined_path, options);
8484 }
8585
86 pub fn access(p: Path, sub_path: []const u8, flags: fs.File.OpenFlags) !void {
87 var buf: [fs.MAX_PATH_BYTES]u8 = undefined;
88 const joined_path = if (p.sub_path.len == 0) sub_path else p: {
89 break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
90 p.sub_path, sub_path,
91 }) catch return error.NameTooLong;
92 };
93 return p.root_dir.handle.access(joined_path, flags);
94 }
95
8696 pub fn format(
8797 self: Path,
8898 comptime fmt_string: []const u8,
src/Package/Fetch.zig+30-6
......@@ -231,6 +231,7 @@ pub fn run(f: *Fetch) RunError!void {
231231 );
232232 f.package_root = try f.parent_package_root.join(arena, sub_path);
233233 try loadManifest(f, f.package_root);
234 try checkBuildFileExistence(f);
234235 if (!f.job_queue.recursive) return;
235236 // Package hashes are used as unique identifiers for packages, so
236237 // we still need one for relative paths.
......@@ -279,17 +280,18 @@ pub fn run(f: *Fetch) RunError!void {
279280 if (cache_root.handle.access(pkg_sub_path, .{})) |_| {
280281 f.package_root = .{
281282 .root_dir = cache_root,
282 .sub_path = pkg_sub_path,
283 .sub_path = try arena.dupe(u8, pkg_sub_path),
283284 };
284285 try loadManifest(f, f.package_root);
286 try checkBuildFileExistence(f);
285287 if (!f.job_queue.recursive) return;
286288 return queueJobsForDeps(f, expected_hash);
287289 } else |err| switch (err) {
288290 error.FileNotFound => {},
289291 else => |e| {
290292 try eb.addRootErrorMessage(.{
291 .msg = try eb.printString("unable to open global package cache directory '{s}': {s}", .{
292 try cache_root.join(arena, &.{pkg_sub_path}), @errorName(e),
293 .msg = try eb.printString("unable to open global package cache directory '{}{s}': {s}", .{
294 cache_root, pkg_sub_path, @errorName(e),
293295 }),
294296 });
295297 return error.FetchFailed;
......@@ -381,10 +383,13 @@ fn runResource(
381383 // by the system. This is done even if the hash is invalid, in case the
382384 // package with the different hash is used in the future.
383385
384 const dest_pkg_sub_path = "p" ++ s ++ Manifest.hexDigest(f.actual_hash);
385 renameTmpIntoCache(cache_root.handle, tmp_dir_sub_path, dest_pkg_sub_path) catch |err| {
386 f.package_root = .{
387 .root_dir = cache_root,
388 .sub_path = try arena.dupe(u8, "p" ++ s ++ Manifest.hexDigest(f.actual_hash)),
389 };
390 renameTmpIntoCache(cache_root.handle, tmp_dir_sub_path, f.package_root.sub_path) catch |err| {
386391 const src = try cache_root.join(arena, &.{tmp_dir_sub_path});
387 const dest = try cache_root.join(arena, &.{dest_pkg_sub_path});
392 const dest = try cache_root.join(arena, &.{f.package_root.sub_path});
388393 try eb.addRootErrorMessage(.{ .msg = try eb.printString(
389394 "unable to rename temporary directory '{s}' into package cache directory '{s}': {s}",
390395 .{ src, dest, @errorName(err) },
......@@ -423,6 +428,25 @@ fn runResource(
423428 return queueJobsForDeps(f, actual_hex);
424429}
425430
431/// `computeHash` gets a free check for the existence of `build.zig`, but when
432/// not computing a hash, we need to do a syscall to check for it.
433fn checkBuildFileExistence(f: *Fetch) RunError!void {
434 const eb = &f.error_bundle;
435 if (f.package_root.access(Package.build_zig_basename, .{})) |_| {
436 f.has_build_zig = true;
437 } else |err| switch (err) {
438 error.FileNotFound => {},
439 else => |e| {
440 try eb.addRootErrorMessage(.{
441 .msg = try eb.printString("unable to access '{}{s}': {s}", .{
442 f.package_root, Package.build_zig_basename, @errorName(e),
443 }),
444 });
445 return error.FetchFailed;
446 },
447 }
448}
449
426450/// This function populates `f.manifest` or leaves it `null`.
427451fn loadManifest(f: *Fetch, pkg_root: Package.Path) RunError!void {
428452 const eb = &f.error_bundle;