You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2026/04/24 06:52:14 UTC
[PR] Add script to smartly recompile ANTLR4 modules [shardingsphere]
sandynz opened a new pull request, #38648:
URL: https://github.com/apache/shardingsphere/pull/38648
Changes proposed in this pull request:
- Add script to smartly recompile ANTLR4 modules and update .gitignore
---
Before committing this PR, I'm sure that I have checked the following options:
- [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [ ] I have self-reviewed the commit code.
- [ ] I have (or in comment I request) added corresponding labels for the pull request.
- [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [ ] I have added corresponding unit tests for my changes.
- [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add script to smartly recompile ANTLR4 modules [shardingsphere]
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on PR #38648:
URL: https://github.com/apache/shardingsphere/pull/38648#issuecomment-4311385920
• 1. Decision block
Merge Verdict: Mergeable
Reviewed Scope: PR #38648 latest head c91761320c860b7702c7b9a0b296113cbc5cbd61; .gitignore, scripts/smart-antlr-rebuild.sh:1, docs/community/content/involved/contribute/contributor.en.md:39,
docs/community/content/involved/contribute/contributor.cn.md:39; PR metadata, commit list, changed-file list, issue comment.
Not Reviewed Scope: GitHub Actions job logs were not independently inspected; runtime JDBC/Proxy paths are unaffected and therefore not deeply reviewed.
Need Expert Review: No.
2. Basis
This PR is mergeable because it fixes the actual workflow gap rather than adding a superficial fallback. The target problem is parser-source regeneration after .g4 changes without forcing
contributors into a full repository build. The script addresses that directly by:
- locating the repo root from the script path itself, so invocation is not tied to the caller’s current directory (scripts/smart-antlr-rebuild.sh:27)
- mapping changed .g4 files back to Maven modules and rebuilding only the affected modules (scripts/smart-antlr-rebuild.sh:45, scripts/smart-antlr-rebuild.sh:104)
- covering committed, staged, unstaged, and untracked grammar changes instead of only commit-to-commit diffs (scripts/smart-antlr-rebuild.sh:78)
- using ./mvnw by default, which is consistent with repo conventions (scripts/smart-antlr-rebuild.sh:39)
Fresh-pass risk scan did not find a blocking side effect:
- Design: isolated tooling change only; no shared runtime, SPI, parser semantics, or metadata assembly path changed.
- Performance: the expensive path is first-run / branch-switch full scan, but that is an explicit tooling tradeoff, not a hot-path regression.
- Compatibility: no JDBC/Proxy behavior, config semantics, API/SPI, or SQL-dialect behavior changed. .gitignore only adds the local state file and is aligned with the script design.
- Regression surface: the script’s no-change path, subdirectory invocation path, and outside-repo absolute-path invocation path are all consistent with the intended behavior.
Adversarial pass also came back clean:
- Cross-feature regression path: none found, because this is a standalone developer script and docs update.
- Config-disabled / adjacent path: when the state file is absent or branch changes, the script intentionally falls back to full ANTLR module scan rather than producing partial or stale output.
- Original symptom partial-coverage path: local uncommitted .g4 edits are explicitly included in collect_changed_g4_files, which closes the main incremental-detection gap.
There are no unrelated changes in the PR. The documentation updates are directly tied to the new script, and the .gitignore entry is necessary for the script’s state file.
3. Pre-merge checks
Evidence reviewed:
- PR scope from GitHub API: 4 files, 3 commits, no dependency changes, no review comments, one author issue comment describing intent.
- Local script syntax check: bash -n scripts/smart-antlr-rebuild.sh -> exit code 0
- Local invocation from repo subdirectory: bash ../scripts/smart-antlr-rebuild.sh from parser/ -> exit code 0
- Local invocation from outside repo: bash /path/to/shardingsphere/scripts/smart-antlr-rebuild.sh from /tmp -> exit code 0
Residual note: there is no automated test coverage for the shell script itself, but for this change type the current manual validation is sufficient and I do not see an unresolved merge blocker.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add script to smartly recompile ANTLR4 modules [shardingsphere]
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on PR #38648:
URL: https://github.com/apache/shardingsphere/pull/38648#issuecomment-4311316642
## Background
ShardingSphere parser development often needs regenerated Java sources after `.g4` grammar changes.
This PR introduces `scripts/smart-antlr-rebuild.sh` as a lightweight helper for parser regeneration, so contributors do not need to rerun a full repository build every time they touch grammar files.
The goal is straightforward:
- detect which ANTLR-related modules need to be rebuilt
- recompile only the affected modules
- keep the workflow reliable for common local development scenarios
## What This PR Improves
This PR adds a focused workflow for parser-related rebuilds and makes that workflow reliable for day-to-day development.
### 1. Support running from any directory
The script now resolves the project root from the script location itself:
```bash
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
PROJECT_ROOT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null)
```
This means it works in both of the following cases:
- Running from any subdirectory inside the ShardingSphere repository
- Running from outside the repository with an absolute script path
### 2. Detect local `.g4` changes more accurately
The script collects grammar changes from all relevant local sources:
- committed changes since the last recorded baseline
- staged changes
- unstaged working tree changes
- untracked `.g4` files
This closes the gap where local grammar edits could previously be missed before commit time.
### 3. Follow repository build conventions
The script now prefers:
```bash
./mvnw compile ...
```
and falls back to `mvn` only if the wrapper is not executable.
This keeps the script aligned with the repository's standard build entrypoint and reduces environment drift across contributor environments.
### 4. Improve shell robustness
Some small but useful hardening changes were added:
- `set -u`
- `set -o pipefail`
- `find ... -print0` instead of a more fragile `find | xargs`
- extracted helper functions for module resolution and state-file writing
- parameter expansion instead of spawning `cut` for state parsing
These changes make the script easier to maintain and less sensitive to shell edge cases.
## Why These Changes Matter
The purpose of this script is not just convenience. It is meant to be a safe and repeatable developer shortcut for parser regeneration.
If local `.g4` edits are not detected, or if the script only works from some directories, contributors still need to fall back to trial-and-error builds. That weakens the value of having a dedicated helper script in the first place.
With this PR, the script becomes more predictable in the common workflows below:
- pull latest changes and refresh generated parser classes
- rebase and rebuild parser artifacts
- edit grammar files locally before committing
- invoke the helper from a submodule directory or from an external terminal
## Validation
The updated script was checked with the following commands:
```bash
bash scripts/smart-antlr-rebuild.sh
```
```bash
cd parser
bash ../scripts/smart-antlr-rebuild.sh
```
```bash
cd /tmp
bash /path/to/shardingsphere/scripts/smart-antlr-rebuild.sh
```
The script also completed a real compile run successfully with:
```bash
./mvnw compile -pl <detected modules> -am -T 1C \
-DskipTests \
-Dcheckstyle.skip \
-Drat.skip \
-Dmaven.javadoc.skip \
-Djacoco.skip \
-Dspotless.skip
```
## Result
This PR does not change parser logic or generated grammar output format.
It improves the developer experience around parser regeneration by making `scripts/smart-antlr-rebuild.sh`:
- more accurate
- more portable
- more consistent with repository conventions
- safer to use in real local workflows
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add script to smartly recompile ANTLR4 modules [shardingsphere]
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz merged PR #38648:
URL: https://github.com/apache/shardingsphere/pull/38648
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org