mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
update all readFileAlloc() to accept Io instance
This commit is contained in:
@@ -179,10 +179,11 @@ fn serveDocsFile(
|
||||
content_type: []const u8,
|
||||
) !void {
|
||||
const gpa = context.gpa;
|
||||
const io = context.io;
|
||||
// The desired API is actually sendfile, which will require enhancing std.http.Server.
|
||||
// We load the file with every request so that the user can make changes to the file
|
||||
// and refresh the HTML page without restarting this server.
|
||||
const file_contents = try context.lib_dir.readFileAlloc(name, gpa, .limited(10 * 1024 * 1024));
|
||||
const file_contents = try context.lib_dir.readFileAlloc(io, name, gpa, .limited(10 * 1024 * 1024));
|
||||
defer gpa.free(file_contents);
|
||||
try request.respond(file_contents, .{
|
||||
.extra_headers = &.{
|
||||
@@ -255,6 +256,7 @@ fn serveWasm(
|
||||
optimize_mode: std.builtin.OptimizeMode,
|
||||
) !void {
|
||||
const gpa = context.gpa;
|
||||
const io = context.io;
|
||||
|
||||
var arena_instance = std.heap.ArenaAllocator.init(gpa);
|
||||
defer arena_instance.deinit();
|
||||
@@ -273,7 +275,7 @@ fn serveWasm(
|
||||
});
|
||||
// std.http.Server does not have a sendfile API yet.
|
||||
const bin_path = try wasm_base_path.join(arena, bin_name);
|
||||
const file_contents = try bin_path.root_dir.handle.readFileAlloc(bin_path.sub_path, gpa, .limited(10 * 1024 * 1024));
|
||||
const file_contents = try bin_path.root_dir.handle.readFileAlloc(io, bin_path.sub_path, gpa, .limited(10 * 1024 * 1024));
|
||||
defer gpa.free(file_contents);
|
||||
try request.respond(file_contents, .{
|
||||
.extra_headers = &.{
|
||||
|
||||
@@ -1075,7 +1075,8 @@ pub const Manifest = struct {
|
||||
|
||||
fn addDepFileMaybePost(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void {
|
||||
const gpa = self.cache.gpa;
|
||||
const dep_file_contents = try dir.readFileAlloc(dep_file_sub_path, gpa, .limited(manifest_file_size_max));
|
||||
const io = self.cache.io;
|
||||
const dep_file_contents = try dir.readFileAlloc(io, dep_file_sub_path, gpa, .limited(manifest_file_size_max));
|
||||
defer gpa.free(dep_file_contents);
|
||||
|
||||
var error_buf: std.ArrayList(u8) = .empty;
|
||||
|
||||
@@ -51,11 +51,12 @@ pub fn setName(check_file: *CheckFile, name: []const u8) void {
|
||||
fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
_ = options;
|
||||
const b = step.owner;
|
||||
const io = b.graph.io;
|
||||
const check_file: *CheckFile = @fieldParentPtr("step", step);
|
||||
try step.singleUnchangingWatchInput(check_file.source);
|
||||
|
||||
const src_path = check_file.source.getPath2(b, step);
|
||||
const contents = Io.Dir.cwd().readFileAlloc(src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| {
|
||||
const contents = Io.Dir.cwd().readFileAlloc(io, src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| {
|
||||
return step.fail("unable to read '{s}': {s}", .{
|
||||
src_path, @errorName(err),
|
||||
});
|
||||
|
||||
@@ -208,7 +208,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
.autoconf_undef, .autoconf_at => |file_source| {
|
||||
try bw.writeAll(c_generated_line);
|
||||
const src_path = file_source.getPath2(b, step);
|
||||
const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
|
||||
const contents = Io.Dir.cwd().readFileAlloc(io, src_path, arena, .limited(config_header.max_bytes)) catch |err| {
|
||||
return step.fail("unable to read autoconf input file '{s}': {s}", .{
|
||||
src_path, @errorName(err),
|
||||
});
|
||||
@@ -222,7 +222,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
.cmake => |file_source| {
|
||||
try bw.writeAll(c_generated_line);
|
||||
const src_path = file_source.getPath2(b, step);
|
||||
const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
|
||||
const contents = Io.Dir.cwd().readFileAlloc(io, src_path, arena, .limited(config_header.max_bytes)) catch |err| {
|
||||
return step.fail("unable to read cmake input file '{s}': {s}", .{
|
||||
src_path, @errorName(err),
|
||||
});
|
||||
|
||||
@@ -469,11 +469,12 @@ pub fn serveFile(
|
||||
content_type: []const u8,
|
||||
) !void {
|
||||
const gpa = ws.gpa;
|
||||
const io = ws.graph.io;
|
||||
// The desired API is actually sendfile, which will require enhancing http.Server.
|
||||
// We load the file with every request so that the user can make changes to the file
|
||||
// and refresh the HTML page without restarting this server.
|
||||
const file_contents = path.root_dir.handle.readFileAlloc(path.sub_path, gpa, .limited(10 * 1024 * 1024)) catch |err| {
|
||||
log.err("failed to read '{f}': {s}", .{ path, @errorName(err) });
|
||||
const file_contents = path.root_dir.handle.readFileAlloc(io, path.sub_path, gpa, .limited(10 * 1024 * 1024)) catch |err| {
|
||||
log.err("failed to read '{f}': {t}", .{ path, err });
|
||||
return error.AlreadyReported;
|
||||
};
|
||||
defer gpa.free(file_contents);
|
||||
|
||||
+3
-3
@@ -1117,10 +1117,10 @@ pub fn readLink(dir: Dir, io: Io, sub_path: []const u8, buffer: []u8) ReadLinkEr
|
||||
/// On other platforms, `path` is an opaque sequence of bytes with no particular encoding.
|
||||
pub fn readLinkAbsolute(io: Io, absolute_path: []const u8, buffer: []u8) ReadLinkError!usize {
|
||||
assert(path.isAbsolute(absolute_path));
|
||||
return io.vtable.dirReadLink(io.userdata, .cwd(), path, buffer);
|
||||
return io.vtable.dirReadLink(io.userdata, .cwd(), absolute_path, buffer);
|
||||
}
|
||||
|
||||
pub const ReadFileAllocError = File.OpenError || File.ReadError || Allocator.Error || error{
|
||||
pub const ReadFileAllocError = File.OpenError || File.Reader.Error || Allocator.Error || error{
|
||||
/// File size reached or exceeded the provided limit.
|
||||
StreamTooLong,
|
||||
};
|
||||
@@ -1603,7 +1603,7 @@ pub const CopyFileOptions = struct {
|
||||
|
||||
pub const CopyFileError = File.OpenError || File.StatError ||
|
||||
File.Atomic.InitError || File.Atomic.FinishError ||
|
||||
File.ReadError || File.WriteError || error{InvalidFileName};
|
||||
File.Reader.Error || File.WriteError || error{InvalidFileName};
|
||||
|
||||
/// Atomically creates a new file at `dest_path` within `dest_dir` with the
|
||||
/// same contents as `source_path` within `source_dir`, overwriting any already
|
||||
|
||||
@@ -17,9 +17,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanM
|
||||
"/Library/Keychains/System.keychain",
|
||||
};
|
||||
|
||||
_ = io; // TODO migrate file system to use std.Io
|
||||
for (keychain_paths) |keychain_path| {
|
||||
const bytes = Io.Dir.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
|
||||
const bytes = Io.Dir.cwd().readFileAlloc(io, keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
|
||||
error.StreamTooLong => return error.FileTooBig,
|
||||
else => |e| return e,
|
||||
};
|
||||
|
||||
+14
-13
@@ -767,7 +767,7 @@ test "readFileAlloc" {
|
||||
var file = try tmp_dir.dir.createFile(io, "test_file", .{ .read = true });
|
||||
defer file.close(io);
|
||||
|
||||
const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024));
|
||||
const buf1 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(1024));
|
||||
defer testing.allocator.free(buf1);
|
||||
try testing.expectEqualStrings("", buf1);
|
||||
|
||||
@@ -776,7 +776,7 @@ test "readFileAlloc" {
|
||||
|
||||
{
|
||||
// max_bytes > file_size
|
||||
const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024));
|
||||
const buf2 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(1024));
|
||||
defer testing.allocator.free(buf2);
|
||||
try testing.expectEqualStrings(write_buf, buf2);
|
||||
}
|
||||
@@ -785,13 +785,13 @@ test "readFileAlloc" {
|
||||
// max_bytes == file_size
|
||||
try testing.expectError(
|
||||
error.StreamTooLong,
|
||||
tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len)),
|
||||
tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len)),
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
// max_bytes == file_size + 1
|
||||
const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len + 1));
|
||||
const buf2 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len + 1));
|
||||
defer testing.allocator.free(buf2);
|
||||
try testing.expectEqualStrings(write_buf, buf2);
|
||||
}
|
||||
@@ -799,7 +799,7 @@ test "readFileAlloc" {
|
||||
// max_bytes < file_size
|
||||
try testing.expectError(
|
||||
error.StreamTooLong,
|
||||
tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len - 1)),
|
||||
tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len - 1)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -877,16 +877,16 @@ test "file operations on directories" {
|
||||
switch (native_os) {
|
||||
.dragonfly, .netbsd => {
|
||||
// no error when reading a directory. See https://github.com/ziglang/zig/issues/5732
|
||||
const buf = try ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited);
|
||||
const buf = try ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited);
|
||||
testing.allocator.free(buf);
|
||||
},
|
||||
.wasi => {
|
||||
// WASI return EBADF, which gets mapped to NotOpenForReading.
|
||||
// See https://github.com/bytecodealliance/wasmtime/issues/1935
|
||||
try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited));
|
||||
try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited));
|
||||
},
|
||||
else => {
|
||||
try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited));
|
||||
try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited));
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1679,14 +1679,14 @@ test "copyFile" {
|
||||
try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, .{ .override_mode = File.default_mode });
|
||||
defer ctx.dir.deleteFile(dest_file2) catch {};
|
||||
|
||||
try expectFileContents(ctx.dir, dest_file, data);
|
||||
try expectFileContents(ctx.dir, dest_file2, data);
|
||||
try expectFileContents(io, ctx.dir, dest_file, data);
|
||||
try expectFileContents(io, ctx.dir, dest_file2, data);
|
||||
}
|
||||
}.impl);
|
||||
}
|
||||
|
||||
fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
|
||||
const contents = try dir.readFileAlloc(file_path, testing.allocator, .limited(1000));
|
||||
fn expectFileContents(io: Io, dir: Dir, file_path: []const u8, data: []const u8) !void {
|
||||
const contents = try dir.readFileAlloc(io, file_path, testing.allocator, .limited(1000));
|
||||
defer testing.allocator.free(contents);
|
||||
|
||||
try testing.expectEqualSlices(u8, data, contents);
|
||||
@@ -1695,6 +1695,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void {
|
||||
test "AtomicFile" {
|
||||
try testWithAllSupportedPathTypes(struct {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
const io = ctx.io;
|
||||
const allocator = ctx.arena.allocator();
|
||||
const test_out_file = try ctx.transformPath("tmp_atomic_file_test_dest.txt");
|
||||
const test_content =
|
||||
@@ -1709,7 +1710,7 @@ test "AtomicFile" {
|
||||
try af.file_writer.interface.writeAll(test_content);
|
||||
try af.finish();
|
||||
}
|
||||
const content = try ctx.dir.readFileAlloc(test_out_file, allocator, .limited(9999));
|
||||
const content = try ctx.dir.readFileAlloc(io, test_out_file, allocator, .limited(9999));
|
||||
try testing.expectEqualStrings(test_content, content);
|
||||
|
||||
try ctx.dir.deleteFile(test_out_file);
|
||||
|
||||
@@ -37,11 +37,7 @@ pub const FindError = error{
|
||||
ZigIsTheCCompiler,
|
||||
};
|
||||
|
||||
pub fn parse(
|
||||
allocator: Allocator,
|
||||
libc_file: []const u8,
|
||||
target: *const std.Target,
|
||||
) !LibCInstallation {
|
||||
pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation {
|
||||
var self: LibCInstallation = .{};
|
||||
|
||||
const fields = std.meta.fields(LibCInstallation);
|
||||
@@ -57,7 +53,7 @@ pub fn parse(
|
||||
}
|
||||
}
|
||||
|
||||
const contents = try Io.Dir.cwd().readFileAlloc(libc_file, allocator, .limited(std.math.maxInt(usize)));
|
||||
const contents = try Io.Dir.cwd().readFileAlloc(io, libc_file, allocator, .limited(std.math.maxInt(usize)));
|
||||
defer allocator.free(contents);
|
||||
|
||||
var it = std.mem.tokenizeScalar(u8, contents, '\n');
|
||||
|
||||
@@ -775,7 +775,7 @@ const MsvcLibDir = struct {
|
||||
writer.writeByte(std.fs.path.sep) catch unreachable;
|
||||
writer.writeAll("state.json") catch unreachable;
|
||||
|
||||
const json_contents = instances_dir.readFileAlloc(writer.buffered(), allocator, .limited(std.math.maxInt(usize))) catch continue;
|
||||
const json_contents = instances_dir.readFileAlloc(io, writer.buffered(), allocator, .limited(std.math.maxInt(usize))) catch continue;
|
||||
defer allocator.free(json_contents);
|
||||
|
||||
var parsed = std.json.parseFromSlice(std.json.Value, allocator, json_contents, .{}) catch continue;
|
||||
|
||||
+2
-2
@@ -6400,7 +6400,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
|
||||
|
||||
if (comp.file_system_inputs != null) {
|
||||
// Use the same file size limit as the cache code does for dependency files.
|
||||
const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, gpa, .limited(Cache.manifest_file_size_max));
|
||||
const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, gpa, .limited(Cache.manifest_file_size_max));
|
||||
defer gpa.free(dep_file_contents);
|
||||
|
||||
var str_buf: std.ArrayList(u8) = .empty;
|
||||
@@ -6665,7 +6665,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
|
||||
// Read depfile and update cache manifest
|
||||
{
|
||||
const dep_basename = fs.path.basename(out_dep_path);
|
||||
const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, arena, .limited(50 * 1024 * 1024));
|
||||
const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, arena, .limited(50 * 1024 * 1024));
|
||||
defer arena.free(dep_file_contents);
|
||||
|
||||
const value = try std.json.parseFromSliceLeaky(std.json.Value, arena, dep_file_contents, .{});
|
||||
|
||||
@@ -1602,7 +1602,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u
|
||||
const max_file_size = 8192;
|
||||
|
||||
if (!skip_checksums) {
|
||||
const index_file_data = try git_dir.dir.readFileAlloc("testrepo.idx", testing.allocator, .limited(max_file_size));
|
||||
const index_file_data = try git_dir.dir.readFileAlloc(io, "testrepo.idx", testing.allocator, .limited(max_file_size));
|
||||
defer testing.allocator.free(index_file_data);
|
||||
// testrepo.idx is generated by Git. The index created by this file should
|
||||
// match it exactly. Running `git verify-pack -v testrepo.pack` can verify
|
||||
@@ -1678,7 +1678,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u
|
||||
\\revision 19
|
||||
\\
|
||||
;
|
||||
const actual_file_contents = try worktree.dir.readFileAlloc("file", testing.allocator, .limited(max_file_size));
|
||||
const actual_file_contents = try worktree.dir.readFileAlloc(io, "file", testing.allocator, .limited(max_file_size));
|
||||
defer testing.allocator.free(actual_file_contents);
|
||||
try testing.expectEqualStrings(expected_file_contents, actual_file_contents);
|
||||
}
|
||||
|
||||
+2
-2
@@ -624,12 +624,12 @@ pub const File = struct {
|
||||
try emit.root_dir.handle.rename(tmp_sub_path, emit.root_dir.handle, emit.sub_path, io);
|
||||
switch (builtin.os.tag) {
|
||||
.linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| {
|
||||
log.warn("ptrace failure: {s}", .{@errorName(err)});
|
||||
log.warn("ptrace failure: {t}", .{err});
|
||||
},
|
||||
.maccatalyst, .macos => {
|
||||
const macho_file = base.cast(.macho).?;
|
||||
macho_file.ptraceAttach(pid) catch |err| {
|
||||
log.warn("attaching failed with error: {s}", .{@errorName(err)});
|
||||
log.warn("attaching failed with error: {t}", .{err});
|
||||
};
|
||||
},
|
||||
.windows => unreachable,
|
||||
|
||||
+5
-3
@@ -4347,11 +4347,13 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi
|
||||
defer arena_allocator.deinit();
|
||||
const arena = arena_allocator.allocator();
|
||||
|
||||
const io = comp.io;
|
||||
|
||||
const sdk_dir = switch (sdk_layout) {
|
||||
.sdk => comp.sysroot.?,
|
||||
.vendored => fs.path.join(arena, &.{ comp.dirs.zig_lib.path.?, "libc", "darwin" }) catch return null,
|
||||
};
|
||||
if (readSdkVersionFromSettings(arena, sdk_dir)) |ver| {
|
||||
if (readSdkVersionFromSettings(arena, io, sdk_dir)) |ver| {
|
||||
return parseSdkVersion(ver);
|
||||
} else |_| {
|
||||
// Read from settings should always succeed when vendored.
|
||||
@@ -4374,9 +4376,9 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi
|
||||
// Official Apple SDKs ship with a `SDKSettings.json` located at the top of SDK fs layout.
|
||||
// Use property `MinimalDisplayName` to determine version.
|
||||
// The file/property is also available with vendored libc.
|
||||
fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 {
|
||||
fn readSdkVersionFromSettings(arena: Allocator, io: Io, dir: []const u8) ![]const u8 {
|
||||
const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" });
|
||||
const contents = try Io.Dir.cwd().readFileAlloc(sdk_path, arena, .limited(std.math.maxInt(u16)));
|
||||
const contents = try Io.Dir.cwd().readFileAlloc(io, sdk_path, arena, .limited(std.math.maxInt(u16)));
|
||||
const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{});
|
||||
if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string;
|
||||
return error.SdkVersionFailure;
|
||||
|
||||
@@ -17,6 +17,12 @@ const MachO = @import("../MachO.zig");
|
||||
|
||||
const hash_size = Sha256.digest_length;
|
||||
|
||||
page_size: u16,
|
||||
code_directory: CodeDirectory,
|
||||
requirements: ?Requirements = null,
|
||||
entitlements: ?Entitlements = null,
|
||||
signature: ?Signature = null,
|
||||
|
||||
const Blob = union(enum) {
|
||||
code_directory: *CodeDirectory,
|
||||
requirements: *Requirements,
|
||||
@@ -220,12 +226,6 @@ const Signature = struct {
|
||||
}
|
||||
};
|
||||
|
||||
page_size: u16,
|
||||
code_directory: CodeDirectory,
|
||||
requirements: ?Requirements = null,
|
||||
entitlements: ?Entitlements = null,
|
||||
signature: ?Signature = null,
|
||||
|
||||
pub fn init(page_size: u16) CodeSignature {
|
||||
return .{
|
||||
.page_size = page_size,
|
||||
@@ -246,8 +246,8 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void {
|
||||
const inner = try Io.Dir.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32)));
|
||||
pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, io: Io, path: []const u8) !void {
|
||||
const inner = try Io.Dir.cwd().readFileAlloc(io, path, allocator, .limited(std.math.maxInt(u32)));
|
||||
self.entitlements = .{ .inner = inner };
|
||||
}
|
||||
|
||||
|
||||
+9
-12
@@ -1029,9 +1029,8 @@ fn buildOutputType(
|
||||
if (mem.cutPrefix(u8, arg, "@")) |resp_file_path| {
|
||||
// This is a "compiler response file". We must parse the file and treat its
|
||||
// contents as command line parameters.
|
||||
args_iter.resp_file = initArgIteratorResponseFile(arena, resp_file_path) catch |err| {
|
||||
fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) });
|
||||
};
|
||||
args_iter.resp_file = initArgIteratorResponseFile(arena, io, resp_file_path) catch |err|
|
||||
fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });
|
||||
} else if (mem.startsWith(u8, arg, "-")) {
|
||||
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
||||
try Io.File.stdout().writeAll(usage_build_generic);
|
||||
@@ -5441,7 +5440,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
|
||||
// that are missing.
|
||||
const s = fs.path.sep_str;
|
||||
const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce;
|
||||
const stdout = dirs.local_cache.handle.readFileAlloc(tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| {
|
||||
const stdout = dirs.local_cache.handle.readFileAlloc(io, tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| {
|
||||
fatal("unable to read results of configure phase from '{f}{s}': {s}", .{
|
||||
dirs.local_cache, tmp_sub_path, @errorName(err),
|
||||
});
|
||||
@@ -5822,9 +5821,9 @@ pub fn lldMain(
|
||||
const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, .single_quotes = true });
|
||||
|
||||
/// Initialize the arguments from a Response File. "*.rsp"
|
||||
fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile {
|
||||
fn initArgIteratorResponseFile(allocator: Allocator, io: Io, resp_file_path: []const u8) !ArgIteratorResponseFile {
|
||||
const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit
|
||||
const cmd_line = try Io.Dir.cwd().readFileAlloc(resp_file_path, allocator, .limited(max_bytes));
|
||||
const cmd_line = try Io.Dir.cwd().readFileAlloc(io, resp_file_path, allocator, .limited(max_bytes));
|
||||
errdefer allocator.free(cmd_line);
|
||||
|
||||
return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line);
|
||||
@@ -5952,7 +5951,7 @@ pub const ClangArgIterator = struct {
|
||||
};
|
||||
}
|
||||
|
||||
fn next(self: *ClangArgIterator) !void {
|
||||
fn next(self: *ClangArgIterator, io: Io) !void {
|
||||
assert(self.has_next);
|
||||
assert(self.next_index < self.argv.len);
|
||||
// In this state we know that the parameter we are looking at is a root parameter
|
||||
@@ -5970,10 +5969,8 @@ pub const ClangArgIterator = struct {
|
||||
const arena = self.arena;
|
||||
const resp_file_path = arg[1..];
|
||||
|
||||
self.arg_iterator_response_file =
|
||||
initArgIteratorResponseFile(arena, resp_file_path) catch |err| {
|
||||
fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) });
|
||||
};
|
||||
self.arg_iterator_response_file = initArgIteratorResponseFile(arena, io, resp_file_path) catch |err|
|
||||
fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err });
|
||||
// NOTE: The ArgIteratorResponseFile returns tokens from next() that are slices of an
|
||||
// internal buffer. This internal buffer is arena allocated, so it is not cleaned up here.
|
||||
|
||||
@@ -7405,7 +7402,7 @@ const Templates = struct {
|
||||
}
|
||||
|
||||
const max_bytes = 10 * 1024 * 1024;
|
||||
const contents = templates.dir.readFileAlloc(template_path, arena, .limited(max_bytes)) catch |err| {
|
||||
const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| {
|
||||
fatal("unable to read template file '{s}': {t}", .{ template_path, err });
|
||||
};
|
||||
templates.buffer.clearRetainingCapacity();
|
||||
|
||||
Reference in New Issue
Block a user