Skip to content

Commit 84f20b5

Browse files
motiejusandrewrk
authored andcommitted
tmpFilePath: re-use the same function
And move under `Compilation.Directory`, since it belongs there most.
1 parent df99c66 commit 84f20b5

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

src/Compilation.zig

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,7 +3981,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
39813981

39823982
// We can't know the digest until we do the C compiler invocation,
39833983
// so we need a temporary filename.
3984-
const out_obj_path = try comp.tmpFilePath(arena, o_basename);
3984+
const out_obj_path = try comp.local_cache_directory.tmpFilePath(arena, o_basename);
39853985
var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});
39863986
defer zig_cache_tmp_dir.close();
39873987

@@ -4129,16 +4129,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
41294129
};
41304130
}
41314131

4132-
pub fn tmpFilePath(comp: *Compilation, ally: Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 {
4133-
const s = std.fs.path.sep_str;
4134-
const rand_int = std.crypto.random.int(u64);
4135-
if (comp.local_cache_directory.path) |p| {
4136-
return std.fmt.allocPrint(ally, "{s}" ++ s ++ "tmp" ++ s ++ "{x}-{s}", .{ p, rand_int, suffix });
4137-
} else {
4138-
return std.fmt.allocPrint(ally, "tmp" ++ s ++ "{x}-{s}", .{ rand_int, suffix });
4139-
}
4140-
}
4141-
41424132
pub fn addTranslateCCArgs(
41434133
comp: *Compilation,
41444134
arena: Allocator,

src/main.zig

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,9 @@ fn copyToFile(
668668
in_fd: std.os.fd_t,
669669
dst_dir: Compilation.Directory,
670670
) ![]const u8 {
671-
// the section below is inspired by Compilation.tmpFilePath
672-
const new_name = blk: {
673-
const s = std.fs.path.sep_str;
674-
const rand_int = std.crypto.random.int(u64);
675-
if (dst_dir.path) |p| {
676-
break :blk try std.fmt.allocPrint(arena, "{s}" ++ s ++ "tmp" ++ s ++ "{x}", .{ p, rand_int });
677-
} else {
678-
break :blk try std.fmt.allocPrint(arena, "tmp" ++ s ++ "{x}", .{rand_int});
679-
}
680-
};
671+
const new_name = try dst_dir.tmpFilePath(arena, "waspipe");
681672
try dst_dir.handle.makePath("tmp");
682-
683-
var outfile = try dst_dir.handle.createFile(new_name, std.fs.File.CreateFlags{ .exclusive = true });
673+
var outfile = try dst_dir.handle.createFile(new_name, .{});
684674
defer outfile.close();
685675
errdefer dst_dir.handle.deleteFile(new_name) catch {};
686676

@@ -3967,7 +3957,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Translate
39673957

39683958
const c_src_basename = fs.path.basename(c_source_file.src_path);
39693959
const dep_basename = try std.fmt.allocPrint(arena, "{s}.d", .{c_src_basename});
3970-
const out_dep_path = try comp.tmpFilePath(arena, dep_basename);
3960+
const out_dep_path = try comp.local_cache_directory.tmpFilePath(arena, dep_basename);
39713961
break :blk out_dep_path;
39723962
};
39733963

0 commit comments

Comments
 (0)