authorgravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2023-06-25 23:35:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-26 15:59:53-07:00
logbbda053f9e309128ee4b2eb1a5b886aeb30fcabf
tree9ad13aa9708562f57e67a09ba934d13fb6098ec6
parent7322aa118376a635ab077ca833dd152639953337

Build: make `InstallDirStep` use a `FileSource`

Closes #16187

4 files changed, 16 insertions(+), 13 deletions(-)

build.zig+1-1
......@@ -105,7 +105,7 @@ pub fn build(b: *std.Build) !void {
105105
106106 if (!skip_install_lib_files) {
107107 b.installDirectory(InstallDirectoryOptions{
108 .source_dir = "lib",
108 .source_dir = .{ .path = "lib" },
109109 .install_dir = .lib,
110110 .install_subdir = "zig",
111111 .exclude_extensions = &[_][]const u8{
lib/std/Build.zig+1-3
......@@ -1317,9 +1317,7 @@ pub fn addInstallFileWithDir(
13171317}
13181318
13191319pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir {
1320 const install_step = self.allocator.create(Step.InstallDir) catch @panic("OOM");
1321 install_step.* = Step.InstallDir.init(self, options);
1322 return install_step;
1320 return Step.InstallDir.create(self, options);
13231321}
13241322
13251323pub fn addCheckFile(
lib/std/Build/Step/Compile.zig+1-1
......@@ -564,7 +564,7 @@ pub fn installHeadersDirectory(
564564 dest_rel_path: []const u8,
565565) void {
566566 return installHeadersDirectoryOptions(a, .{
567 .source_dir = src_dir_path,
567 .source_dir = .{ .path = src_dir_path },
568568 .install_dir = .header,
569569 .install_subdir = dest_rel_path,
570570 });
lib/std/Build/Step/InstallDir.zig+13-8
......@@ -2,6 +2,7 @@ const std = @import("std");
22const mem = std.mem;
33const fs = std.fs;
44const Step = std.Build.Step;
5const FileSource = std.Build.FileSource;
56const InstallDir = std.Build.InstallDir;
67const InstallDirStep = @This();
78
......@@ -14,7 +15,7 @@ dest_builder: *std.Build,
1415pub const base_id = .install_dir;
1516
1617pub const Options = struct {
17 source_dir: []const u8,
18 source_dir: FileSource,
1819 install_dir: InstallDir,
1920 install_subdir: []const u8,
2021 /// File paths which end in any of these suffixes will be excluded
......@@ -29,7 +30,7 @@ pub const Options = struct {
2930
3031 fn dupe(self: Options, b: *std.Build) Options {
3132 return .{
32 .source_dir = b.dupe(self.source_dir),
33 .source_dir = self.source_dir.dupe(b),
3334 .install_dir = self.install_dir.dupe(b),
3435 .install_subdir = b.dupe(self.install_subdir),
3536 .exclude_extensions = b.dupeStrings(self.exclude_extensions),
......@@ -38,18 +39,21 @@ pub const Options = struct {
3839 }
3940};
4041
41pub fn init(owner: *std.Build, options: Options) InstallDirStep {
42pub fn create(owner: *std.Build, options: Options) *InstallDirStep {
4243 owner.pushInstalledFile(options.install_dir, options.install_subdir);
43 return .{
44 const self = owner.allocator.create(InstallDirStep) catch @panic("OOM");
45 self.* = .{
4446 .step = Step.init(.{
4547 .id = .install_dir,
46 .name = owner.fmt("install {s}/", .{options.source_dir}),
48 .name = owner.fmt("install {s}/", .{options.source_dir.getDisplayName()}),
4749 .owner = owner,
4850 .makeFn = make,
4951 }),
5052 .options = options.dupe(owner),
5153 .dest_builder = owner,
5254 };
55 options.source_dir.addStepDependencies(&self.step);
56 return self;
5357}
5458
5559fn make(step: *Step, prog_node: *std.Progress.Node) !void {
......@@ -59,9 +63,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
5963 const arena = dest_builder.allocator;
6064 const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
6165 const src_builder = self.step.owner;
62 var src_dir = src_builder.build_root.handle.openIterableDir(self.options.source_dir, .{}) catch |err| {
66 const src_dir_path = self.options.source_dir.getPath2(src_builder, step);
67 var src_dir = src_builder.build_root.handle.openIterableDir(src_dir_path, .{}) catch |err| {
6368 return step.fail("unable to open source directory '{}{s}': {s}", .{
64 src_builder.build_root, self.options.source_dir, @errorName(err),
69 src_builder.build_root, src_dir_path, @errorName(err),
6570 });
6671 };
6772 defer src_dir.close();
......@@ -75,7 +80,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
7580 }
7681
7782 // relative to src build root
78 const src_sub_path = try fs.path.join(arena, &.{ self.options.source_dir, entry.path });
83 const src_sub_path = try fs.path.join(arena, &.{ src_dir_path, entry.path });
7984 const dest_path = try fs.path.join(arena, &.{ dest_prefix, entry.path });
8085 const cwd = fs.cwd();
8186