initial cut of VersionStep - implementation TBD

This commit is contained in:
Emil Lerch 2022-01-12 12:21:28 -08:00
parent 87323ecb71
commit 3bf6adc13e
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
3 changed files with 44 additions and 2 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ demo
src/models/
smithy/zig-out/
libs/
src/git_version.zig

37
VersionStep.zig Normal file
View File

@ -0,0 +1,37 @@
//! Publish Date: 2022-01-12
//! This file is hosted at ??? and is meant to be copied
//! to projects that use it. Sample usage:
//!
//! ??
//! ??
const std = @import("std");
const Step = @This();
step: std.build.Step,
builder: *std.build.Builder,
version_path: []const u8,
// Creates a step that will add the git version info in a file in src/
// so it can be consumed by additional code. If version_path is not specified,
// it will default to "git_version.zig". This should be part of .gitignore
pub fn create(b: *std.build.Builder, version_path: ?[]const u8) *Step {
var result = b.allocator.create(Step) catch @panic("memory");
result.* = Step{
.step = std.build.Step.init(.custom, "create version file", b.allocator, make),
.builder = b,
.version_path = std.fs.path.resolve(b.allocator, &[_][]const u8{
b.build_root,
"src",
version_path orelse "git_version.zig",
}) catch @panic("memory"),
};
return result;
}
fn make(step: *std.build.Step) !void {
const self = @fieldParentPtr(Step, "step", step);
const file = try std.fs.createFileAbsolute(self.version_path, .{});
defer file.close();
try file.writer().print("pub const version = {s};\n", .{"\"to be implemented\""});
}

View File

@ -3,7 +3,8 @@ const builtin = @import("builtin");
const Builder = @import("std").build.Builder;
const GitRepoStep = @import("GitRepoStep.zig");
const CopyStep = @import("CopyStep.zig");
const @"test" = @import("build_test.zig");
const tst = @import("build_test.zig");
const VersionStep = @import("VersionStep.zig");
pub fn build(b: *Builder) !void {
const zfetch_repo = GitRepoStep.create(b, .{
@ -42,6 +43,8 @@ pub fn build(b: *Builder) !void {
);
copy_deps.step.dependOn(&zfetch_repo.step);
const version = VersionStep.create(b, null);
exe.step.dependOn(&version.step);
exe.step.dependOn(&copy_deps.step);
// This import won't work unless we're already cloned. The way around
@ -60,7 +63,8 @@ pub fn build(b: *Builder) !void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
var test_step = try @"test".addTestStep(b, mode, exe.packages.items);
var test_step = try tst.addTestStep(b, mode, exe.packages.items);
test_step.dependOn(&version.step);
if (target.getOs().tag == .linux) {
// TODO: Support > linux with RunStep