Skip to content
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
12 changes: 10 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Compare AUTOSAR MATLAB/Simulink codegen folders while filtering proven generator noise.
Package: compare_tool. Read docs/architecture.md for module ownership and contracts.

## Invariants
## Constraints
- An unproven difference is a real change. Scan/read/parse/compare failures are errors, never empty or clean results.
- Verdicts: identical, comment-only, ignorable-only, real-change, added, deleted, error. Only noise may be hidden; filtering must not change verdicts, counts or raw report results.
- New noise rules must prove both noise-only handling and preservation of a nearby real change.
Expand All @@ -11,7 +11,15 @@ Package: compare_tool. Read docs/architecture.md for module ownership and contra
- HTML reports contain local/inline assets and work offline.
- Exit codes: 0 clean, 1 real changes or configured consistency failures, 2 incomplete/error. --exit-zero must never suppress errors.
- Graceful UI fallback must not disguise comparison failures.
- Update task-oriented English docs and corresponding docs/vi/ with documented behavior changes.

## Documentation

- Write short, direct sentences. Lead with the task or result, avoid marketing language, and link to existing guidance instead of repeating it.
- Keep user guides focused on user tasks, options, constraints, and interpreting results.
- Do not describe transient GUI status text, progress-bar timing or visibility, widget layout, implementation details, or bug-fix history in user guides.
- Put implementation details in maintainer documentation and user-visible fixes in CHANGELOG.md. Update a user guide only when usage, options, constraints, or result interpretation changes.
- Keep architecture documentation focused on the current design, contracts, constraints, and verification entry points. Exclude update history, completed-work lists, validation snapshots, TODOs, and roadmaps.
- Keep English docs and corresponding docs/vi/ synchronized.

## Verification
For code changes:
Expand Down
40 changes: 13 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
# Contributing

Thanks for helping improve the CodeGen Compare Tool. This file is the short
version of what CI enforces; [`docs/architecture.md`](docs/architecture.md) is
the map of how the pieces fit and why.
Read [AGENTS.md](AGENTS.md) for constraints and [Architecture](docs/architecture.md) for module ownership.

## Setup

No install is needed to run the tool or the tests — the core is standard
library only.
From the repository folder:

```bash
git clone https://github.com/longvo92/codegen-compare-tool.git
cd codegen-compare-tool
python -m pip install ruff mypy
python -m compare_tool --help
```

The viewer and its tests need PySide6:
The CLI and core tests need no runtime dependencies. Install the optional viewer for GUI work:

```bash
pip install "PySide6>=6.5"
python -m pip install -e ".[viewer]"
```

## Two hard constraints
## Change requirements

These are checked automatically ([`tests/test_stdlib_only.py`](tests/test_stdlib_only.py)),
not left to reviewers to remember:
- Support Python 3.8+ and keep the core/zipapp standard-library only.
- Keep Qt imports in `compare_tool/qtviewer/`; shared models must work without Qt.
- Test new noise rules with both a noise-only case and a nearby real change.
- Keep CLI, viewer and report decisions consistent.
- Update task-oriented English/Vietnamese guides when usage changes. Put release notes in [CHANGELOG.md](CHANGELOG.md).

1. **The compare core is standard library only.** Everything under
`compare_tool/` except `compare_tool/qtviewer/` ships inside
`compare_tool.pyz`, the documented fallback for machines where antivirus
blocks the `.exe`. One third-party import there and the zipapp stops running
on exactly those machines. If you genuinely need a library in the core, say
so in the PR — it is a real trade-off (it costs the `.pyz` and the "zero
dependencies" line), not something to slip in.
2. **PySide6 lives only under `compare_tool/qtviewer/`,** imported lazily when
the viewer opens. `tree.py` and `summary_model.py` stay Qt-free so the suite
runs headless.
## Verification

Python 3.8 is a shipped promise: no `match`, no `X | Y` at runtime, and
`list[str]` in an annotation needs `from __future__ import annotations`.


Issues and pull requests are welcome.
Run the [checks and relevant smoke tests](docs/architecture.md#verification) before opening a PR. Documentation-only changes need link, example and diff checks.
126 changes: 34 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,68 @@
<p align="center">
<img src="resources/logo/logo-full.png" alt="CodeGen Compare Tool" width="360">
</p>

<p align="center">
<a href="https://github.com/longvo92/codegen-compare-tool/actions/workflows/test.yml"><img src="https://github.com/longvo92/codegen-compare-tool/actions/workflows/test.yml/badge.svg" alt="Test"></a>
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.8%2B-blue.svg" alt="Python 3.8+"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License: MIT"></a>
<a href="https://github.com/longvo92/codegen-compare-tool/releases/latest"><img src="https://img.shields.io/github/v/release/longvo92/codegen-compare-tool?label=release&color=blue" alt="Release"></a>
</p>

<p align="center">🇻🇳 <a href="docs/vi/README.md">Tiếng Việt</a></p>

# CodeGen Compare Tool

Compare two AUTOSAR MATLAB/Simulink code-generation snapshots and focus on the changes that need review.

The tool filters generator noise that it can prove is harmless, then summarizes changes to generated C/C++, ARXML, RTE access and A2L objects.
[Tiếng Việt](docs/vi/README.md)

> If a difference cannot be proven to be noise, it remains a real change.
Compare AUTOSAR MATLAB/Simulink codegen folders or ZIPs and review C/C++, ARXML, RTE and A2L changes. Only proven generator noise is filtered; unexplained differences remain real changes.

## Quick start

Download `compare-tool.exe` or `compare_tool.pyz` from the [latest release](https://github.com/longvo92/codegen-compare-tool/releases/latest). Both accept the options shown below.
1. Download `compare-tool.exe` from [Releases](https://github.com/longvo92/codegen-compare-tool/releases/latest) and open it. No Python installation is needed.
2. Select BASELINE and CURRENT, then run the comparison.
3. Review changes in the viewer or export an offline HTML report.

To run from source:
For CLI use, download `compare_tool.pyz` and run it with Python 3.8+, or use the source commands below. Replace `python -m compare_tool` with `compare-tool.exe` or `python compare_tool.pyz` for downloaded builds.

## Run from source

```bash
git clone https://github.com/longvo92/codegen-compare-tool.git
cd codegen-compare-tool
```

For downloaded builds, replace `python -m compare_tool` with `compare-tool.exe` or `python compare_tool.pyz`.

Check consistency before delivery using one folder or ZIP (new in source; not released yet):

```bash
python -m compare_tool --check-current current
```

This mode runs no diff and writes no HTML. The `delivery` policy gates missing input and unchecked items; existing comparison commands and YAML remain supported. See [usage](docs/usage.md#consistency-check) for mappings and exceptions.

Create a self-contained HTML report:

```bash
python -m compare_tool baseline current --report report.html
```

Print only a terminal summary:
The CLI uses only the Python standard library. For the desktop viewer:

```bash
python -m compare_tool baseline current --no-report
python -m pip install -e ".[viewer]"
python -m compare_tool
```

The terminal mode shows a per-model Overview, AUTOSAR/A2L changes, consistency warnings, effective compare settings, hunk-classification totals and one summary for each non-identical file. Add `--check-consistency` to validate CURRENT generated RTE calls against CURRENT ARXML declarations. It does not print individual hunks, source diffs or create HTML.
Sample inputs: [tests/fixtures/demo](tests/fixtures/demo).

Open the desktop viewer:
## Usage

```bash
python -m compare_tool
python -m compare_tool baseline current --no-report
python -m compare_tool --check-current current
```

The viewer requires PySide6. The CLI and `compare_tool.pyz` use only the Python standard library.

Folders and ZIP archives are accepted as inputs.

## Outputs

| Output | Use it for |
| Output | Use it to |
|---|---|
| Desktop viewer | Interactive side-by-side review |
| HTML report | Sharing or publishing as a CI artifact |
| `--check-current PATH` | CURRENT consistency and coverage before delivery |
| `--no-report` | Detailed terminal review and diagnostics without generated files |
| `--json` | Structured pipeline processing |
| `--sarif` | Code-scanning annotations |

The comparison engine also reports:

- model/SWC ownership;
- ports, port interfaces, runnables and events;
- `Rte_*` access points;
- A2L `CHARACTERISTIC` and `MEASUREMENT` objects;
- possible incomplete regeneration across ARXML, A2L and generated C;
- generated RTE calls that disagree with CURRENT ARXML access declarations when `--check-consistency` is enabled.

Old/new regeneration warnings remain advisory. The optional CURRENT-tree check is disabled by default; when enabled, a `fail` finding exits `1`, an incomplete consistency scan exits `2`, and a `warn` finding does not change the exit code. No consistency result changes a file verdict.

## Verdicts

| Verdict | Meaning |
|---|---|
| Modified | A real change needs review |
| Comment | Only comments changed |
| Unimportant | Only proven generator noise changed |
| Added / Deleted | The file exists on one side only |
| Identical | No difference |
| Not compared | The file could not be read or compared |

## CI exit codes

| Code | Meaning |
|---:|---|
| `0` | No real changes |
| `1` | Real changes found |
| `2` | Comparison incomplete or failed |
| Desktop viewer | Review changes side by side |
| HTML report | Share results offline or as a CI artifact |
| `--no-report` | Review summaries and diagnostics in the terminal |
| `--check-current PATH` | Check CURRENT RTE/ARXML consistency before delivery |
| `--json` / `--sarif` | Export comparison results for pipelines |

`--exit-zero` suppresses only file-difference failures, never consistency failures or incomplete scans. `--check-current` returns `0` for a policy pass, `1` for failed rules and `2` for incomplete input/scanning or unchecked items under delivery policy.
CURRENT consistency findings are terminal-only; JSON/SARIF exports contain comparison results and old/new advisories.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Distinguish SARIF from JSON advisory output

State that only JSON contains the old/new advisories. When a pipeline requests SARIF, serialize.build_sarif() emits only actionable per-file findings and has no advisory field, whereas the JSON document stores advisories under consistency; the current wording incorrectly promises SARIF consumers data they cannot receive.

Useful? React with 👍 / 👎.


## Requirements
## Review the results

- Python 3.8 or newer
- No server, database or network access at runtime
- PySide6 only for the desktop viewer
- Self-contained HTML reports with no CDN or external assets
- **Modified**, **Added** and **Deleted** need review. **Comment** and **Unimportant** contain only comments or proven noise. **Not compared** indicates an error.
- Overview groups changes by model/SWC, including ports, runnables, events, RTE access and A2L objects.
- Old/new regeneration warnings are advisory; unchanged output does not prove regeneration history.
- `--check-current` uses delivery policy: failed rules exit `1`; missing input, scan errors or unchecked items exit `2`. See the [User Guide](docs/usage.md#consistency-check) for scope and exceptions.
- Comparisons exit `0` when clean, `1` for real changes or enabled consistency failures, and `2` for errors/incomplete scans. `--exit-zero` suppresses only file-difference failures.

## Documentation

- [Usage Guide](docs/usage.md) — commands, viewer controls, noise rules and CI
- [Vietnamese documentation](docs/vi/README.md)
- [User Guide](docs/usage.md) — viewer, CLI, noise rules and CI
- [Architecture](docs/architecture.md) — components, contracts, verification and builds
- [Contributing](CONTRIBUTING.md) — setup and change requirements
- [Changelog](CHANGELOG.md) — release notes

Run `python -m compare_tool --help` for the complete CLI reference.
See [CLI flags](docs/usage.md#cli-flags) for defaults and supported combinations, or run `python -m compare_tool --help`. HTML reports work offline without a server or external assets.

## License

[MIT](LICENSE) © 2026 Long Vo Thien
[MIT](LICENSE) · Long Vo Thien
Loading
Loading