From 6c1cfcb2fe517bad3fef0854ede848221c710910 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 10 May 2024 21:00:16 +0200 Subject: [PATCH] some name shuffling --- build.zig | 3 ++- example-ci/build.zig | 5 ++--- src/buildlib.zig | 25 +++++++++++++------------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/build.zig b/build.zig index 0532729..8e90d11 100644 --- a/build.zig +++ b/build.zig @@ -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; diff --git a/example-ci/build.zig b/example-ci/build.zig index 05e082a..cdf42e4 100644 --- a/example-ci/build.zig +++ b/example-ci/build.zig @@ -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); } diff --git a/src/buildlib.zig b/src/buildlib.zig index 41fa2be..a897508 100644 --- a/src/buildlib.zig +++ b/src/buildlib.zig @@ -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, .{});