Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions charmcraft/parts/plugins/_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import json
import shlex
import shutil
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -225,6 +226,12 @@ def build(
finally:
charm_build_dir.unlink()

# charm build places .build.manifest in build_dir alongside the charm directory.
# Copy it into install_dir so it ends up in the final .charm artifact.
build_manifest = build_dir / ".build.manifest"
if build_manifest.exists():
shutil.copy2(build_manifest, install_dir / ".build.manifest")

return 0


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies = [
"distro>=1.7.0",
"docker>=7.0.0",
"humanize>=2.6.0",
"jsonschema~=4.0",
"jinja2",
"pydantic~=2.0",
"python-dateutil",
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/parts/plugins/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,37 @@ def test_get_charm_build_command(
assert _reactive._get_charm_build_command(arguments, build_dir) == expected


# Reproducer for https://github.com/canonical/charmcraft/issues/872
def test_build_includes_build_manifest(build_dir, install_dir, fake_run):
"""The .build.manifest file generated by charm build must be present in install_dir.

charm build places .build.manifest alongside the charm directory in the output dir
(i.e. in build_dir, not inside build_dir/charm_name/). The plugin must copy it
to install_dir so it ends up in the final .charm artifact.
"""

def _fake_charm_build(args, **kwargs):
# Simulate charm build writing .build.manifest into the output dir
# (alongside the charm directory, not inside it).
if args[0:2] == ["charm", "build"]:
(build_dir / ".build.manifest").write_text('{"build": "metadata"}')
return CompletedProcess(args, 0)

fake_run.side_effect = _fake_charm_build

returncode = _reactive.build(
charm_name="test-charm",
build_dir=build_dir,
install_dir=install_dir,
charm_build_arguments=[],
)

assert returncode == 0
assert (install_dir / ".build.manifest").exists(), (
".build.manifest generated by charm build must be present in the install directory"
)


def test_build(build_dir, install_dir, fake_run):
fake_run.return_value = CompletedProcess(("charm", "build"), 0)
returncode = _reactive.build(
Expand Down
Loading