|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | import * as os from "os"; |
16 | | -import * as utils from "./utils"; |
17 | 16 |
|
18 | 17 | export class PlatformInformation { |
19 | | - public static GetPlatformInformation(): Promise<PlatformInformation> { |
| 18 | + public static GetPlatformInformation(): PlatformInformation { |
20 | 19 | const platform: string = os.platform(); |
21 | | - let architecturePromise: Promise<string>; |
| 20 | + const arch = os.arch(); |
22 | 21 |
|
| 22 | + // Map os.arch() values to expected architecture strings |
| 23 | + let architecture: string; |
23 | 24 | switch (platform) { |
24 | 25 | case "win32": |
25 | | - architecturePromise = PlatformInformation.GetWindowsArchitecture(); |
| 26 | + if (arch === "x64") { |
| 27 | + architecture = "x86_x64"; |
| 28 | + } else if (arch === "ia32") { |
| 29 | + architecture = "x86"; |
| 30 | + } else { |
| 31 | + architecture = "Unknown"; |
| 32 | + } |
26 | 33 | break; |
27 | 34 | case "linux": |
28 | | - architecturePromise = PlatformInformation.GetUnixArchitecture(); |
29 | | - break; |
30 | 35 | case "darwin": |
31 | | - architecturePromise = PlatformInformation.GetUnixArchitecture(); |
| 36 | + if (arch === "x64") { |
| 37 | + architecture = "x64"; |
| 38 | + } else if (arch === "ia32") { |
| 39 | + architecture = "x86"; |
| 40 | + } else if (arch === "arm64") { |
| 41 | + architecture = "arm64"; |
| 42 | + } else if (arch === "arm") { |
| 43 | + architecture = "armhf"; |
| 44 | + } else { |
| 45 | + architecture = arch; |
| 46 | + } |
| 47 | + break; |
32 | 48 | default: |
| 49 | + architecture = "Unknown"; |
33 | 50 | break; |
34 | 51 | } |
35 | | - return Promise.all<string>([architecturePromise]).then(([architecture]) => { |
36 | | - return new PlatformInformation(platform, architecture); |
37 | | - }); |
| 52 | + |
| 53 | + return new PlatformInformation(platform, architecture); |
38 | 54 | } |
39 | 55 |
|
40 | 56 | public get platformToUse(): string { |
@@ -75,48 +91,5 @@ export class PlatformInformation { |
75 | 91 | } |
76 | 92 | } |
77 | 93 |
|
78 | | - public static GetUnknownArchitecture(): string { |
79 | | - return "Unknown"; |
80 | | - } |
81 | | - |
82 | | - public static GetUnixArchitecture(): Promise<string> { |
83 | | - const command = "uname"; |
84 | | - const args = ["-m"]; |
85 | | - return utils |
86 | | - .execChildProcess(command, args, utils.extensionContext.extensionPath) |
87 | | - .then((architecture) => { |
88 | | - if (architecture) { |
89 | | - return architecture.trim(); |
90 | | - } |
91 | | - }); |
92 | | - } |
93 | | - |
94 | | - private static GetWindowsArchitecture(): Promise<string> { |
95 | | - const command = "powershell"; |
96 | | - const args = [ |
97 | | - "-executionPolicy", |
98 | | - "bypass", |
99 | | - "(Get-WmiObject Win32_OperatingSystem).OSArchitecture", |
100 | | - ]; |
101 | | - return utils |
102 | | - .execChildProcess(command, args, utils.extensionContext.extensionPath) |
103 | | - .then((architecture) => { |
104 | | - if (architecture) { |
105 | | - const archArray: string[] = architecture.split(os.EOL); |
106 | | - if (archArray.length > 2) { |
107 | | - const arch: string = archArray[1].trim(); |
108 | | - if (arch.indexOf("64") >= 0) { |
109 | | - return "x86_x64"; |
110 | | - } else if (arch.indexOf("32") >= 0) { |
111 | | - return "x86"; |
112 | | - } |
113 | | - } |
114 | | - } |
115 | | - return PlatformInformation.GetUnknownArchitecture(); |
116 | | - }) |
117 | | - .catch((err) => { |
118 | | - return PlatformInformation.GetUnknownArchitecture(); |
119 | | - }); |
120 | | - } |
121 | 94 | constructor(public platform: string, public architecture: string) {} |
122 | 95 | } |
0 commit comments