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 {...@@ -105,7 +105,7 @@ pub fn build(b: *std.Build) !void {
105105
106 if (!skip_install_lib_files) {106 if (!skip_install_lib_files) {
107 b.installDirectory(InstallDirectoryOptions{107 b.installDirectory(InstallDirectoryOptions{
108 .source_dir = "lib",108 .source_dir = .{ .path = "lib" },
109 .install_dir = .lib,109 .install_dir = .lib,
110 .install_subdir = "zig",110 .install_subdir = "zig",
111 .exclude_extensions = &[_][]const u8{111 .exclude_extensions = &[_][]const u8{
lib/std/Build.zig+1-3
...@@ -1317,9 +1317,7 @@ pub fn addInstallFileWithDir(...@@ -1317,9 +1317,7 @@ pub fn addInstallFileWithDir(
1317}1317}
13181318
1319pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir {1319pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir {
1320 const install_step = self.allocator.create(Step.InstallDir) catch @panic("OOM");1320 return Step.InstallDir.create(self, options);
1321 install_step.* = Step.InstallDir.init(self, options);
1322 return install_step;
1323}1321}
13241322
1325pub fn addCheckFile(1323pub fn addCheckFile(
lib/std/Build/Step/Compile.zig+1-1
...@@ -564,7 +564,7 @@ pub fn installHeadersDirectory(...@@ -564,7 +564,7 @@ pub fn installHeadersDirectory(
564 dest_rel_path: []const u8,564 dest_rel_path: []const u8,
565) void {565) void {
566 return installHeadersDirectoryOptions(a, .{566 return installHeadersDirectoryOptions(a, .{
567 .source_dir = src_dir_path,567 .source_dir = .{ .path = src_dir_path },
568 .install_dir = .header,568 .install_dir = .header,
569 .install_subdir = dest_rel_path,569 .install_subdir = dest_rel_path,
570 });570 });
lib/std/Build/Step/InstallDir.zig+13-8
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const mem = std.mem;2const mem = std.mem;
3const fs = std.fs;3const fs = std.fs;
4const Step = std.Build.Step;4const Step = std.Build.Step;
5const FileSource = std.Build.FileSource;
5const InstallDir = std.Build.InstallDir;6const InstallDir = std.Build.InstallDir;
6const InstallDirStep = @This();7const InstallDirStep = @This();
78
...@@ -14,7 +15,7 @@ dest_builder: *std.Build,...@@ -14,7 +15,7 @@ dest_builder: *std.Build,
14pub const base_id = .install_dir;15pub const base_id = .install_dir;
1516
16pub const Options = struct {17pub 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 excluded21 /// 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 {
2930
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};
4041
41pub fn init(owner: *std.Build, options: Options) InstallDirStep {42pub 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}
5458
55fn make(step: *Step, prog_node: *std.Progress.Node) !void {59fn 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 }
7681
77 // relative to src build root82 // 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();
8186