diff --git a/lib/compiler/fmt.zig b/lib/compiler/fmt.zig index 2fc04b7935..e549a05bdd 100644 --- a/lib/compiler/fmt.zig +++ b/lib/compiler/fmt.zig @@ -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; 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 }); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 1073d6d3ab..44bcf3abc1 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -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 diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 63e7968c64..bd2f4e844c 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index a03abd2626..c41c41a2e4 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); }; diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 4e895ef3a7..051b6becee 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -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"); diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index 6528c2a53f..f45a5cc93e 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -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; @@ -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; @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/main.zig b/src/main.zig index 22349dd36a..2eb79877f3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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) = .{}; @@ -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 }; @@ -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, }; }; diff --git a/test/src/Cases.zig b/test/src/Cases.zig index 72574bd97e..9296f4668f 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -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.?); @@ -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 = .{ diff --git a/tools/doctest.zig b/tools/doctest.zig index 6be9d59ffb..422c07aa5e 100644 --- a/tools/doctest.zig +++ b/tools/doctest.zig @@ -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/ \\ ;