build: handle null install_prefix correctly

This commit is contained in:
Isaac Freund 2021-03-22 11:54:02 +01:00
parent 8627a2feff
commit 6438f193ae
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
2 changed files with 16 additions and 12 deletions

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const fs = std.fs;
const zbs = std.build; const zbs = std.build;
const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep; const ScanProtocolsStep = @import("deps/zig-wayland/build.zig").ScanProtocolsStep;
@ -45,16 +46,19 @@ pub fn build(b: *zbs.Builder) !void {
const examples = b.option(bool, "examples", "Set to true to build examples") orelse false; const examples = b.option(bool, "examples", "Set to true to build examples") orelse false;
const resolved_prefix = try std.fs.path.resolve(b.allocator, &[_][]const u8{b.install_prefix.?}); const rel_config_path = blk: {
const rel_config_path = if (std.mem.eql(u8, resolved_prefix, "/usr")) if (b.install_prefix) |prefix| {
"../etc/river/init" if (std.mem.eql(u8, try fs.path.resolve(b.allocator, &[_][]const u8{prefix}), "/usr")) {
else break :blk "../etc/river/init";
"etc/river/init"; }
}
break :blk "etc/river/init";
};
b.installFile("example/init", rel_config_path); b.installFile("example/init", rel_config_path);
const default_config_path = try std.fs.path.resolve( const abs_config_path = try fs.path.resolve(b.allocator, &[_][]const u8{
b.allocator, b.install_prefix orelse b.cache_root,
&[_][]const u8{ resolved_prefix, rel_config_path }, rel_config_path,
); });
const scanner = ScanProtocolsStep.create(b); const scanner = ScanProtocolsStep.create(b);
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
@ -72,7 +76,7 @@ pub fn build(b: *zbs.Builder) !void {
river.setTarget(target); river.setTarget(target);
river.setBuildMode(mode); river.setBuildMode(mode);
river.addBuildOption(bool, "xwayland", xwayland); river.addBuildOption(bool, "xwayland", xwayland);
river.addBuildOption([]const u8, "default_config_path", default_config_path); river.addBuildOption([]const u8, "default_config_path", abs_config_path);
addServerDeps(river, scanner); addServerDeps(river, scanner);
@ -229,7 +233,7 @@ const ScdocStep = struct {
for (scd_paths) |path| { for (scd_paths) |path| {
const path_no_ext = path[0..(path.len - 4)]; const path_no_ext = path[0..(path.len - 4)];
const basename_no_ext = std.fs.path.basename(path_no_ext); const basename_no_ext = fs.path.basename(path_no_ext);
const section = path_no_ext[(path_no_ext.len - 1)..]; const section = path_no_ext[(path_no_ext.len - 1)..];
const output = try std.fmt.allocPrint( const output = try std.fmt.allocPrint(

2
deps/zig-wayland vendored

@ -1 +1 @@
Subproject commit 5def9c58107c4803847e37511d16c15ff294b62d Subproject commit f170fe0265dfcea6a00f80691fc9464735734860