-
Notifications
You must be signed in to change notification settings - Fork 24
feat: force clean build after warnings or dependency changes #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| # Unit Tests of incremental.py | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from incremental import clean_builddir_if_stale, update_module_hash | ||
|
|
||
| _BUILD = Path("/build") | ||
| _MODULE = Path("/MODULE.bazel") | ||
| _LOCK = Path("/MODULE.bazel.lock") | ||
|
|
||
|
|
||
| def _simulate_old_state(fs, warnings: str | None) -> None: | ||
| """Helper function to set up a build directory with an old hash and warnings.""" | ||
|
|
||
| fs.create_dir(_BUILD) | ||
| fs.create_file(_MODULE, contents="stable") | ||
| fs.create_file(_LOCK, contents="old lock") | ||
| update_module_hash(_BUILD, [_MODULE, _LOCK]) | ||
| if warnings is not None: | ||
| fs.create_file(_BUILD / "warnings.txt", contents=warnings) | ||
|
|
||
|
|
||
| def test_clean_removes_build_dir_when_previous_build_had_warnings(fs) -> None: | ||
| """If warnings.txt exists and is not empty, the build dir is removed.""" | ||
|
|
||
| _simulate_old_state(fs, warnings="WARNING: something went wrong") | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE]) | ||
|
|
||
| assert not _BUILD.exists() | ||
|
|
||
|
|
||
| def test_clean_keeps_build_dir_when_warnings_txt_is_empty(fs) -> None: | ||
| """If warnings.txt exists and is empty, the build dir is kept.""" | ||
|
|
||
| _simulate_old_state(fs, warnings="") | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE, _LOCK]) | ||
|
|
||
| assert _BUILD.exists() | ||
|
|
||
|
|
||
| def test_clean_is_noop_when_warnings_txt_is_absent(fs) -> None: | ||
| """If warnings.txt does not exist, the build dir is kept (no error).""" | ||
|
|
||
| _simulate_old_state(fs, warnings=None) | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE, _LOCK]) | ||
|
|
||
| assert _BUILD.exists() | ||
|
|
||
|
|
||
| def test_clean_is_noop_when_build_dir_is_absent(fs) -> None: | ||
| fs.create_file(_MODULE, contents="stable") | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE]) | ||
|
|
||
|
|
||
| def test_module_changed_removes_build_dir_when_one_sentinel_file_changed(fs) -> None: | ||
| _simulate_old_state(fs, warnings=None) | ||
|
|
||
| _LOCK.write_bytes(b"new lock") | ||
| clean_builddir_if_stale(_BUILD, [_MODULE, _LOCK]) | ||
|
|
||
| assert not _BUILD.exists() | ||
|
|
||
|
|
||
| def test_module_changed_keeps_build_dir_when_all_sentinel_files_unchanged(fs) -> None: | ||
| _simulate_old_state(fs, warnings=None) | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE, _LOCK]) | ||
|
|
||
| assert _BUILD.exists() | ||
|
|
||
|
|
||
| def test_module_change_after_successful_build_forces_clean(fs) -> None: | ||
| _simulate_old_state(fs, warnings=None) | ||
|
|
||
| _MODULE.write_bytes(b"version 2") | ||
| clean_builddir_if_stale(_BUILD, [_MODULE]) | ||
|
|
||
| assert not _BUILD.exists() | ||
|
|
||
|
|
||
| def test_missing_hash_file_triggers_clean(fs) -> None: | ||
| """If _build/ exists but hash file is absent, treat as stale (e.g. upgrade from old version).""" | ||
| fs.create_dir(_BUILD) | ||
| fs.create_file(_MODULE, contents="stable") | ||
| # No hash file written | ||
|
|
||
| clean_builddir_if_stale(_BUILD, [_MODULE]) | ||
|
|
||
| assert not _BUILD.exists() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,4 +35,5 @@ bazel-runfiles | |
|
|
||
| # Local development | ||
| pytest | ||
| pyfakefs | ||
| basedpyright | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.