lib/tldr/src/profiling/collect/parse/large/config/state.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const collect = @import("../../../root.zig");
 2 const collect_base = collect.base;
 3 const std = collect_base.std;
 4 const discover = collect_base.discover;
 5 
 6 const model = collect.model;
 7 const large = @import("../root.zig");
 8 
 9 pub const State = struct {
10     config: model.CollectLargeConfig = .{},
11     inputs: std.ArrayList(model.CollectLargeInput) = .empty,
12     relink_replacements: std.ArrayList(model.RelinkReplacement) = .empty,
13     build_arguments: std.ArrayList([]const u8) = .empty,
14     run_command: std.ArrayList([]const u8) = .empty,
15     tags: std.ArrayList([]const u8) = .empty,
16     product_stages: std.ArrayList([]const u8) = .empty,
17 };
18 
19 pub fn finish(allocator: model.Allocator, state: *State) !model.CollectLargeConfig {
20     const name = state.config.name orelse return error.InvalidArguments;
21     if (!large.safeCollectLargeName(name)) return error.InvalidArguments;
22     if (state.config.response == null) return error.InvalidArguments;
23     if (state.config.response_cwd != null and !state.config.copy_response_inputs) return error.InvalidArguments;
24     if (state.config.rewrite_absolute_inputs and !state.config.copy_response_inputs) return error.InvalidArguments;
25     if (state.config.copy_static_library_inputs and !state.config.copy_response_inputs) return error.InvalidArguments;
26     if (state.config.copy_dynamic_library_inputs and !state.config.copy_response_inputs) return error.InvalidArguments;
27     if (!large.validCollectLargeKind(state.config.kind)) return error.InvalidArguments;
28     _ = discover.Platform.parse(state.config.platform) orelse return error.InvalidArguments;
29     if (!large.validIncrementalState(state.config.incremental_state)) return error.InvalidArguments;
30     state.config.inputs = try state.inputs.toOwnedSlice(allocator);
31     state.config.relink_replacements = try state.relink_replacements.toOwnedSlice(allocator);
32     state.config.build_arguments = try state.build_arguments.toOwnedSlice(allocator);
33     state.config.run_command = try state.run_command.toOwnedSlice(allocator);
34     if (state.tags.items.len != 0) state.config.tags = try state.tags.toOwnedSlice(allocator);
35     if (state.product_stages.items.len != 0) state.config.product_stages = try state.product_stages.toOwnedSlice(allocator);
36     return state.config;
37 }