Skip to content

Commit

Permalink
provide build_runner command on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
leecannon committed Aug 3, 2022
1 parent f2315e0 commit 29c4f2f
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,40 @@ fn loadPackages(context: LoadPackagesContext) !void {
defer if (context.build_file_path == null) allocator.free(build_file_path);
const directory_path = build_file_path[0 .. build_file_path.len - "build.zig".len];

const args: []const []const u8 = &[_][]const u8{
zig_exe_path,
"run",
build_runner_path,
"--cache-dir",
build_runner_cache_path,
"--pkg-begin",
"@build@",
build_file_path,
"--pkg-end",
"--",
zig_exe_path,
directory_path,
context.cache_root,
context.global_cache_root,
};

errdefer blk: {
const joined = std.mem.join(allocator, " ", args) catch break :blk;
defer allocator.free(joined);

log.err(
"Failed to execute build runner to collect packages, command:\n{s}",
.{joined},
);
std.io.getStdErr().writer().print(
"Failed to execute build runner to collect packages, command:\n{s}\n",
.{joined},
) catch {};
}

const zig_run_result = try std.ChildProcess.exec(.{
.allocator = allocator,
.argv = &[_][]const u8{
zig_exe_path,
"run",
build_runner_path,
"--cache-dir",
build_runner_cache_path,
"--pkg-begin",
"@build@",
build_file_path,
"--pkg-end",
"--",
zig_exe_path,
directory_path,
context.cache_root,
context.global_cache_root,
},
.argv = args,
});

defer {
Expand Down Expand Up @@ -271,7 +287,7 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: [:0]u8) anyerror!*Ha
.cache_root = self.zig_cache_root,
.global_cache_root = self.zig_global_cache_root,
}) catch |err| {
log.warn("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
log.err("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
};

try self.build_files.append(self.allocator, build_file);
Expand Down Expand Up @@ -540,7 +556,7 @@ pub fn applySave(self: *DocumentStore, handle: *Handle) !void {
.cache_root = self.zig_cache_root,
.global_cache_root = self.zig_global_cache_root,
}) catch |err| {
log.warn("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
log.err("Failed to load packages of build file {s} (error: {})", .{ build_file.uri, err });
};
}
}
Expand Down

0 comments on commit 29c4f2f

Please sign in to comment.