Skip to content

Commit ffba2b4

Browse files
Enable dotnet core installer to work for any architecture (#8721) (#9015)
* Remove preview flags from Go tasks * Use separate config dirs to enable parallel execution of az cli task * enable dotnet core installer for all architectures * use arch for caching and querying * Update minor version # Conflicts: # Tasks/DotNetCoreInstallerV0/task.json # Tasks/DotNetCoreInstallerV0/task.loc.json
1 parent ba56ae3 commit ffba2b4

File tree

6 files changed

+95
-39
lines changed

6 files changed

+95
-39
lines changed

Tasks/DotNetCoreInstallerV0/Tests/InstallWindows.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
2222
"C:\\somedir\\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command & 'C:\\currDir\\externals\\install-dotnet.ps1' -Version 1.0.4 -DryRun -SharedRuntime": {
2323
"code": 0,
2424
"stdout": "dotnet-install: Payload URLs:" + os.EOL + "dotnet-install: Primary - https://primary-runtime-url" + os.EOL + "dotnet-install: Legacy - https://legacy-runtime-url" + os.EOL + "dotnet-install: Repeatable invocation: .\install-dotnet.ps1 -Version 1.1.2 -Channel 1.1 -Architecture x64 -InstallDir <auto>"
25+
},
26+
"C:\\somedir\\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command & 'C:\\currDir\\externals\\get-os-platform.ps1'": {
27+
"code": 0,
28+
"stdout": "Primary: win-x64" + os.EOL,
2529
}
2630
},
2731
"osType": {
@@ -37,7 +41,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
3741

3842
var ut = require('../utilities');
3943
tr.registerMock('./utilities', {
40-
getCurrentDir : function() {
44+
getCurrentDir: function () {
4145
return "C:\\currDir";
4246
},
4347
setFileAttribute: ut.setFileAttribute

Tasks/DotNetCoreInstallerV0/dotnetcoreinstaller.ts

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class DotnetCoreInstaller {
2020
public async install() {
2121
// Check cache
2222
let toolPath: string;
23+
let osSuffixes = this.detectMachineOS();
24+
let parts = osSuffixes[0].split("-");
25+
this.arch = parts.length > 1 ? parts[1] : "x64";
2326
toolPath = this.getLocalTool();
2427

2528
if (!toolPath) {
2629
// download, extract, cache
2730
console.log(tl.loc("InstallingAfresh"));
28-
let osSuffixes = this.detectMachineOS();
2931
console.log(tl.loc("GettingDownloadUrl", this.packageType, this.version));
3032
let downloadUrls = await DotNetCoreReleaseFetcher.getDownloadUrls(osSuffixes, this.version, this.packageType);
3133
toolPath = await this.downloadAndInstall(downloadUrls);
@@ -57,46 +59,52 @@ class DotnetCoreInstaller {
5759

5860
private getLocalTool(): string {
5961
console.log(tl.loc("CheckingToolCache"));
60-
return toolLib.findLocalTool(this.cachedToolName, this.version);
62+
return toolLib.findLocalTool(this.cachedToolName, this.version, this.arch);
6163
}
6264

6365
private detectMachineOS(): string[] {
6466
let osSuffix = [];
67+
let scriptRunner: trm.ToolRunner;
6568

6669
if (tl.osType().match(/^Win/)) {
67-
let primary = "win-" + os.arch();
68-
osSuffix.push(primary);
69-
console.log(tl.loc("PrimaryPlatform", primary));
70+
let escapedScript = path.join(utilities.getCurrentDir(), 'externals', 'get-os-platform.ps1').replace(/'/g, "''");
71+
let command = `& '${escapedScript}'`
72+
73+
let powershellPath = tl.which('powershell', true);
74+
scriptRunner = tl.tool(powershellPath)
75+
.line('-NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command')
76+
.arg(command);
7077
}
7178
else {
7279
let scriptPath = path.join(utilities.getCurrentDir(), 'externals', 'get-os-distro.sh');
7380
utilities.setFileAttribute(scriptPath, "777");
7481

75-
let scriptRunner: trm.ToolRunner = tl.tool(tl.which(scriptPath, true));
76-
let result: trm.IExecSyncResult = scriptRunner.execSync();
82+
scriptRunner = tl.tool(tl.which(scriptPath, true));
83+
}
7784

78-
if (result.code != 0) {
79-
throw tl.loc("getMachinePlatformFailed", result.error ? result.error.message : result.stderr);
80-
}
85+
let result: trm.IExecSyncResult = scriptRunner.execSync();
8186

82-
let output: string = result.stdout;
87+
if (result.code != 0) {
88+
throw tl.loc("getMachinePlatformFailed", result.error ? result.error.message : result.stderr);
89+
}
8390

84-
let index;
85-
if ((index = output.indexOf("Primary:")) >= 0) {
86-
let primary = output.substr(index + "Primary:".length).split(os.EOL)[0];
87-
osSuffix.push(primary);
88-
console.log(tl.loc("PrimaryPlatform", primary));
89-
}
91+
let output: string = result.stdout;
9092

91-
if ((index = output.indexOf("Legacy:")) >= 0) {
92-
let legacy = output.substr(index + "Legacy:".length).split(os.EOL)[0];
93-
osSuffix.push(legacy);
94-
console.log(tl.loc("LegacyPlatform", legacy));
95-
}
93+
let index;
94+
if ((index = output.indexOf("Primary:")) >= 0) {
95+
let primary = output.substr(index + "Primary:".length).split(os.EOL)[0];
96+
osSuffix.push(primary);
97+
console.log(tl.loc("PrimaryPlatform", primary));
98+
}
9699

97-
if (osSuffix.length == 0) {
98-
throw tl.loc("CouldNotDetectPlatform");
99-
}
100+
if ((index = output.indexOf("Legacy:")) >= 0) {
101+
let legacy = output.substr(index + "Legacy:".length).split(os.EOL)[0];
102+
osSuffix.push(legacy);
103+
console.log(tl.loc("LegacyPlatform", legacy));
104+
}
105+
106+
if (osSuffix.length == 0) {
107+
throw tl.loc("CouldNotDetectPlatform");
100108
}
101109

102110
return osSuffix;
@@ -125,14 +133,15 @@ class DotnetCoreInstaller {
125133

126134
// cache tool
127135
console.log(tl.loc("CachingTool"));
128-
let cachedDir = await toolLib.cacheDir(extPath, this.cachedToolName, this.version);
136+
let cachedDir = await toolLib.cacheDir(extPath, this.cachedToolName, this.version, this.arch);
129137
console.log(tl.loc("SuccessfullyInstalled", this.packageType, this.version));
130138
return cachedDir;
131139
}
132140

133141
private packageType: string;
134142
private version: string;
135143
private cachedToolName: string;
144+
private arch: string;
136145
}
137146

138147
async function run() {

Tasks/DotNetCoreInstallerV0/externals/get-os-distro.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ get_current_os_name() {
113113

114114
local uname=$(uname)
115115
if [ "$uname" = "Darwin" ]; then
116-
echo "mac-x64"
116+
echo "mac"
117117
return 0
118118
elif [ "$uname" = "Linux" ]; then
119119
local linux_platform_name
120-
linux_platform_name="$(get_linux_platform_name)" || { echo "linux-x64" && return 0 ; }
120+
linux_platform_name="$(get_linux_platform_name)" || { echo "linux" && return 0 ; }
121121

122122
if [[ $linux_platform_name == "rhel.6" ]]; then
123-
echo "$linux_platform_name-x64"
123+
echo "$linux_platform_name"
124124
return 0
125125
elif [[ $linux_platform_name == alpine* ]]; then
126-
echo "linux-musl-x64"
126+
echo "linux-musl"
127127
return 0
128128
else
129-
echo "linux-x64"
129+
echo "linux"
130130
return 0
131131
fi
132132
fi
@@ -156,12 +156,37 @@ get_legacy_os_name() {
156156
return 1
157157
}
158158

159-
primaryName=$(get_current_os_name || echo "")
160-
legacyName=$(get_legacy_os_name || echo "")
159+
get_machine_architecture() {
160+
161+
if command -v uname > /dev/null; then
162+
CPUName=$(uname -m)
163+
case $CPUName in
164+
armv7l)
165+
echo "arm"
166+
return 0
167+
;;
168+
aarch64)
169+
echo "arm64"
170+
return 0
171+
;;
172+
esac
173+
fi
174+
175+
# Always default to 'x64'
176+
echo "x64"
177+
return 0
178+
}
179+
180+
osName=$(get_current_os_name || echo "")
181+
legacyOsName=$(get_legacy_os_name || echo "")
182+
arch=$(get_machine_architecture || echo "")
183+
184+
primaryName="$osName-$arch"
185+
legacyName="$legacyOsName"
161186

162187
echo "Primary:$primaryName"
163188
echo "Legacy:$legacyName"
164189

165-
if [ -z "$primaryName" ] && [ -z "$legacyName" ];then
190+
if [ -z "$osName" ] && [ -z "$legacyOsName" ];then
166191
exit 1
167192
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Get-Machine-Architecture()
2+
{
3+
# possible values: AMD64, IA64, x86
4+
return $ENV:PROCESSOR_ARCHITECTURE
5+
}
6+
7+
function Get-CLIArchitecture-From-Architecture([string]$Architecture)
8+
{
9+
switch ($Architecture.ToLower())
10+
{
11+
{ ($_ -eq "amd64") -or ($_ -eq "x64") } { return "x64" }
12+
{ $_ -eq "x86" } { return "x86" }
13+
default { throw "Architecture not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues" }
14+
}
15+
}
16+
17+
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $(Get-Machine-Architecture)
18+
Write-Output "Primary:win-$CLIArchitecture"

Tasks/DotNetCoreInstallerV0/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"author": "Microsoft Corporation",
1313
"version": {
1414
"Major": 0,
15-
"Minor": 1,
16-
"Patch": 19
15+
"Minor": 2,
16+
"Patch": 0
1717
},
1818
"satisfies": [
1919
"DotNetCore"

Tasks/DotNetCoreInstallerV0/task.loc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"author": "Microsoft Corporation",
1313
"version": {
1414
"Major": 0,
15-
"Minor": 1,
16-
"Patch": 18
15+
"Minor": 2,
16+
"Patch": 0
1717
},
1818
"satisfies": [
1919
"DotNetCore"

0 commit comments

Comments
 (0)