Add 'build-resource-generation/' from commit '05bb7e2b91130df744f12ffd62f644315b771697'
git-subtree-dir: build-resource-generation git-subtree-mainline:7f29076a93
git-subtree-split:05bb7e2b91
This commit is contained in:
15
build-resource-generation/src/gen.zig
Normal file
15
build-resource-generation/src/gen.zig
Normal file
@@ -0,0 +1,15 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var args = std.process.args();
|
||||
_ = args.skip(); // skip exe
|
||||
|
||||
const out_path = args.next().?;
|
||||
|
||||
var cwd = std.fs.cwd();
|
||||
var out = try cwd.createFile(out_path, .{});
|
||||
defer out.close();
|
||||
|
||||
const now = std.time.timestamp();
|
||||
try out.writer().print("timestamp: {d}", .{now});
|
||||
}
|
54
build-resource-generation/src/main.zig
Normal file
54
build-resource-generation/src/main.zig
Normal file
@@ -0,0 +1,54 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const ally = gpa.allocator();
|
||||
|
||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
try stdout.print("Run `zig build test` to run the tests.\n", .{});
|
||||
|
||||
try bw.flush();
|
||||
|
||||
const exe_dir_path = try std.fs.selfExeDirPathAlloc(ally);
|
||||
defer ally.free(exe_dir_path);
|
||||
|
||||
const res_dir_path = try std.fs.path.resolve(ally, &.{ exe_dir_path, "..", "res" });
|
||||
defer ally.free(res_dir_path);
|
||||
|
||||
// std.debug.print("exe path: '{s}'\n", .{exe_dir_path});
|
||||
|
||||
var res_dir = try std.fs.openDirAbsolute(res_dir_path, .{});
|
||||
defer res_dir.close();
|
||||
|
||||
{
|
||||
var fb = try res_dir.openFile("fizzbuzz", .{});
|
||||
defer fb.close();
|
||||
|
||||
const content = try fb.reader().readAllAlloc(ally, 1024);
|
||||
defer ally.free(content);
|
||||
|
||||
std.debug.print("Read: '{s}'\n", .{content});
|
||||
}
|
||||
|
||||
{
|
||||
var stamp = try res_dir.openFile("foobar", .{});
|
||||
defer stamp.close();
|
||||
|
||||
const content = try stamp.reader().readAllAlloc(ally, 1024);
|
||||
defer ally.free(content);
|
||||
|
||||
std.debug.print("generated foobar: '{s}'\n", .{content});
|
||||
}
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||
defer list.deinit();
|
||||
try list.append(42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
}
|
Reference in New Issue
Block a user