some name shuffling

This commit is contained in:
Hamcha 2024-05-10 21:00:16 +02:00
parent c391f50197
commit 6c1cfcb2fe
Signed by: hamcha
GPG key ID: 1669C533B8CF6D89
3 changed files with 17 additions and 16 deletions

View file

@ -46,4 +46,5 @@ pub fn addModule(b: *std.Build) void {
});
}
pub const buildlib = @import("src/buildlib.zig");
pub const convertInstalled = @import("src/buildlib.zig").convertInstalled;
pub const convertExecutable = @import("src/buildlib.zig").convertExecutable;

View file

@ -3,9 +3,8 @@ const elphin = @import("elphin");
pub fn build(b: *std.Build) void {
const file = b.addInstallBinFile(.{ .path = "../testdata/example.elf" }, "lol.elf");
const convert = elphin.buildlib.convertFile(b, "lol.elf", .{});
b.getInstallStep().dependOn(&file.step);
const convert = elphin.convertInstalled(b, "lol.elf", .{});
b.getInstallStep().dependOn(&convert.step);
}

View file

@ -12,9 +12,17 @@ step: std.Build.Step,
path: []const u8,
options: ConvertFileOptions,
pub fn convertFile(b: *std.Build, file: []const u8, options: ConvertFileOptions) *Self {
const convert = b.step("convert", "Converts the compiled .elf file into .dol");
pub fn convertExecutable(b: *std.Build, artifact: *std.Build.Step.Compile, options: ConvertFileOptions) *Self {
const inputPath = artifact.getEmittedBin().getPath(b);
return convertFile(b, inputPath, options);
}
pub fn convertInstalled(b: *std.Build, path: []const u8, options: ConvertFileOptions) *Self {
const inputPath = b.getInstallPath(options.installDir, path);
return convertFile(b, inputPath, options);
}
fn convertFile(b: *std.Build, file: []const u8, options: ConvertFileOptions) *Self {
const self = b.allocator.create(Self) catch @panic("OOM");
self.* = .{
.step = std.Build.Step.init(.{
@ -27,8 +35,6 @@ pub fn convertFile(b: *std.Build, file: []const u8, options: ConvertFileOptions)
.options = options,
};
convert.dependOn(&self.step);
return self;
}
@ -36,18 +42,13 @@ fn make(step: *std.Build.Step, _: *std.Progress.Node) !void {
const self: *Self = @fieldParentPtr("step", step);
const b = step.owner;
// Get input path
const inputPath = b.getInstallPath(self.options.installDir, self.path);
// Read input
const input = try std.fs.cwd().openFile(inputPath, .{});
const input = try std.fs.cwd().openFile(self.path, .{});
defer input.close();
// Get output path or calculate it from the input
const destination = if (self.options.filename) |name|
b.getInstallPath(self.options.installDir, name)
else
calculateOutputName(b, inputPath);
const name = self.options.filename orelse calculateOutputName(b, std.fs.path.basename(self.path));
const destination = b.getInstallPath(self.options.installDir, name);
// Create output file
const output = try std.fs.cwd().createFile(destination, .{});