| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | const mem = std.mem; | 2 | const mem = std.mem; |
| 3 | const fs = std.fs; | 3 | const fs = std.fs; |
| 4 | const Step = std.Build.Step; | 4 | const Step = std.Build.Step; |
| | 5 | const FileSource = std.Build.FileSource; |
| 5 | const InstallDir = std.Build.InstallDir; | 6 | const InstallDir = std.Build.InstallDir; |
| 6 | const InstallDirStep = @This(); | 7 | const InstallDirStep = @This(); |
| 7 | | 8 | |
| ... | @@ -14,7 +15,7 @@ dest_builder: *std.Build, | ... | @@ -14,7 +15,7 @@ dest_builder: *std.Build, |
| 14 | pub const base_id = .install_dir; | 15 | pub const base_id = .install_dir; |
| 15 | | 16 | |
| 16 | pub const Options = struct { | 17 | pub const Options = struct { |
| 17 | source_dir: []const u8, | 18 | source_dir: FileSource, |
| 18 | install_dir: InstallDir, | 19 | install_dir: InstallDir, |
| 19 | install_subdir: []const u8, | 20 | install_subdir: []const u8, |
| 20 | /// File paths which end in any of these suffixes will be excluded | 21 | /// File paths which end in any of these suffixes will be excluded |
| ... | @@ -29,7 +30,7 @@ pub const Options = struct { | ... | @@ -29,7 +30,7 @@ pub const Options = struct { |
| 29 | | 30 | |
| 30 | fn dupe(self: Options, b: *std.Build) Options { | 31 | fn dupe(self: Options, b: *std.Build) Options { |
| 31 | return .{ | 32 | return .{ |
| 32 | .source_dir = b.dupe(self.source_dir), | 33 | .source_dir = self.source_dir.dupe(b), |
| 33 | .install_dir = self.install_dir.dupe(b), | 34 | .install_dir = self.install_dir.dupe(b), |
| 34 | .install_subdir = b.dupe(self.install_subdir), | 35 | .install_subdir = b.dupe(self.install_subdir), |
| 35 | .exclude_extensions = b.dupeStrings(self.exclude_extensions), | 36 | .exclude_extensions = b.dupeStrings(self.exclude_extensions), |
| ... | @@ -38,18 +39,21 @@ pub const Options = struct { | ... | @@ -38,18 +39,21 @@ pub const Options = struct { |
| 38 | } | 39 | } |
| 39 | }; | 40 | }; |
| 40 | | 41 | |
| 41 | pub fn init(owner: *std.Build, options: Options) InstallDirStep { | 42 | pub fn create(owner: *std.Build, options: Options) *InstallDirStep { |
| 42 | owner.pushInstalledFile(options.install_dir, options.install_subdir); | 43 | owner.pushInstalledFile(options.install_dir, options.install_subdir); |
| 43 | return .{ | 44 | const self = owner.allocator.create(InstallDirStep) catch @panic("OOM"); |
| | 45 | self.* = .{ |
| 44 | .step = Step.init(.{ | 46 | .step = Step.init(.{ |
| 45 | .id = .install_dir, | 47 | .id = .install_dir, |
| 46 | .name = owner.fmt("install {s}/", .{options.source_dir}), | 48 | .name = owner.fmt("install {s}/", .{options.source_dir.getDisplayName()}), |
| 47 | .owner = owner, | 49 | .owner = owner, |
| 48 | .makeFn = make, | 50 | .makeFn = make, |
| 49 | }), | 51 | }), |
| 50 | .options = options.dupe(owner), | 52 | .options = options.dupe(owner), |
| 51 | .dest_builder = owner, | 53 | .dest_builder = owner, |
| 52 | }; | 54 | }; |
| | 55 | options.source_dir.addStepDependencies(&self.step); |
| | 56 | return self; |
| 53 | } | 57 | } |
| 54 | | 58 | |
| 55 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { | 59 | fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| ... | @@ -59,9 +63,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -59,9 +63,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 59 | const arena = dest_builder.allocator; | 63 | const arena = dest_builder.allocator; |
| 60 | const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir); | 64 | const dest_prefix = dest_builder.getInstallPath(self.options.install_dir, self.options.install_subdir); |
| 61 | const src_builder = self.step.owner; | 65 | 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| { |
| 63 | return step.fail("unable to open source directory '{}{s}': {s}", .{ | 68 | 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), |
| 65 | }); | 70 | }); |
| 66 | }; | 71 | }; |
| 67 | defer src_dir.close(); | 72 | defer src_dir.close(); |
| ... | @@ -75,7 +80,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -75,7 +80,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 75 | } | 80 | } |
| 76 | | 81 | |
| 77 | // relative to src build root | 82 | // 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 }); |
| 79 | const dest_path = try fs.path.join(arena, &.{ dest_prefix, entry.path }); | 84 | const dest_path = try fs.path.join(arena, &.{ dest_prefix, entry.path }); |
| 80 | const cwd = fs.cwd(); | 85 | const cwd = fs.cwd(); |
| 81 | | 86 | |