Skip to content

Commit

Permalink
Merge pull request #428 from cjp256/log-status
Browse files Browse the repository at this point in the history
build: inform user that packing charm may take time (CRAFT-347)
  • Loading branch information
Chris Patterson authored Jul 2, 2021
2 parents b4af96b + 820236f commit a3560a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
46 changes: 25 additions & 21 deletions charmcraft/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import zipfile
from typing import List, Optional

from craft_providers import Executor

from charmcraft.bases import check_if_base_matches_host
from charmcraft.cmdbase import BaseCommand, CommandError
Expand Down Expand Up @@ -220,16 +219,11 @@ def run(self, bases_indices: Optional[List[int]] = None) -> List[str]:
if is_managed_mode:
charm_name = self.build_charm(bases_config)
else:
with launched_environment(
charm_name=self.metadata.name,
project_path=self.charmdir,
base=build_on,
charm_name = self.pack_charm_in_instance(
bases_index=bases_index,
build_on=build_on,
build_on_index=build_on_index,
) as instance:
charm_name = self.pack_charm_in_instance(
instance, bases_index
)
)

charms.append(charm_name)
break
Expand All @@ -253,7 +247,9 @@ def run(self, bases_indices: Optional[List[int]] = None) -> List[str]:

return charms

def pack_charm_in_instance(self, instance: Executor, bases_index: int) -> str:
def pack_charm_in_instance(
self, *, bases_index: int, build_on: Base, build_on_index: int
) -> str:
"""Pack instance in Charm."""
charm_name = format_charm_file_name(
self.metadata.name, self.config.bases[bases_index]
Expand All @@ -265,17 +261,25 @@ def pack_charm_in_instance(self, instance: Executor, bases_index: int) -> str:
elif message_handler.mode == message_handler.QUIET:
cmd.append("--quiet")

try:
instance.execute_run(
cmd,
check=True,
cwd=get_managed_environment_project_path().as_posix(),
)
except subprocess.CalledProcessError as error:
capture_logs_from_instance(instance)
raise CommandError(
f"Failed to build charm for bases index '{bases_index}'."
) from error
logger.info(f"Packing charm {charm_name!r}...")
with launched_environment(
charm_name=self.metadata.name,
project_path=self.charmdir,
base=build_on,
bases_index=bases_index,
build_on_index=build_on_index,
) as instance:
try:
instance.execute_run(
cmd,
check=True,
cwd=get_managed_environment_project_path().as_posix(),
)
except subprocess.CalledProcessError as error:
capture_logs_from_instance(instance)
raise CommandError(
f"Failed to build charm for bases index '{bases_index}'."
) from error

return charm_name

Expand Down
4 changes: 4 additions & 0 deletions tests/commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ def test_build_bases_index_scenarios_provider(
),
call().__exit__(None, None, None),
]
assert (
f"Packing charm 'name-from-metadata_ubuntu-18.04-{host_arch}.charm'..."
in [r.message for r in caplog.records]
)
mock_ensure_provider_is_available.assert_called_once()
mock_launch.reset_mock()

Expand Down

0 comments on commit a3560a4

Please sign in to comment.