Skip to content

Commit

Permalink
[Agent] Bug Fix - Fixed Processor Arch Detection in Windows - AB#2232…
Browse files Browse the repository at this point in the history
…751 (#5049)

* [Agent] Fixed Processor Arch Detection in Windows

* Fixed dev.sh script

* retrigger checks

* Revised Implementation

* Revised Implementation

* Revised Implementation
  • Loading branch information
AdityaMankal-MS authored Nov 26, 2024
1 parent be02918 commit b88ed00
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Written for .NET Core in C#.
|![Win-x86](docs/res/win_med.png) **Windows x86**|[![Build & Test][win-x86-build-badge]][build]|
|![Win-arm64](docs/res/win_med.png) **Windows ARM64**|[![Build & Test][win-arm64-build-badge]][build]|
|![macOS](docs/res/apple_med.png) **macOS**|[![Build & Test][macOS-build-badge]][build]|
|![Linux-x64](docs/res/linux_med.png) **Linux x64**|[![Build & Test][linux-x64-build-badge]][build]|
|![Linux-arm](docs/res/linux_med.png) **Linux ARM**|[![Build & Test][linux-arm-build-badge]][build]|
|![RHEL6-x64](docs/res/redhat_med.png) **RHEL 6 x64**|[![Build & Test][rhel6-x64-build-badge]][build]|
|![Linux-x64](docs/res/linux_med.png) **Linux x64**|[![Build & Test][linux-x64-build-badge]][build]|
|![Linux-arm](docs/res/linux_med.png) **Linux ARM**|[![Build & Test][linux-arm-build-badge]][build]|
|![RHEL6-x64](docs/res/redhat_med.png) **RHEL 6 x64**|[![Build & Test][rhel6-x64-build-badge]][build]|

[win-x64-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Windows%20(x64)
[win-x86-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Windows%20(x86)
[win-arm64-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Windows%20(arm64)
[win-arm64-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Windows%20(ARM64)
[macOS-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=macOS%20(x64)
[linux-x64-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Linux%20(x64)
[linux-arm-build-badge]: https://mseng.visualstudio.com/pipelinetools/_apis/build/status/VSTS.Agent/azure-pipelines-agent.ci?branchName=master&jobname=Linux%20(ARM)
Expand Down
51 changes: 48 additions & 3 deletions src/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ function detect_platform_and_runtime_id() {
CURRENT_PLATFORM=$(uname | awk '{print tolower($0)}')
fi

echo "Detected Process Arch: $PROCESSOR_ARCHITECTURE"
if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then
local processor_type=$(detect_system_architecture)
echo "Detected Process Arch: $processor_type"

# Default to win-x64
DETECTED_RUNTIME_ID='win-x64'
if [[ "$PROCESSOR_ARCHITECTURE" == 'x86' ]]; then
if [[ "$processor_type" == 'x86' ]]; then
DETECTED_RUNTIME_ID='win-x86'
elif [[ "$PROCESSOR_ARCHITECTURE" == 'ARM64' ]]; then
elif [[ "$processor_type" == 'ARM64' ]]; then
DETECTED_RUNTIME_ID='win-arm64'
fi
elif [[ "$CURRENT_PLATFORM" == 'linux' ]]; then
Expand Down Expand Up @@ -368,6 +371,48 @@ function cmd_lint_verify() {
"${DOTNET_DIR}/dotnet" format --verify-no-changes -v diag "$REPO_ROOT/azure-pipelines-agent.sln" || checkRC "cmd_lint_verify"
}

function detect_system_architecture() {
local processor # Variable to hold the processor type (e.g., x, ARM)
local os_arch # Variable to hold the OS bitness (e.g., 64, 86)

# Detect processor type using PROCESSOR_IDENTIFIER
# Check for AMD64 or Intel in the variable to classify as "x" (covers x86 and x64 processors)
if [[ "$PROCESSOR_IDENTIFIER" =~ "AMD64" || "$PROCESSOR_IDENTIFIER" =~ "Intel64" ]]; then
processor="x"
# Check for ARM64 in the variable to classify as "ARM"
elif [[ "$PROCESSOR_IDENTIFIER" =~ "ARM" || "$PROCESSOR_IDENTIFIER" =~ "Arm" ]]; then
processor="ARM"
# Default to "x" for unknown or unhandled cases
else
processor="x"
fi

# Detect OS bitness using uname
# "x86_64" indicates a 64-bit operating system
if [[ "$(uname -m)" == "x86_64" ]]; then
os_arch="64"
# "i686" or "i386" indicates a 32-bit operating system
elif [[ "$(uname -m)" == "i686" || "$(uname -m)" == "i386" ]]; then
os_arch="86"
# "aarch64" indicates a 64-bit ARM operating system
elif [[ "$(uname -m)" == "aarch64" ]]; then
os_arch="64"
# Default to "64" for unknown or unhandled cases
else
os_arch="64"
fi

# Note: AMD32 does not exist as a specific label; 32-bit AMD processors are referred to as x86.
# ARM32 also does not exist in this context; ARM processors are always 64-bit.

# Combine processor type and OS bitness for the final result
# Examples:
# - "x64" for Intel/AMD 64-bit
# - "x86" for Intel/AMD 32-bit
# - "ARM64" for ARM 64-bit
echo "${processor}${os_arch}"
}

detect_platform_and_runtime_id
echo "Current platform: $CURRENT_PLATFORM"
echo "Current runtime ID: $DETECTED_RUNTIME_ID"
Expand Down

0 comments on commit b88ed00

Please sign in to comment.