Skip to content

rename zig-cache to .zig-cache #20115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compiler/fmt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn fmtPathDir(
while (try dir_it.next()) |entry| {
const is_dir = entry.kind == .directory;

if (is_dir and (mem.eql(u8, entry.name, "zig-cache") or mem.eql(u8, entry.name, "zig-out"))) continue;
if (mem.startsWith(u8, entry.name, ".")) continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I wrong in thinking it might still make sense to ignore zig-out here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although zig-out is the default installation prefix, it is not the only one that could possibly exist. It is not supposed to be special.


if (is_dir or entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"))) {
const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });
Expand Down
2 changes: 1 addition & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ test printLineFromFileAnyOs {
var test_dir = std.testing.tmpDir(.{});
defer test_dir.cleanup();
// Relies on testing.tmpDir internals which is not ideal, but LineInfo requires paths.
const test_dir_path = try join(allocator, &.{ "zig-cache", "tmp", test_dir.sub_path[0..] });
const test_dir_path = try join(allocator, &.{ ".zig-cache", "tmp", test_dir.sub_path[0..] });
defer allocator.free(test_dir_path);

// Cases
Expand Down
10 changes: 5 additions & 5 deletions lib/std/fs/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ test "accessAbsolute" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &.{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand All @@ -344,7 +344,7 @@ test "openDirAbsolute" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &.{ "zig-cache", "tmp", tmp.sub_path[0..], "subdir" });
const relative_path = try fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp.sub_path[0..], "subdir" });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -407,7 +407,7 @@ test "readLinkAbsolute" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &.{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -990,7 +990,7 @@ test "renameAbsolute" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &.{ "zig-cache", "tmp", tmp_dir.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp_dir.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -1772,7 +1772,7 @@ test "'.' and '..' in absolute functions" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &.{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &.{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down
14 changes: 7 additions & 7 deletions lib/std/posix/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test "open smoke test" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -1022,7 +1022,7 @@ test "rename smoke test" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -1079,7 +1079,7 @@ test "access smoke test" {
const allocator = arena.allocator();

const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down Expand Up @@ -1153,7 +1153,7 @@ test "read with empty buffer" {

// Get base abs path
const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand All @@ -1178,7 +1178,7 @@ test "pread with empty buffer" {

// Get base abs path
const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand All @@ -1203,7 +1203,7 @@ test "write with empty buffer" {

// Get base abs path
const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand All @@ -1228,7 +1228,7 @@ test "pwrite with empty buffer" {

// Get base abs path
const base_path = blk: {
const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] });
const relative_path = try fs.path.join(allocator, &[_][]const u8{ ".zig-cache", "tmp", tmp.sub_path[0..] });
break :blk try fs.realpathAlloc(allocator, relative_path);
};

Expand Down
6 changes: 3 additions & 3 deletions lib/std/testing.zig
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
_ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);

const cwd = std.fs.cwd();
var cache_dir = cwd.makeOpenPath("zig-cache", .{}) catch
@panic("unable to make tmp dir for testing: unable to make and open zig-cache dir");
var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch
@panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
defer cache_dir.close();
const parent_dir = cache_dir.makeOpenPath("tmp", .{}) catch
@panic("unable to make tmp dir for testing: unable to make and open zig-cache/tmp dir");
@panic("unable to make tmp dir for testing: unable to make and open .zig-cache/tmp dir");
const dir = parent_dir.makeOpenPath(&sub_path, opts) catch
@panic("unable to make tmp dir for testing: unable to make and open the tmp dir");

Expand Down
12 changes: 6 additions & 6 deletions src/Package/Fetch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ test "zip" {
try bw.flush();
}

const zip_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/test.zip", .{tmp.sub_path});
const zip_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/test.zip", .{tmp.sub_path});
defer gpa.free(zip_path);

var fb: TestFetchBuilder = undefined;
Expand Down Expand Up @@ -2033,7 +2033,7 @@ test "zip with one root folder" {
try bw.flush();
}

const zip_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/test.zip", .{tmp.sub_path});
const zip_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/test.zip", .{tmp.sub_path});
defer gpa.free(zip_path);

var fb: TestFetchBuilder = undefined;
Expand Down Expand Up @@ -2069,7 +2069,7 @@ test "tarball with duplicate paths" {

const tarball_name = "duplicate_paths.tar.gz";
try saveEmbedFile(tarball_name, tmp.dir);
const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
defer gpa.free(tarball_path);

// Run tarball fetch, expect to fail
Expand Down Expand Up @@ -2101,7 +2101,7 @@ test "tarball with excluded duplicate paths" {

const tarball_name = "duplicate_paths_excluded.tar.gz";
try saveEmbedFile(tarball_name, tmp.dir);
const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
defer gpa.free(tarball_path);

// Run tarball fetch, should succeed
Expand Down Expand Up @@ -2145,7 +2145,7 @@ test "tarball without root folder" {

const tarball_name = "no_root.tar.gz";
try saveEmbedFile(tarball_name, tmp.dir);
const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
defer gpa.free(tarball_path);

// Run tarball fetch, should succeed
Expand Down Expand Up @@ -2176,7 +2176,7 @@ test "set executable bit based on file content" {

const tarball_name = "executables.tar.gz";
try saveEmbedFile(tarball_name, tmp.dir);
const tarball_path = try std.fmt.allocPrint(gpa, "zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
defer gpa.free(tarball_path);

// $ tar -tvf executables.tar.gz
Expand Down
8 changes: 4 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const debug_usage = normal_usage ++
;

const usage = if (build_options.enable_debug_extensions) debug_usage else normal_usage;
const default_local_zig_cache_basename = ".zig-cache";

var log_scopes: std.ArrayListUnmanaged([]const u8) = .{};

Expand Down Expand Up @@ -3107,14 +3108,13 @@ fn buildOutputType(

// search upwards from cwd until we find directory with build.zig
const cwd_path = try process.getCwdAlloc(arena);
const zig_cache = "zig-cache";
var dirname: []const u8 = cwd_path;
while (true) {
const joined_path = try fs.path.join(arena, &.{
dirname, Package.build_zig_basename,
});
if (fs.cwd().access(joined_path, .{})) |_| {
const cache_dir_path = try fs.path.join(arena, &.{ dirname, zig_cache });
const cache_dir_path = try fs.path.join(arena, &.{ dirname, default_local_zig_cache_basename });
const dir = try fs.cwd().makeOpenPath(cache_dir_path, .{});
cleanup_local_cache_dir = dir;
break :l .{ .handle = dir, .path = cache_dir_path };
Expand Down Expand Up @@ -4869,9 +4869,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
.path = local_cache_dir_path,
};
}
const cache_dir_path = try build_root.directory.join(arena, &[_][]const u8{"zig-cache"});
const cache_dir_path = try build_root.directory.join(arena, &.{default_local_zig_cache_basename});
break :l .{
.handle = try build_root.directory.handle.makeOpenPath("zig-cache", .{}),
.handle = try build_root.directory.handle.makeOpenPath(default_local_zig_cache_basename, .{}),
.path = cache_dir_path,
};
};
Expand Down
12 changes: 6 additions & 6 deletions test/src/Cases.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1449,14 +1449,14 @@ fn runCases(self: *Cases, zig_exe_path: []const u8) !void {
var global_tmp = std.testing.tmpDir(.{});
defer global_tmp.cleanup();

var cache_dir = try global_tmp.dir.makeOpenPath("zig-cache", .{});
var cache_dir = try global_tmp.dir.makeOpenPath(".zig-cache", .{});
defer cache_dir.close();
const tmp_dir_path = try std.fs.path.join(self.gpa, &[_][]const u8{ ".", "zig-cache", "tmp", &global_tmp.sub_path });
const tmp_dir_path = try std.fs.path.join(self.gpa, &[_][]const u8{ ".", ".zig-cache", "tmp", &global_tmp.sub_path });
defer self.gpa.free(tmp_dir_path);

const global_cache_directory: Compilation.Directory = .{
.handle = cache_dir,
.path = try std.fs.path.join(self.gpa, &[_][]const u8{ tmp_dir_path, "zig-cache" }),
.path = try std.fs.path.join(self.gpa, &[_][]const u8{ tmp_dir_path, ".zig-cache" }),
};
defer self.gpa.free(global_cache_directory.path.?);

Expand Down Expand Up @@ -1529,16 +1529,16 @@ fn runOneCase(
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();

var cache_dir = try tmp.dir.makeOpenPath("zig-cache", .{});
var cache_dir = try tmp.dir.makeOpenPath(".zig-cache", .{});
defer cache_dir.close();

const tmp_dir_path = try std.fs.path.join(
arena,
&[_][]const u8{ ".", "zig-cache", "tmp", &tmp.sub_path },
&[_][]const u8{ ".", ".zig-cache", "tmp", &tmp.sub_path },
);
const local_cache_path = try std.fs.path.join(
arena,
&[_][]const u8{ tmp_dir_path, "zig-cache" },
&[_][]const u8{ tmp_dir_path, ".zig-cache" },
);

const zig_cache_directory: Compilation.Directory = .{
Expand Down
2 changes: 1 addition & 1 deletion tools/doctest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const usage =
\\ -o output Where to write output HTML docs to
\\ --zig zig Path to the zig compiler
\\ --zig-lib-dir dir Override the zig compiler library path
\\ --cache-root dir Path to local zig-cache/
\\ --cache-root dir Path to local .zig-cache/
\\
;

Expand Down