| ... | ... | @@ -24,7 +24,7 @@ const product_version_max_length = version_major_minor_max_length + ".65535".len |
| 24 | 24 | /// Find path and version of Windows 10 SDK and Windows 8.1 SDK, and find path to MSVC's `lib/` directory. |
| 25 | 25 | /// Caller owns the result's fields. |
| 26 | 26 | /// Returns memory allocated by `gpa` |
| 27 | | pub fn find(gpa: Allocator, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk { |
| 27 | pub fn find(gpa: Allocator, io: Io, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFound, PathTooLong }!WindowsSdk { |
| 28 | 28 | if (builtin.os.tag != .windows) return error.NotFound; |
| 29 | 29 | |
| 30 | 30 | //note(dimenus): If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed |
| ... | ... | @@ -33,7 +33,7 @@ pub fn find(gpa: Allocator, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFo |
| 33 | 33 | }; |
| 34 | 34 | defer roots_key.closeKey(); |
| 35 | 35 | |
| 36 | | const windows10sdk = Installation.find(gpa, roots_key, "KitsRoot10", "", "v10.0") catch |err| switch (err) { |
| 36 | const windows10sdk = Installation.find(gpa, io, roots_key, "KitsRoot10", "", "v10.0") catch |err| switch (err) { |
| 37 | 37 | error.InstallationNotFound => null, |
| 38 | 38 | error.PathTooLong => null, |
| 39 | 39 | error.VersionTooLong => null, |
| ... | ... | @@ -41,7 +41,7 @@ pub fn find(gpa: Allocator, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFo |
| 41 | 41 | }; |
| 42 | 42 | errdefer if (windows10sdk) |*w| w.free(gpa); |
| 43 | 43 | |
| 44 | | const windows81sdk = Installation.find(gpa, roots_key, "KitsRoot81", "winver", "v8.1") catch |err| switch (err) { |
| 44 | const windows81sdk = Installation.find(gpa, io, roots_key, "KitsRoot81", "winver", "v8.1") catch |err| switch (err) { |
| 45 | 45 | error.InstallationNotFound => null, |
| 46 | 46 | error.PathTooLong => null, |
| 47 | 47 | error.VersionTooLong => null, |
| ... | ... | @@ -49,7 +49,7 @@ pub fn find(gpa: Allocator, arch: std.Target.Cpu.Arch) error{ OutOfMemory, NotFo |
| 49 | 49 | }; |
| 50 | 50 | errdefer if (windows81sdk) |*w| w.free(gpa); |
| 51 | 51 | |
| 52 | | const msvc_lib_dir: ?[]const u8 = MsvcLibDir.find(gpa, arch) catch |err| switch (err) { |
| 52 | const msvc_lib_dir: ?[]const u8 = MsvcLibDir.find(gpa, io, arch) catch |err| switch (err) { |
| 53 | 53 | error.MsvcLibDirNotFound => null, |
| 54 | 54 | error.OutOfMemory => return error.OutOfMemory, |
| 55 | 55 | }; |
| ... | ... | @@ -80,6 +80,7 @@ pub fn free(sdk: WindowsSdk, gpa: Allocator) void { |
| 80 | 80 | fn iterateAndFilterByVersion( |
| 81 | 81 | iterator: *Dir.Iterator, |
| 82 | 82 | gpa: Allocator, |
| 83 | io: Io, |
| 83 | 84 | prefix: []const u8, |
| 84 | 85 | ) error{OutOfMemory}![][]const u8 { |
| 85 | 86 | const Version = struct { |
| ... | ... | @@ -104,7 +105,7 @@ fn iterateAndFilterByVersion( |
| 104 | 105 | dirs.deinit(); |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | | iterate: while (iterator.next() catch null) |entry| { |
| 108 | iterate: while (iterator.next(io) catch null) |entry| { |
| 108 | 109 | if (entry.kind != .directory) continue; |
| 109 | 110 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; |
| 110 | 111 | |
| ... | ... | @@ -420,13 +421,14 @@ pub const Installation = struct { |
| 420 | 421 | /// Caller owns the result's fields. |
| 421 | 422 | fn find( |
| 422 | 423 | gpa: Allocator, |
| 424 | io: Io, |
| 423 | 425 | roots_key: RegistryWtf8, |
| 424 | 426 | roots_subkey: []const u8, |
| 425 | 427 | prefix: []const u8, |
| 426 | 428 | version_key_name: []const u8, |
| 427 | 429 | ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { |
| 428 | 430 | roots: { |
| 429 | | const installation = findFromRoot(gpa, roots_key, roots_subkey, prefix) catch |
| 431 | const installation = findFromRoot(gpa, io, roots_key, roots_subkey, prefix) catch |
| 430 | 432 | break :roots; |
| 431 | 433 | if (installation.isValidVersion()) return installation; |
| 432 | 434 | installation.free(gpa); |
| ... | ... | @@ -485,7 +487,7 @@ pub const Installation = struct { |
| 485 | 487 | defer sdk_lib_dir.close(io); |
| 486 | 488 | |
| 487 | 489 | var iterator = sdk_lib_dir.iterate(); |
| 488 | | const versions = try iterateAndFilterByVersion(&iterator, gpa, prefix); |
| 490 | const versions = try iterateAndFilterByVersion(&iterator, gpa, io, prefix); |
| 489 | 491 | if (versions.len == 0) return error.InstallationNotFound; |
| 490 | 492 | defer { |
| 491 | 493 | for (versions[1..]) |version| gpa.free(version); |
| ... | ... | @@ -673,7 +675,7 @@ const MsvcLibDir = struct { |
| 673 | 675 | // First, try getting the packages cache path from the registry. |
| 674 | 676 | // This only seems to exist when the path is different from the default. |
| 675 | 677 | method1: { |
| 676 | | return findInstancesDirViaSetup(gpa) catch |err| switch (err) { |
| 678 | return findInstancesDirViaSetup(gpa, io) catch |err| switch (err) { |
| 677 | 679 | error.OutOfMemory => |e| return e, |
| 678 | 680 | error.PathNotFound => break :method1, |
| 679 | 681 | }; |
| ... | ... | @@ -766,7 +768,7 @@ const MsvcLibDir = struct { |
| 766 | 768 | |
| 767 | 769 | var latest_version: u64 = 0; |
| 768 | 770 | var instances_dir_it = instances_dir.iterateAssumeFirstIteration(); |
| 769 | | while (instances_dir_it.next() catch return error.PathNotFound) |entry| { |
| 771 | while (instances_dir_it.next(io) catch return error.PathNotFound) |entry| { |
| 770 | 772 | if (entry.kind != .directory) continue; |
| 771 | 773 | |
| 772 | 774 | var writer: Writer = .fixed(&state_subpath_buf); |
| ... | ... | @@ -828,7 +830,7 @@ const MsvcLibDir = struct { |
| 828 | 830 | |
| 829 | 831 | try lib_dir_buf.appendSlice("VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt"); |
| 830 | 832 | var default_tools_version_buf: [512]u8 = undefined; |
| 831 | | const default_tools_version_contents = Dir.cwd().readFile(lib_dir_buf.items, &default_tools_version_buf) catch { |
| 833 | const default_tools_version_contents = Dir.cwd().readFile(io, lib_dir_buf.items, &default_tools_version_buf) catch { |
| 832 | 834 | return error.PathNotFound; |
| 833 | 835 | }; |
| 834 | 836 | var tokenizer = std.mem.tokenizeAny(u8, default_tools_version_contents, " \r\n"); |
| ... | ... | @@ -871,7 +873,7 @@ const MsvcLibDir = struct { |
| 871 | 873 | defer visualstudio_folder.close(io); |
| 872 | 874 | |
| 873 | 875 | var iterator = visualstudio_folder.iterate(); |
| 874 | | break :vs_versions try iterateAndFilterByVersion(&iterator, gpa, ""); |
| 876 | break :vs_versions try iterateAndFilterByVersion(&iterator, gpa, io, ""); |
| 875 | 877 | }; |
| 876 | 878 | defer { |
| 877 | 879 | for (vs_versions) |vs_version| gpa.free(vs_version); |