commands: project: use cached manifest instead of reparsing

Now that we have a self.manifest attribute which returns the manifest
when it's available and fails gracefully when it isn't, we can avoid
re-parsing the manifest in the project command implementations.

Note this change is more convenient to make after having introduced
_ProjectCommand to allow accessing per-instance state from each of
these commands, instead of using standalone module-level functions.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Marti Bolivar 2019-08-15 10:30:21 -07:00 committed by Carles Cufí
parent 7694f88a07
commit 52261a25f4
1 changed files with 6 additions and 17 deletions

View File

@ -48,17 +48,6 @@ class _ProjectCommand(WestCommand):
help='''projects (by name or path) to operate on;
defaults to all projects in the manifest''')
def _all_projects(self):
# Get a list of project objects from the manifest.
#
# If the manifest is malformed, a fatal error occurs and the
# command aborts.
try:
return list(Manifest.from_file().projects)
except MalformedManifest as m:
log.die(m.args[0])
def _cloned_projects(self, args):
# Returns _projects(args, listed_must_be_cloned=True) if a
# list of projects was given by the user (i.e., listed
@ -67,7 +56,7 @@ class _ProjectCommand(WestCommand):
# This approach avoids redundant _cloned() checks
return self._projects(args) if args.projects else \
[project for project in self._all_projects() if _cloned(project)]
[project for project in self.manifest.projects if _cloned(project)]
def _projects(self, args, listed_must_be_cloned=True,
exclude_manifest=False):
@ -78,9 +67,6 @@ class _ProjectCommand(WestCommand):
# projects will be returned. If a non-existent project was
# listed by the user, an error is raised.
#
# Before the manifest is parsed, it is validated agains a
# pykwalify schema. An error is raised on validation errors.
#
# listed_must_be_cloned (default: True):
# If True, an error is raised if an uncloned project was listed. This
# only applies to projects listed explicitly on the command line.
@ -89,7 +75,7 @@ class _ProjectCommand(WestCommand):
# If True, the manifest project will not be included in the returned
# list.
projects = self._all_projects()
projects = list(self.manifest.projects)
if exclude_manifest:
projects.pop(MANIFEST_PROJECT_INDEX)
@ -279,7 +265,10 @@ class Init(_ProjectCommand):
self.create(west_dir)
os.chdir(topdir)
projects = self.projects(manifest_file) # This validates the manifest.
# This validates the manifest. Note we cannot use
# self.manifest from west init, as we are in the middle of
# creating the installation right now.
projects = self.projects(manifest_file)
_msg('Creating {} and local configuration'.format(west_dir))
update_config('manifest', 'path', rel_manifest)