Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Agent] Bug Fix - Fixed Processor Arch Detection in Windows - AB#2232751 #5049

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading