“ERROR: File xxx can’t be indexed twice.” 在分析混合了C#和C++的解决方案时出现。

huangapple go评论131阅读模式
英文:

"ERROR: File xxx can't be indexed twice." when analyzing a solution with a mix of C# and C++

问题

以下是我的Azure管道,用于分析一个混合了C#和C++的解决方案。

这是执行项目构建命令时出现的错误:

> 错误: 在执行SonarScanner时出现错误: 无法对文件
> HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config 进行两次索引。请检查包含/排除模式,确保主文件和测试文件的集合是不相交的。

如何解决这个错误?

日志:构建命令执行日志

resources:
  repositories:
  - repository: Dependency
    type: githubenterprise
    endpoint: https://github.azc.ext.xxx.com
    name: cloud-client/Dependency

trigger: none

pool: 'SWindows2022-DEV'

variables:
  buildPlatform: 'x64'
  buildConfiguration: 'Release'

steps:
- checkout: self
- checkout: Dependency

- script: |
     move Dependency/KHPLib $(Build.SourcesDirectory)

- task: NuGetToolInstaller@1


- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.xxxcloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.'
      Invoke-WebRequest -Uri 'https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.13.0.66756/sonar-scanner-msbuild-5.13.0.66756-net46.zip' -OutFile 'sonar-scanner-msbuild.zip'
      Expand-Archive -Path 'sonar-scanner-msbuild.zip' -DestinationPath './SonarScanner'

- task: VSBuild@1
  inputs:
    solution: 'KHPLib\src\KHPLib\KHPLib.vcxproj'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'xxx_HPCEMConnectionWizardWin'
    cliSources: '.'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-

- task: CmdLine@2
  inputs:
    script: |
      SonarScanner\SonarScanner.MSBuild.exe begin /k:"xxx_HPCEMConnectionWizardWin" /n:"HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln" /v:"1.0" /d:sonar.cfamily.build-wrapper-output="bw-output"
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir bw-output "C:\Program Files\Microsoft Visual Studio22\Enterprise\MSBuild\Current\Bin\MSBuild.exe" HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln -t:Rebuild /p:configuration=release /p:platform=x64
      SonarScanner\SonarScanner.MSBuild.exe end

- task: SonarQubeAnalyze@5

- task: SonarQubePublish@5
  inputs:
    pollingTimeoutSec: '300'

- task: sonar-buildbreaker@8
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'

<hr/>

更新 2023-05-27

我更新了以下管道任务:

- task: SonarQubePrepare@5
  inputs:
    SonarQube: &#39;https://sq.corp.xxxcloud.net&#39;
    scannerMode: &#39;CLI&#39;
    configMode: &#39;manual&#39;
    cliProjectKey: &#39;xxx_HPCEMConnectionWizardWin&#39;
    cliSources: &#39;.&#39;
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-
      sonar.verbose=true
      sonar.sources=HPCEMConnectionWizardWin/src/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

新错误:

> 错误: 在执行SonarScanner时出现错误
2023-05-27T12:25:22.4759667Z 文件 HPCEMConnectionWizardWin/src/HPCEMConnectionWizardLauncher/framework.h 无法被两次索引。请检查包含/排除模式,确保主文件和测试文件的集合是不相交的。

以下是我想要分析的代码:

C#代码(*.cs)目录列表:

  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/
  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/
  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

C++代码(.cpp,.h)目录列表:

  • HPCEMConnectionWizardWin/src/

详细日志:https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt

英文:

Below is my Azure pipeline to analyze a solution with a mix of C# and C++.

This is the error of executing the project build command:

> ERROR: Error during SonarScanner execution ERROR: File
> HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config can’t be
> indexed twice. Please check that inclusion/exclusion patterns produce
> disjoint sets for main and test files

How can I resolve this error?

Logs: build command execute log

resources:
  repositories:
  - repository: Dependency
    type: githubenterprise
    endpoint: https://github.azc.ext.xxx.com
    name: cloud-client/Dependency

trigger: none

pool: &#39;SWindows2022-DEV&#39;

variables:
  buildPlatform: &#39;x64&#39;
  buildConfiguration: &#39;Release&#39;

steps:
- checkout: self
- checkout: Dependency

- script: |
     move Dependency/KHPLib $(Build.SourcesDirectory)

- task: NuGetToolInstaller@1


- task: PowerShell@2
  inputs:
    targetType: &#39;inline&#39;
    script: |
      Invoke-WebRequest -Uri &#39;https://sq.corp.xxxcloud.net/static/cpp/build-wrapper-win-x86.zip&#39; -OutFile &#39;build-wrapper.zip&#39;
      Expand-Archive -Path &#39;build-wrapper.zip&#39; -DestinationPath &#39;.&#39;
      Invoke-WebRequest -Uri &#39;https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.13.0.66756/sonar-scanner-msbuild-5.13.0.66756-net46.zip&#39; -OutFile &#39;sonar-scanner-msbuild.zip&#39;
      Expand-Archive -Path &#39;sonar-scanner-msbuild.zip&#39; -DestinationPath &#39;./SonarScanner&#39;

- task: VSBuild@1
  inputs:
    solution: &#39;KHPLib\src\KHPLib\KHPLib.vcxproj&#39;
    platform: &#39;$(buildPlatform)&#39;
    configuration: &#39;$(buildConfiguration)&#39;

- task: SonarQubePrepare@5
  inputs:
    SonarQube: &#39;https://sq.corp.xxxcloud.net&#39;
    scannerMode: &#39;CLI&#39;
    configMode: &#39;manual&#39;
    cliProjectKey: &#39;xxx_HPCEMConnectionWizardWin&#39;
    cliSources: &#39;.&#39;
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-

- task: CmdLine@2
  inputs:
    script: |
      SonarScanner\SonarScanner.MSBuild.exe begin /k:&quot;xxx_HPCEMConnectionWizardWin&quot; /n:&quot;HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln&quot; /v:&quot;1.0&quot; /d:sonar.cfamily.build-wrapper-output=&quot;bw-output&quot;
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir bw-output &quot;C:\Program Files\Microsoft Visual Studio22\Enterprise\MSBuild\Current\Bin\MSBuild.exe&quot; HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln -t:Rebuild /p:configuration=release /p:platform=x64
      SonarScanner\SonarScanner.MSBuild.exe end

- task: SonarQubeAnalyze@5

- task: SonarQubePublish@5
  inputs:
    pollingTimeoutSec: &#39;300&#39;

- task: sonar-buildbreaker@8
  inputs:
    SonarQube: &#39;https://sq.corp.xxxcloud.net&#39;

<hr/>

Update 2023-05-27

I updated the following pipeline task:

- task: SonarQubePrepare@5
  inputs:
    SonarQube: &#39;https://sq.corp.xxxcloud.net&#39;
    scannerMode: &#39;CLI&#39;
    configMode: &#39;manual&#39;
    cliProjectKey: &#39;xxx_HPCEMConnectionWizardWin&#39;
    cliSources: &#39;.&#39;
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-
      sonar.verbose=true
      sonar.sources=HPCEMConnectionWizardWin/src/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/,HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

New error:

> ERROR: Error during SonarScanner execution
2023-05-27T12:25:22.4759667Z File HPCEMConnectionWizardWin/src/HPCEMConnectionWizardLauncher/framework.h can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Here is the code I like to analyze:

The C# code (*.cs) directory lists:

  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/
  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/
  • HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

The C++ code (.cpp,.h) directory lists:

  • HPCEMConnectionWizardWin/src/

Verbose log: https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt

答案1

得分: 1

你需要检查是否在某种方式下两次包括了 HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config。你应该在 SonarQubePrepare 步骤中添加 sonar.verbose=true,并检查Sonar索引了哪些文件。然后,你可以看到重复的位置在哪里。接下来,按照 缩小焦点 的步骤,确保某些文件没有被重复索引。

为了快速解决问题,只需使用以下方法排除 HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config 文件:

sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
英文:

You need to check if HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config is included twice somehow. You should add sonar.verbose=true in the SonarQubePrepare step and check what files are indexed by Sonar. Then you can see where the duplication lies. Next, follow Narrowing the Focus to make sure certain files are not indexed twice.

For a quick workaround, just exclude that HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config file with:

sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config

huangapple
  • 本文由 发表于 2023年5月22日 15:45:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303988.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定