DoxigAlpha

parseOs

Function parameters

Parameters

#
result:*Query
diags:*ParseOptions.Diagnostics
text:[]const u8

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
parseCpuArch
Similar to `parse` except instead of fully parsing, it only determines the CPU
parseVersion
Similar to `SemanticVersion.parse`, but with following changes:
serializeCpu
Renders the query into a textual representation that can be parsed via the

Source

Implementation

#
fn parseOs(result: *Query, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
    var it = mem.splitScalar(u8, text, '.');
    const os_name = it.first();
    diags.os_name = os_name;
    const os_is_native = mem.eql(u8, os_name, "native");
    if (!os_is_native) {
        result.os_tag = std.meta.stringToEnum(Target.Os.Tag, os_name) orelse
            return error.UnknownOperatingSystem;
    }
    const tag = result.os_tag orelse builtin.os.tag;
    diags.os_tag = tag;

    const version_text = it.rest();
    if (version_text.len > 0) switch (tag.versionRangeTag()) {
        .none => return error.InvalidOperatingSystemVersion,
        .semver, .hurd, .linux => {
            var range_it = mem.splitSequence(u8, version_text, "...");
            result.os_version_min = .{
                .semver = parseVersion(range_it.first()) catch |err| switch (err) {
                    error.Overflow => return error.InvalidOperatingSystemVersion,
                    error.InvalidVersion => return error.InvalidOperatingSystemVersion,
                },
            };
            if (range_it.next()) |v| {
                result.os_version_max = .{
                    .semver = parseVersion(v) catch |err| switch (err) {
                        error.Overflow => return error.InvalidOperatingSystemVersion,
                        error.InvalidVersion => return error.InvalidOperatingSystemVersion,
                    },
                };
            }
        },
        .windows => {
            var range_it = mem.splitSequence(u8, version_text, "...");
            result.os_version_min = .{
                .windows = try Target.Os.WindowsVersion.parse(range_it.first()),
            };
            if (range_it.next()) |v| {
                result.os_version_max = .{
                    .windows = try Target.Os.WindowsVersion.parse(v),
                };
            }
        },
    };
}