Skip to content

Commit

Permalink
Merge branch 'main' into ROCKS-987/docs-live-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Linostar authored Mar 7, 2024
2 parents 5aaea18 + e34a75f commit 683af29
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-parts==1.26.1
craft-providers==1.22.0
craft-providers==1.23.0
cryptography==42.0.2
Deprecated==1.2.14
dill==0.3.8
Expand Down
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-parts==1.26.1
craft-providers==1.22.0
craft-providers==1.23.0
Deprecated==1.2.14
distro==1.9.0
docutils==0.19
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ craft-application==1.2.1
craft-archives==1.1.3
craft-cli==2.5.1
craft-parts==1.26.1
craft-providers==1.22.0
craft-providers==1.23.0
Deprecated==1.2.14
distro==1.9.0
httplib2==0.22.0
Expand Down
28 changes: 28 additions & 0 deletions rockcraft/services/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,32 @@ def _post_prime_callback(step_info: StepInfo) -> bool:
files = step_info.state.files if step_info.state else set()

layers.prune_prime_files(prime_dir, files, base_layer_dir)

_python_usrmerge_fix(step_info)

return True


def _python_usrmerge_fix(step_info: StepInfo):
"""Fix 'lib64' symlinks created by the Python plugin on [email protected] projects."""
if step_info.project_info.base != "[email protected]":
# The issue only affects rocks with 24.04 bases.
return

state = step_info.state
if state is None:
# Can't inspect the files without a StepState.
return

if state.part_properties["plugin"] != "python":
# Be conservative and don't try to fix the files if they didn't come
# from the Python plugin.
return

if "lib64" not in state.files:
return

prime_dir = step_info.prime_dir
lib64 = prime_dir / "lib64"
if lib64.is_symlink() and lib64.readlink() == Path("lib"):
lib64.unlink()
50 changes: 49 additions & 1 deletion tests/unit/services/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from pathlib import Path
from unittest import mock

import pytest
from craft_parts import LifecycleManager, callbacks
from craft_parts import (
LifecycleManager,
Part,
PartInfo,
ProjectDirs,
ProjectInfo,
Step,
StepInfo,
callbacks,
)
from craft_parts.state_manager.prime_state import PrimeState

from rockcraft.services import lifecycle as lifecycle_module

Expand Down Expand Up @@ -78,3 +89,40 @@ def test_lifecycle_package_repositories(
mock_callback.assert_called_once_with(
lifecycle_module._install_overlay_repositories
)


def test_python_usrmerge_fix(tmp_path):
# The test setup is rather involved because we need to recreate/mock an
# exact set of circumstances here:

# 1) Create a project with 24.04 base;
dirs = ProjectDirs(work_dir=tmp_path)
project_info = ProjectInfo(
project_dirs=dirs,
application_name="test",
cache_dir=tmp_path,
strict_mode=False,
base="[email protected]",
)

# 2) Create a part using the Python plugin;
part = Part("p1", {"source": ".", "plugin": "python"})
part_info = PartInfo(project_info=project_info, part=part)

prime_dir = dirs.prime_dir
prime_dir.mkdir()

# 3) Setup a 'prime' directory where "lib64" is a symlink to "lib";
(prime_dir / "lib").mkdir()
(prime_dir / "lib64").symlink_to("lib")

# 4) Create a StepInfo that contains all of this.
step_info = StepInfo(part_info=part_info, step=Step.PRIME)
step_info.state = PrimeState(part_properties=part.spec.marshal(), files={"lib64"})

assert sorted(os.listdir(prime_dir)) == ["lib", "lib64"]

lifecycle_module._python_usrmerge_fix(step_info)

# After running the fix the "lib64" symlink must be gone
assert sorted(os.listdir(prime_dir)) == ["lib"]

0 comments on commit 683af29

Please sign in to comment.