Ejemplo n.º 1
0
    def test_static_base_with_libc6_stage_packaged(self, mock_elf_patcher,
                                                   confinement):
        # The "bare" base is a static base.
        handler = load_part(
            "test-part",
            snap_type="app",
            base="bare",
            build_base="core18",
            confinement=confinement,
        )

        patcher = PartPatcher(
            elf_files=frozenset(["foo"]),
            project=handler._project,
            snap_base_path="/snap/test-snap/current",
            stage_packages=["libc6"],
        )

        patcher.patch()

        mock_elf_patcher.assert_called_once_with(
            dynamic_linker=
            "/snap/test-snap/current/lib/x86_64-linux-gnu/ld-2.27.so",
            preferred_patchelf_path=None,
            root_path=handler._project.prime_dir,
        )
Ejemplo n.º 2
0
    def test_no_patcher_called(
        self,
        monkeypatch,
        mock_partpatcher,
        snap_type,
        snap_name,
        confinement,
        build_attributes,
    ):
        monkeypatch.setattr(file_utils, "get_snap_tool_path", lambda x: x)

        part_properties = {"source-subdir": "src"}
        if build_attributes:
            part_properties["build-attributes"] = build_attributes

        handler = load_part(
            "test-part",
            snap_name=snap_name,
            part_properties=part_properties,
            snap_type=snap_type,
            confinement=confinement,
        )

        handler.prime()

        mock_partpatcher.assert_not_called()
Ejemplo n.º 3
0
    def test_patcher_called(
        self,
        monkeypatch,
        mock_partpatcher,
        confinement,
        build_attributes,
        stage_packages,
    ):
        monkeypatch.setattr(file_utils, "get_snap_tool_path", lambda x: x)

        part_properties = {"source-subdir": "src"}
        if build_attributes:
            part_properties["build-attributes"] = build_attributes
        if stage_packages:
            part_properties["stage-packages"] = stage_packages
        else:
            stage_packages = list()

        handler = load_part(
            "test-part",
            snap_type="app",
            part_properties=part_properties,
            confinement=confinement,
        )

        handler.prime()

        mock_partpatcher.assert_called_with(
            elf_files=frozenset(),
            project=mock.ANY,
            snap_base_path="/snap/fake-name/current",
            stage_packages=stage_packages,
        )
Ejemplo n.º 4
0
    def test_clean_stage(self, tmp_work_path, fileset):
        handler = load_part("test_part", part_properties={"stage": fileset})
        handler.makedirs()

        installdir = pathlib.Path(handler.part_install_dir)

        (installdir / "1/1a/1b").mkdir(parents=True)
        (installdir / "2/2a").mkdir(parents=True)
        (installdir / "3").mkdir(parents=True)

        (installdir / "a").touch()
        (installdir / "b").touch()
        (installdir / "1/a").touch()
        (installdir / "3/a").touch()

        handler.mark_done(steps.BUILD)

        # Stage the installed files
        handler.stage()

        assert os.listdir(handler._project.stage_dir) != []

        handler.clean_stage({})

        assert os.listdir(handler._project.stage_dir) == []
Ejemplo n.º 5
0
    def test_clean_prime(self, monkeypatch, tmp_work_path, fileset):
        monkeypatch.setattr(file_utils, "get_snap_tool_path", lambda x: x)

        handler = load_part("test_part", part_properties={"prime": fileset})
        handler.makedirs()

        installdir = pathlib.Path(handler.part_install_dir)

        (installdir / "1/1a/1b").mkdir(parents=True)
        (installdir / "2/2a").mkdir(parents=True)
        (installdir / "3").mkdir(parents=True)

        (installdir / "a").touch()
        (installdir / "b").touch()
        (installdir / "1/a").touch()
        (installdir / "3/a").touch()

        handler.mark_done(steps.BUILD)

        # Stage the installed files
        handler.stage()

        # Now prime them
        handler.prime()

        assert os.listdir(handler._project.prime_dir) != []

        handler.clean_prime({})

        assert os.listdir(handler._project.prime_dir) == []
Ejemplo n.º 6
0
    def test_state_file_migration(self, tmp_work_path, step):
        part_name = "foo"

        part_dir = tmp_work_path / "parts" / part_name
        part_dir.mkdir(parents=True)
        with (part_dir / "state").open("w") as state_file:
            print(step.name, file=state_file, end="")

        handler = unit.load_part(part_name)

        assert handler.latest_step() == step
Ejemplo n.º 7
0
    def test_set_in_pull(self, tmp_work_path, setter, getter, value):
        handler = unit.load_part(
            "test_part",
            part_properties={
                "override-pull": "snapcraftctl {} {}".format(setter, value)
            },
        )

        handler.pull()

        pull_metadata = handler.get_pull_state().scriptlet_metadata

        assert getattr(pull_metadata, getter)() == value
Ejemplo n.º 8
0
    def test_set_multiple_times(
        self,
        tmp_work_path,
        setter,
        value,
        override_pull,
        override_build,
        override_stage,
        override_prime,
    ):
        part_properties = {}
        if override_pull is not None:
            part_properties["override-pull"] = override_pull.format(
                setter=setter, value=value)
        if override_build is not None:
            part_properties["override-build"] = override_build.format(
                setter=setter, value=value)
        if override_stage is not None:
            part_properties["override-stage"] = override_stage.format(
                setter=setter, value=value)
        if override_prime is not None:
            part_properties["override-prime"] = override_prime.format(
                setter=setter, value=value)

        # A few of these test cases result in only one of these scriptlets
        # being set. In that case, we actually want to double them up (i.e.
        # call set-version twice in the same scriptlet), which should still be
        # an error.
        if len(part_properties) == 1:
            for key, value in part_properties.items():
                part_properties[key] += "\n{}".format(value)

        handler = unit.load_part("test_part", part_properties=part_properties)

        with testtools.ExpectedException(errors.ScriptletDuplicateFieldError):
            silent_popen = functools.partial(subprocess.Popen,
                                             stdout=subprocess.DEVNULL,
                                             stderr=subprocess.DEVNULL)

            with mock.patch("subprocess.Popen", wraps=silent_popen):
                handler.pull()
                handler.build()
                handler.stage()
                handler.prime()
Ejemplo n.º 9
0
    def test_set_in_stage(self, tmp_work_path, setter, getter, value):
        handler = unit.load_part(
            "test_part",
            part_properties={
                "override-stage": "snapcraftctl {} {}".format(setter, value)
            },
        )

        handler.pull()
        handler.build()
        handler.stage()

        pull_metadata = handler.get_pull_state().scriptlet_metadata
        build_metadata = handler.get_build_state().scriptlet_metadata
        stage_metadata = handler.get_stage_state().scriptlet_metadata

        assert getattr(pull_metadata, getter)() is None
        assert getattr(build_metadata, getter)() is None
        assert getattr(stage_metadata, getter)() == value
Ejemplo n.º 10
0
    def test_conflicting_patchelf_build_attributes(self, monkeypatch,
                                                   mock_partpatcher,
                                                   confinement):
        monkeypatch.setattr(file_utils, "get_snap_tool_path", lambda x: x)

        part_properties = {
            "source-subdir": "src",
            "build-attributes": ["no-patchelf", "enable-patchelf"],
        }

        handler = load_part(
            "test-part",
            snap_name="test-snap",
            part_properties=part_properties,
            confinement=confinement,
        )

        with pytest.raises(errors.BuildAttributePatchelfConflictError):
            handler.prime()
Ejemplo n.º 11
0
    def test_no_base(self, mock_elf_patcher, confinement):
        handler = load_part(
            "test-part",
            snap_type="app",
            base=None,
            build_base="core18",
            confinement=confinement,
        )

        patcher = PartPatcher(
            elf_files=frozenset(["foo"]),
            project=handler._project,
            snap_base_path="/snap/test-snap/current",
            stage_packages=[],
        )

        patcher.patch()

        mock_elf_patcher.assert_not_called()
Ejemplo n.º 12
0
    def test_static_base_without_libc6_stage_packaged(self, mock_elf_patcher,
                                                      confinement):
        # The "bare" base is a static base, empty, so there is no linker loader to look for.
        handler = load_part(
            "test-part",
            snap_type="app",
            base="bare",
            build_base="core18",
            confinement=confinement,
        )

        patcher = PartPatcher(
            elf_files=frozenset(["foo"]),
            project=handler._project,
            snap_base_path="/snap/test-snap/current",
            stage_packages=[],
        )

        patcher.patch()

        mock_elf_patcher.assert_not_called()
Ejemplo n.º 13
0
def test_clean_build(tmp_work_path):
    handler = load_part("test-part")

    handler.build()

    source_file = pathlib.Path(handler.part_source_dir) / "source"
    build_basedir = pathlib.Path(handler.plugin.build_basedir)
    source_file.touch()
    (build_basedir / "built").touch()
    (build_basedir / "built").touch()

    handler.clean_build()

    # Make sure the source file hasn't been touched
    assert source_file.exists()

    # Make sure the build directory is gone
    assert not build_basedir.exists()

    # Make sure the install directory is gone
    assert not pathlib.Path(handler.plugin.installdir).exists()