From 54601e4422ae85508e05e1515e6d301d5b294f1d Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 10 May 2024 21:34:04 +0200 Subject: [PATCH] fix build system --- src/buildlib.zig | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/buildlib.zig b/src/buildlib.zig index 8ef2be3..ed4e639 100644 --- a/src/buildlib.zig +++ b/src/buildlib.zig @@ -47,18 +47,26 @@ fn make(step: *std.Build.Step, _: *std.Progress.Node) !void { // Read input const inputPath = self.path.getPath2(b, step); - const input = try std.fs.cwd().openFile(inputPath, .{}); + const input = try std.fs.openFileAbsolute(inputPath, .{}); defer input.close(); - // Get output path or calculate it from the input - const name = self.options.filename orelse calculateOutputName(b, std.fs.path.basename(inputPath)); - const destination = b.getInstallPath(self.options.installDir, name); + // Create output file next to input + // We could create this directly in its final place but the directory usually + // does not exist at that time and this saves us some fs.makePath shenanigans + const name = calculateOutputName(b, inputPath); // Create output file - const output = try std.fs.cwd().createFile(destination, .{}); + const output = try std.fs.createFileAbsolute(name, .{}); defer output.close(); + // Run conversion try lib.convert(input, output); + + // Copy file to destination + const cwd = std.fs.cwd(); + const finalFilename = self.options.filename orelse std.fs.path.basename(name); + const destination = b.getInstallPath(self.options.installDir, finalFilename); + _ = try cwd.updateFile(name, cwd, destination, .{}); } fn calculateOutputName(b: *std.Build, path: []const u8) []const u8 {