| ... | ... | @@ -3,6 +3,7 @@ const ScannedConfig = @This(); |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const Configuration = std.Build.Configuration; |
| 5 | 5 | const Writer = std.Io.Writer; |
| 6 | const Serializer = std.zon.Serializer; |
| 6 | 7 | |
| 7 | 8 | const Graph = @import("Graph.zig"); |
| 8 | 9 | |
| ... | ... | @@ -10,8 +11,12 @@ configuration: Configuration, |
| 10 | 11 | top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index), |
| 11 | 12 | |
| 12 | 13 | pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 14 | std.log.err("TODO also print paths", .{}); |
| 15 | std.log.err("TODO also print unlazy deps", .{}); |
| 16 | std.log.err("TODO also print system integrations", .{}); |
| 17 | std.log.err("TODO also print available options", .{}); |
| 13 | 18 | const c = &sc.configuration; |
| 14 | | var serializer: std.zon.Serializer = .{ .writer = w }; |
| 19 | var serializer: Serializer = .{ .writer = w }; |
| 15 | 20 | var s = try serializer.beginStruct(.{}); |
| 16 | 21 | |
| 17 | 22 | try s.field("default_step", @intFromEnum(c.default_step), .{}); |
| ... | ... | @@ -27,42 +32,7 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 27 | 32 | var tf = try s.beginTupleField("steps", .{}); |
| 28 | 33 | for (c.steps) |*step| { |
| 29 | 34 | var step_field = try tf.beginStructField(.{}); |
| 30 | | try step_field.field("name", step.name.slice(c), .{}); |
| 31 | | switch (step.owner) { |
| 32 | | .root => try step_field.field("owner", .root, .{}), |
| 33 | | _ => try step_field.field("owner", @intFromEnum(step.owner), .{}), |
| 34 | | } |
| 35 | | { |
| 36 | | var deps_field = try step_field.beginTupleField("deps", .{}); |
| 37 | | for (step.deps.slice(c)) |dep| { |
| 38 | | try deps_field.field(@intFromEnum(dep), .{}); |
| 39 | | } |
| 40 | | try deps_field.end(); |
| 41 | | } |
| 42 | | try step_field.field("max_rss", step.max_rss.toBytes(), .{}); |
| 43 | | switch (step.extended.get(c.extra)) { |
| 44 | | .check_file => try step_field.field("check_file", .TODO, .{}), |
| 45 | | .check_object => try step_field.field("check_object", .TODO, .{}), |
| 46 | | .compile => try step_field.field("compile", .TODO, .{}), |
| 47 | | .config_header => try step_field.field("config_header", .TODO, .{}), |
| 48 | | .fail => try step_field.field("fail", .TODO, .{}), |
| 49 | | .fmt => try step_field.field("fmt", .TODO, .{}), |
| 50 | | .install_artifact => try step_field.field("install_artifact", .TODO, .{}), |
| 51 | | .install_dir => try step_field.field("install_dir", .TODO, .{}), |
| 52 | | .install_file => try step_field.field("install_file", .TODO, .{}), |
| 53 | | .objcopy => try step_field.field("objcopy", .TODO, .{}), |
| 54 | | .options => try step_field.field("options", .TODO, .{}), |
| 55 | | .remove_dir => try step_field.field("remove_dir", .TODO, .{}), |
| 56 | | .run => try step_field.field("run", .TODO, .{}), |
| 57 | | .top_level => |top_level| { |
| 58 | | var sf = try step_field.beginStructField("top_level", .{}); |
| 59 | | try sf.field("description", top_level.description.slice(c), .{}); |
| 60 | | try sf.end(); |
| 61 | | }, |
| 62 | | .translate_c => try step_field.field("translate_c", .TODO, .{}), |
| 63 | | .update_source_files => try step_field.field("update_source_files", .TODO, .{}), |
| 64 | | .write_file => try step_field.field("write_file", .TODO, .{}), |
| 65 | | } |
| 35 | try printStruct(sc, &step_field, Configuration.Step, step); |
| 66 | 36 | try step_field.end(); |
| 67 | 37 | } |
| 68 | 38 | try tf.end(); |
| ... | ... | @@ -71,6 +41,74 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 71 | 41 | try s.end(); |
| 72 | 42 | } |
| 73 | 43 | |
| 44 | fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: *const S) !void { |
| 45 | inline for (@typeInfo(S).@"struct".fields) |field| { |
| 46 | try s.fieldPrefix(field.name); |
| 47 | try printValue(sc, s.container.serializer, field.type, @field(v, field.name)); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, field_value: Field) !void { |
| 52 | const c = &sc.configuration; |
| 53 | switch (Field) { |
| 54 | Configuration.String => { |
| 55 | try s.value(field_value.slice(c), .{}); |
| 56 | }, |
| 57 | Configuration.Deps => { |
| 58 | var deps_field = try s.beginTuple(.{}); |
| 59 | for (field_value.slice(c)) |dep| { |
| 60 | try deps_field.field(@intFromEnum(dep), .{}); |
| 61 | } |
| 62 | try deps_field.end(); |
| 63 | }, |
| 64 | Configuration.MaxRss => { |
| 65 | try s.value(field_value.toBytes(), .{}); |
| 66 | }, |
| 67 | else => switch (@typeInfo(Field)) { |
| 68 | .int => try s.int(field_value), |
| 69 | .@"enum" => { |
| 70 | if (@hasDecl(Field, "storage")) switch (Field.storage) { |
| 71 | .extended => { |
| 72 | var sub_struct = try s.beginStruct(.{}); |
| 73 | try printTaggedUnion(sc, &sub_struct, field_value.get(c.extra)); |
| 74 | try sub_struct.end(); |
| 75 | }, |
| 76 | .flag_optional => comptime unreachable, |
| 77 | } else if (std.enums.tagName(Field, field_value)) |name| { |
| 78 | try s.ident(name); |
| 79 | } else { |
| 80 | try s.int(@intFromEnum(field_value)); |
| 81 | } |
| 82 | }, |
| 83 | .@"struct" => |info| switch (info.layout) { |
| 84 | .@"packed" => { |
| 85 | try s.value(field_value, .{}); |
| 86 | }, |
| 87 | .auto => switch (Field.storage) { |
| 88 | .flag_optional => { |
| 89 | if (field_value.value) |some| { |
| 90 | try printValue(sc, s, Field.Value, some); |
| 91 | } else { |
| 92 | try s.value(null, .{}); |
| 93 | } |
| 94 | }, |
| 95 | .extended => @compileError("TODO"), |
| 96 | }, |
| 97 | else => @compileError("not implemented: " ++ @typeName(Field)), |
| 98 | }, |
| 99 | else => @compileError("not implemented: " ++ @typeName(Field)), |
| 100 | }, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | fn printTaggedUnion(sc: *const ScannedConfig, s: *Serializer.Struct, value: anytype) !void { |
| 105 | switch (value) { |
| 106 | inline else => |*u| { |
| 107 | try printStruct(sc, s, @TypeOf(u.*), u); |
| 108 | }, |
| 109 | } |
| 110 | } |
| 111 | |
| 74 | 112 | pub fn printSteps(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void { |
| 75 | 113 | const arena = graph.arena; |
| 76 | 114 | const c = &sc.configuration; |