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