-
Notifications
You must be signed in to change notification settings - Fork 155
manifest: Support --active-only argument for --resolve/--freeze #808
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
carlescufi
merged 2 commits into
zephyrproject-rtos:main
from
pdgendt:freeze-resolve-active
May 6, 2025
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright (c) 2018, 2019 Nordic Semiconductor ASA | ||
|
Check notice on line 1 in src/west/app/project.py
|
||
| # Copyright 2018, 2019 Foundries.io | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
@@ -638,6 +638,8 @@ | |
| group = parser.add_argument_group('options for --resolve and --freeze') | ||
| group.add_argument('-o', '--out', | ||
| help='output file, default is standard output') | ||
| group.add_argument('--active-only', action='store_true', | ||
| help='only resolve active projects') | ||
|
|
||
| return parser | ||
|
|
||
|
|
@@ -649,11 +651,13 @@ | |
| if args.validate: | ||
| pass # nothing more to do | ||
| elif args.resolve: | ||
| self._die_if_manifest_project_filter('resolve') | ||
| self._dump(args, manifest.as_yaml(**dump_kwargs)) | ||
| if not args.active_only: | ||
| self._die_if_manifest_project_filter('resolve') | ||
| self._dump(args, manifest.as_yaml(active_only=args.active_only, **dump_kwargs)) | ||
| elif args.freeze: | ||
| self._die_if_manifest_project_filter('freeze') | ||
| self._dump(args, manifest.as_frozen_yaml(**dump_kwargs)) | ||
| if not args.active_only: | ||
| self._die_if_manifest_project_filter('freeze') | ||
| self._dump(args, manifest.as_frozen_yaml(active_only=args.active_only, **dump_kwargs)) | ||
| elif args.untracked: | ||
| self._untracked() | ||
| elif args.path: | ||
|
|
@@ -666,7 +670,9 @@ | |
| if self.config.get('manifest.project-filter') is not None: | ||
| self.die(f'"west manifest --{action}" is not (yet) supported ' | ||
| 'when the manifest.project-filter option is set. ' | ||
| 'Please clear the project-filter configuration ' | ||
| f'Add --active-only to {action} only the projects ' | ||
| 'currently active in the workspace. Alternatively, ' | ||
| 'please clear the project-filter configuration ' | ||
| 'option and re-run this command, or contact the ' | ||
| 'west developers if you have a use case for resolving ' | ||
| 'the manifest while projects are made inactive by the ' | ||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright (c) 2018, 2019, 2020 Nordic Semiconductor ASA | ||
|
Check notice on line 1 in src/west/manifest.py
|
||
| # Copyright 2018, 2019 Foundries.io Ltd | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
@@ -1599,16 +1599,20 @@ | |
| return ret | ||
|
|
||
| def _as_dict_helper( | ||
| self, pdict: Optional[Callable[[Project], dict]] = None) \ | ||
| -> dict: | ||
| self, | ||
| pdict: Optional[Callable[[Project], dict]] = None, | ||
| pfilter: Optional[Callable[[Project], bool]] = None, | ||
| ) -> dict: | ||
| # pdict: returns a Project's dict representation. | ||
| # By default, it's Project.as_dict. | ||
| # pfilter: filter to apply on listing the projects. | ||
| # By default, no filter is applied. | ||
| if pdict is None: | ||
| pdict = Project.as_dict | ||
|
|
||
| projects = list(self.projects) | ||
| del projects[MANIFEST_PROJECT_INDEX] | ||
| project_dicts = [pdict(p) for p in projects] | ||
| project_dicts = [pdict(p) for p in projects if pfilter is None or pfilter(p)] | ||
|
pdgendt marked this conversation as resolved.
|
||
|
|
||
| # This relies on insertion-ordered dictionaries for | ||
| # predictability, which is a CPython 3.6 implementation detail | ||
|
|
@@ -1622,22 +1626,26 @@ | |
|
|
||
| return r | ||
|
|
||
| def as_dict(self) -> dict: | ||
| def as_dict(self, active_only: bool = False) -> dict: | ||
| '''Returns a dict representing self, fully resolved. | ||
|
|
||
| The value is "resolved" in that the result is as if all | ||
| projects had been defined in a single manifest without any | ||
| import attributes. | ||
|
|
||
| :param active_only: Do not resolve inactive projects | ||
| ''' | ||
| return self._as_dict_helper() | ||
| return self._as_dict_helper(pfilter=self.is_active if active_only else None) | ||
|
|
||
| def as_frozen_dict(self) -> dict: | ||
| def as_frozen_dict(self, active_only: bool = False) -> dict: | ||
| '''Returns a dict representing self, but frozen. | ||
|
|
||
| The value is "frozen" in that all project revisions are the | ||
| full SHAs pointed to by `QUAL_MANIFEST_REV_BRANCH` references. | ||
|
|
||
| Raises ``RuntimeError`` if a project SHA can't be resolved. | ||
|
|
||
| :param active_only: Do not freeze inactive projects | ||
| ''' | ||
| def pdict(p): | ||
| if not p.is_cloned(): | ||
|
|
@@ -1653,7 +1661,7 @@ | |
| d['revision'] = sha | ||
| return d | ||
|
|
||
| return self._as_dict_helper(pdict=pdict) | ||
| return self._as_dict_helper(pdict=pdict, pfilter=self.is_active if active_only else None) | ||
|
|
||
| def _dump_yaml(self, to_dump: dict, **kwargs) -> str: | ||
| ''' Dumps dictionary to YAML using the multi-line string representer. | ||
|
|
@@ -1672,28 +1680,30 @@ | |
| yaml.add_representer(_MLS, mls_representer, Dumper=yaml.SafeDumper) | ||
| return yaml.safe_dump(to_dump, **kwargs) | ||
|
|
||
| def as_yaml(self, **kwargs) -> str: | ||
| def as_yaml(self, active_only: bool = False, **kwargs) -> str: | ||
| '''Returns a YAML representation for self, fully resolved. | ||
|
|
||
| The value is "resolved" in that the result is as if all | ||
| projects had been defined in a single manifest without any | ||
| import attributes. | ||
|
|
||
| :param active_only: Do not resolve inactive projects | ||
| :param kwargs: passed to yaml.safe_dump() | ||
| ''' | ||
| return self._dump_yaml(self.as_dict(), **kwargs) | ||
| return self._dump_yaml(self.as_dict(active_only=active_only), **kwargs) | ||
|
|
||
| def as_frozen_yaml(self, **kwargs) -> str: | ||
| def as_frozen_yaml(self, active_only: bool = False, **kwargs) -> str: | ||
| '''Returns a YAML representation for self, but frozen. | ||
|
|
||
| The value is "frozen" in that all project revisions are the | ||
| full SHAs pointed to by `QUAL_MANIFEST_REV_BRANCH` references. | ||
|
|
||
| Raises ``RuntimeError`` if a project SHA can't be resolved. | ||
|
|
||
| :param active_only: Do not freeze inactive projects | ||
| :param kwargs: passed to yaml.safe_dump() | ||
| ''' | ||
| return self._dump_yaml(self.as_frozen_dict(), **kwargs) | ||
| return self._dump_yaml(self.as_frozen_dict(active_only=active_only), **kwargs) | ||
|
|
||
| @property | ||
| def projects(self) -> list[Project]: | ||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright (c) 2020, Nordic Semiconductor ASA | ||
|
Check notice on line 1 in tests/test_project.py
|
||
|
|
||
| import collections | ||
| import os | ||
|
|
@@ -407,6 +407,77 @@ | |
| '^ path: zephyr$'] | ||
| _match_multiline_regex(expected_res, actual) | ||
|
|
||
| def test_manifest_freeze_active(west_update_tmpdir): | ||
| # We should be able to freeze manifests with inactive projects. | ||
|
pdgendt marked this conversation as resolved.
|
||
| cmd('config manifest.group-filter -- -Kconfiglib-group') | ||
|
|
||
| actual = cmd('manifest --freeze --active-only').splitlines() | ||
| # Same as test_manifest_freeze but without inactive projects | ||
| expected_res = ['^manifest:$', | ||
| '^ projects:$', | ||
| '^ - name: tagged_repo$', | ||
| '^ url: .*$', | ||
| '^ revision: [a-f0-9]{40}$', | ||
| '^ - name: net-tools$', | ||
| '^ description: Networking tools.$', | ||
| '^ url: .*$', | ||
| '^ revision: [a-f0-9]{40}$', | ||
| '^ clone-depth: 1$', | ||
| '^ west-commands: scripts/west-commands.yml$', | ||
| '^ self:$', | ||
| '^ path: zephyr$'] | ||
| _match_multiline_regex(expected_res, actual) | ||
|
|
||
| def test_manifest_resolve(west_update_tmpdir): | ||
| # We should be able to resolve manifests. | ||
| actual = cmd('manifest --resolve').splitlines() | ||
| # Similar as test_manifest_freeze but with resolved projects | ||
| expected_res = ['^manifest:$', | ||
| '^ projects:$', | ||
| '^ - name: Kconfiglib$', | ||
| '^ description: |', | ||
| '^ Kconfiglib is an implementation of$', | ||
| '^ the Kconfig language written in Python.$', | ||
| '^ url: .*$', | ||
| '^ revision: zephyr$', | ||
| '^ path: subdir/Kconfiglib$', | ||
| '^ groups:$', | ||
| '^ - Kconfiglib-group$', | ||
| '^ submodules: true$', | ||
| '^ - name: tagged_repo$', | ||
| '^ url: .*$', | ||
| '^ revision: v1.0$', | ||
| '^ - name: net-tools$', | ||
| '^ description: Networking tools.$', | ||
| '^ url: .*$', | ||
| '^ revision: master$', | ||
| '^ clone-depth: 1$', | ||
| '^ west-commands: scripts/west-commands.yml$', | ||
| '^ self:$', | ||
| '^ path: zephyr$'] | ||
| _match_multiline_regex(expected_res, actual) | ||
|
|
||
| def test_manifest_resolve_active(west_update_tmpdir): | ||
| # We should be able to resolve manifests with inactive projects. | ||
| cmd('config manifest.group-filter -- -Kconfiglib-group') | ||
|
|
||
| actual = cmd('manifest --resolve --active-only').splitlines() | ||
| # Same as test_manifest_resolve but without inactive projects | ||
| expected_res = ['^manifest:$', | ||
| '^ projects:$', | ||
| '^ - name: tagged_repo$', | ||
| '^ url: .*$', | ||
| '^ revision: v1.0$', | ||
| '^ - name: net-tools$', | ||
| '^ description: Networking tools.$', | ||
| '^ url: .*$', | ||
| '^ revision: master$', | ||
| '^ clone-depth: 1$', | ||
| '^ west-commands: scripts/west-commands.yml$', | ||
| '^ self:$', | ||
| '^ path: zephyr$'] | ||
| _match_multiline_regex(expected_res, actual) | ||
|
|
||
| def test_compare(config_tmpdir, west_init_tmpdir): | ||
| # 'west compare' with no projects cloned should still work, | ||
| # and not print anything. | ||
|
|
||
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.