diff options
author | 2021-11-16 15:03:11 -0800 | |
---|---|---|
committer | 2021-12-16 19:18:51 -0800 | |
commit | 48b9af129832e0003f0de3086c1ef63bb27feb53 (patch) | |
tree | 44aa2cb136e5b6ce33a972d777958e12ebae6a7d | |
parent | cec59bc58085a862c867264b594f1be3350f1b8c (diff) | |
download | bun-48b9af129832e0003f0de3086c1ef63bb27feb53.tar.gz bun-48b9af129832e0003f0de3086c1ef63bb27feb53.tar.zst bun-48b9af129832e0003f0de3086c1ef63bb27feb53.zip |
[bun install] Track build/pre tags with a bitset
-rw-r--r-- | src/install/semver.zig | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/install/semver.zig b/src/install/semver.zig index af68ec495..2ec7e04d3 100644 --- a/src/install/semver.zig +++ b/src/install/semver.zig @@ -385,6 +385,7 @@ pub const Version = extern struct { } const tag_result = Tag.parse(allocator, sliced_string.sub(input[part_start_i..])); result.version.tag = tag_result.tag; + i += tag_result.len; break; }, 'x', '*', 'X' => { @@ -683,8 +684,14 @@ pub const Query = struct { tail: ?*List = null, allocator: *std.mem.Allocator, input: string = "", - has_pre: bool = false, - has_post: bool = false, + + flags: FlagsBitSet = FlagsBitSet.initEmpty(), + pub const Flags = struct { + pub const pre = 1; + pub const build = 0; + }; + + pub const FlagsBitSet = std.bit_set.IntegerBitSet(3); pub fn orVersion(self: *Group, version: Version) !void { if (self.tail == null and !self.head.head.range.hasLeft()) { @@ -982,6 +989,9 @@ pub const Query = struct { if (!skip_round) { const parse_result = Version.parse(SlicedString.init(input, input[i..]), allocator); + if (parse_result.version.tag.hasBuild()) list.flags.setValue(Group.Flags.build, true); + if (parse_result.version.tag.hasPre()) list.flags.setValue(Group.Flags.pre, true); + token.wildcard = parse_result.wildcard; i += parse_result.stopped_at; @@ -1014,6 +1024,8 @@ pub const Query = struct { if (hyphenate) { var second_version = Version.parse(SlicedString.init(input, input[i..]), allocator); + if (second_version.version.tag.hasBuild()) list.flags.setValue(Group.Flags.build, true); + if (second_version.version.tag.hasPre()) list.flags.setValue(Group.Flags.pre, true); const range: Range = brk: { switch (second_version.wildcard) { @@ -1231,6 +1243,17 @@ test "Version parsing" { { var v = Version{ + .major = 0, + .minor = 21, + .patch = 0, + }; + var input: string = "0.21.0-beta-96ca8d915-20211115"; + v.tag.pre = SlicedString.init(input, input["0.21.0-".len..]).external(); + expect.versionT(input, v, @src()); + } + + { + var v = Version{ .major = 1, .minor = 0, .patch = 0, |