From 64e497aba9254bc120d3587f22724ae96588c134 Mon Sep 17 00:00:00 2001 From: juliancarrivick Date: Mon, 23 May 2022 21:50:28 +0800 Subject: [PATCH] Add clang-tidy to Ubuntu images (#5541) --- .../SoftwareReport/SoftwareReport.Common.psm1 | 14 ++++++++++---- .../SoftwareReport/SoftwareReport.Generator.ps1 | 3 ++- images/linux/scripts/installers/clang.sh | 4 +++- images/linux/scripts/tests/Tools.Tests.ps1 | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 07356a30d..5941b309a 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -24,14 +24,15 @@ function Get-ClangToolVersions { param ( [Parameter(Mandatory = $true)] [string] $ToolName, + [string] $VersionLineMatcher = "${ToolName} version", [string] $VersionPattern = "\d+\.\d+\.\d+)-" ) $result = Get-CommandResult "apt list --installed" -Multiline $toolVersions = $result.Output | Where-Object { $_ -match "^${ToolName}-\d+"} | ForEach-Object { $clangCommand = ($_ -Split "/")[0] - Invoke-Expression "$clangCommand --version" | Where-Object { $_ -match "${ToolName} version" } | ForEach-Object { - $_ -match "${ToolName} version (?${VersionPattern}" | Out-Null + Invoke-Expression "$clangCommand --version" | Where-Object { $_ -match "${VersionLineMatcher}" } | ForEach-Object { + $_ -match "${VersionLineMatcher} (?${VersionPattern}" | Out-Null $Matches.version } } | Sort-Object {[Version]$_} @@ -41,12 +42,17 @@ function Get-ClangToolVersions { function Get-ClangVersions { $clangVersions = Get-ClangToolVersions -ToolName "clang" - return "Clang " + $clangVersions + return "Clang $clangVersions" } function Get-ClangFormatVersions { $clangFormatVersions = Get-ClangToolVersions -ToolName "clang-format" - return "Clang-format " + $clangFormatVersions + return "Clang-format $clangFormatVersions" +} + +function Get-ClangTidyVersions { + $clangFormatVersions = Get-ClangToolVersions -ToolName "clang-tidy" -VersionLineMatcher "LLVM version" -VersionPattern "\d+\.\d+\.\d+)" + return "Clang-tidy $clangFormatVersions" } diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index 96faa9902..dc0f9a8f1 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -48,7 +48,8 @@ $runtimesList = @( (Get-RubyVersion), (Get-JuliaVersion), (Get-ClangVersions), - (Get-ClangFormatVersions) + (Get-ClangFormatVersions), + (Get-ClangTidyVersions) ) if ((Test-IsUbuntu18) -or (Test-IsUbuntu20)) { diff --git a/images/linux/scripts/installers/clang.sh b/images/linux/scripts/installers/clang.sh index 91f5b962a..1c97364fd 100644 --- a/images/linux/scripts/installers/clang.sh +++ b/images/linux/scripts/installers/clang.sh @@ -11,7 +11,7 @@ function InstallClang { local version=$1 echo "Installing clang-$version..." - apt-get install -y "clang-$version" "lldb-$version" "lld-$version" "clang-format-$version" + apt-get install -y "clang-$version" "lldb-$version" "lld-$version" "clang-format-$version" "clang-tidy-$version" } function SetDefaultClang { @@ -21,6 +21,8 @@ function SetDefaultClang { update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${version} 100 update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${version} 100 update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${version} 100 + update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${version} 100 + update-alternatives --install /usr/bin/run-clang-tidy run-clang-tidy /usr/bin/run-clang-tidy-${version} 100 } versions=$(get_toolset_value '.clang.versions[]') diff --git a/images/linux/scripts/tests/Tools.Tests.ps1 b/images/linux/scripts/tests/Tools.Tests.ps1 index 178eac1ec..582da0ea6 100644 --- a/images/linux/scripts/tests/Tools.Tests.ps1 +++ b/images/linux/scripts/tests/Tools.Tests.ps1 @@ -120,6 +120,9 @@ Describe "clang" { "clang-$ClangVersion --version" | Should -ReturnZeroExitCode "clang++-$ClangVersion --version" | Should -ReturnZeroExitCode + "clang-format-$ClangVersion --version" | Should -ReturnZeroExitCode + "clang-tidy-$ClangVersion --version" | Should -ReturnZeroExitCode + "run-clang-tidy-$ClangVersion --help" | Should -ReturnZeroExitCode } }