ament / ament/ament_lint

ament_clang_tidy corrupts Windows paths and diagnostic messages in xUnit output

Ouverte
#594 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
50
Forks
129
Merge moyen
3 j 10 h
PR mergées (30 j)
3

Description

## Description

`ament_clang_tidy` does not correctly parse clang-tidy diagnostics containing Windows absolute paths. The generated xUnit output contains a truncated file path and diagnostic message.

This affects xUnit reporting only; clang-tidy itself prints the diagnostic correctly.

## Environment

* Windows
* `ament_clang_tidy` 0.21.2 (Rolling)
* clang-tidy 19.1.7
* Python 3.12.3

## Reproduction

For example, clang-tidy reports:

```text
C:\pixi_ws\ros2-windows\include\rclcpp\rclcpp/any_subscription_callback.hpp:441:7: warning: 'set_deprecated>>' is deprecated: use 'void(std::shared_ptr)' instead [clang-diagnostic-deprecated-declarations]
```

Run `ament_clang_tidy` with xUnit output enabled:

```powershell
ament_clang_tidy.exe `
--xunit-file build\ament_clang_tidy.xunit.xml `
build\memfd_buffer_backend
```

The resulting xUnit contains:

```xml


/any_subscription_callback.hpp:441:7

```

## Expected

The xUnit result should preserve:

* the complete Windows path (`C:\...`)
* line and column
* the complete message following `warning:` or `error:`
* the associated diagnostic context in the failure body

## Cause

There appear to be three issues in `ament_clang_tidy/main.py`:

1. `error_re` assumes an absolute path starts with `/`:

```python
error_re = re.compile(
'(/.*?\\.(?:%s)):(\\d+):(\\d+): (?:warning:|error:)'
% '|'.join(extensions))
```

On Windows this starts matching at a later `/` in the path, dropping the drive and preceding directories.

2. `find_error_message()` uses the last colon in the line:

```python
def find_error_message(data):
return data[data.rfind(':') + 2:]
```

A diagnostic message can itself contain colons, e.g. `deprecated:` or `std::shared_ptr`, so this can truncate the message.

3. Diagnostic context is collected in `error['code_correct_rec']`, but `get_xunit_content()` checks the newly constructed `data` dictionary instead:

```python
if 'code_correct_rec' in data:
```

so the collected source lines and `note:` diagnostics are not included in the failure body.

### Did you use Generative AI?

Codex/Luna and ChatGPT were used for invetigation and creating the draft of this PR description.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.