some name shuffling
This commit is contained in:
parent
c391f50197
commit
6c1cfcb2fe
3 changed files with 17 additions and 16 deletions
|
@ -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;
|
||||||
|
|
|
@ -3,9 +3,8 @@ const elphin = @import("elphin");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const file = b.addInstallBinFile(.{ .path = "../testdata/example.elf" }, "lol.elf");
|
const file = b.addInstallBinFile(.{ .path = "../testdata/example.elf" }, "lol.elf");
|
||||||
|
|
||||||
const convert = elphin.buildlib.convertFile(b, "lol.elf", .{});
|
|
||||||
|
|
||||||
b.getInstallStep().dependOn(&file.step);
|
b.getInstallStep().dependOn(&file.step);
|
||||||
|
|
||||||
|
const convert = elphin.convertInstalled(b, "lol.elf", .{});
|
||||||
b.getInstallStep().dependOn(&convert.step);
|
b.getInstallStep().dependOn(&convert.step);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,17 @@ step: std.Build.Step,
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
options: ConvertFileOptions,
|
options: ConvertFileOptions,
|
||||||
|
|
||||||
pub fn convertFile(b: *std.Build, file: []const u8, options: ConvertFileOptions) *Self {
|
pub fn convertExecutable(b: *std.Build, artifact: *std.Build.Step.Compile, options: ConvertFileOptions) *Self {
|
||||||
const convert = b.step("convert", "Converts the compiled .elf file into .dol");
|
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");
|
const self = b.allocator.create(Self) catch @panic("OOM");
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.step = std.Build.Step.init(.{
|
.step = std.Build.Step.init(.{
|
||||||
|
@ -27,8 +35,6 @@ pub fn convertFile(b: *std.Build, file: []const u8, options: ConvertFileOptions)
|
||||||
.options = options,
|
.options = options,
|
||||||
};
|
};
|
||||||
|
|
||||||
convert.dependOn(&self.step);
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,18 +42,13 @@ fn make(step: *std.Build.Step, _: *std.Progress.Node) !void {
|
||||||
const self: *Self = @fieldParentPtr("step", step);
|
const self: *Self = @fieldParentPtr("step", step);
|
||||||
const b = step.owner;
|
const b = step.owner;
|
||||||
|
|
||||||
// Get input path
|
|
||||||
const inputPath = b.getInstallPath(self.options.installDir, self.path);
|
|
||||||
|
|
||||||
// Read input
|
// Read input
|
||||||
const input = try std.fs.cwd().openFile(inputPath, .{});
|
const input = try std.fs.cwd().openFile(self.path, .{});
|
||||||
defer input.close();
|
defer input.close();
|
||||||
|
|
||||||
// Get output path or calculate it from the input
|
// Get output path or calculate it from the input
|
||||||
const destination = if (self.options.filename) |name|
|
const name = self.options.filename orelse calculateOutputName(b, std.fs.path.basename(self.path));
|
||||||
b.getInstallPath(self.options.installDir, name)
|
const destination = b.getInstallPath(self.options.installDir, name);
|
||||||
else
|
|
||||||
calculateOutputName(b, inputPath);
|
|
||||||
|
|
||||||
// Create output file
|
// Create output file
|
||||||
const output = try std.fs.cwd().createFile(destination, .{});
|
const output = try std.fs.cwd().createFile(destination, .{});
|
||||||
|
|
Loading…
Reference in a new issue