From 04cb9cbe90e3b6badc8e77ebae8b56126496dce9 Mon Sep 17 00:00:00 2001 From: Sai Bulusu Date: Fri, 8 Nov 2024 09:42:37 -0800 Subject: [PATCH] CompilerInstallation fix: Remove existing alternatives for cpp (#396) * Added line to remove existing alternatives for cpp. * Fixing CompilerInstallation test. * Removing existing duplicate command. --------- Co-authored-by: saibulusu --- .../VirtualClient.Dependencies/CompilerInstallation.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/VirtualClient/VirtualClient.Dependencies/CompilerInstallation.cs b/src/VirtualClient/VirtualClient.Dependencies/CompilerInstallation.cs index 400c45cb40..a920db889a 100644 --- a/src/VirtualClient/VirtualClient.Dependencies/CompilerInstallation.cs +++ b/src/VirtualClient/VirtualClient.Dependencies/CompilerInstallation.cs @@ -242,8 +242,7 @@ private async Task RemoveAlternativesAsync(EventContext telemetryContext, Cancel string[] packages = { "gcc", - "gfortran", - "cpp" + "gfortran" }; // due to the following error: @@ -264,7 +263,7 @@ private async Task RemoveAlternativesAsync(EventContext telemetryContext, Cancel } } } - + private async Task SetGccPriorityAsync(string gccVersion, EventContext telemetryContext, CancellationToken cancellationToken) { string updateAlternativeArgument = $"--install /usr/bin/gcc gcc /usr/bin/gcc-{gccVersion} {gccVersion}0 " + @@ -276,6 +275,9 @@ private async Task SetGccPriorityAsync(string gccVersion, EventContext telemetry await this.ExecuteCommandAsync("update-alternatives", updateAlternativeArgument, Environment.CurrentDirectory, telemetryContext, cancellationToken); + // Remove all existing alternatives for cpp before the subsequent "update-alternatives" of cpp + await this.ExecuteCommandAsync("update-alternatives", "--remove-all cpp", Environment.CurrentDirectory, telemetryContext, cancellationToken); + // For some update path, the cpp can't be update-alternative by a gcc, so needs a separate call. string updateAlternativeArgumentCpp = $"--install /usr/bin/cpp cpp /usr/bin/cpp-{gccVersion} {gccVersion}0";