Beispiel #1
0
 def test_get_linker_version_for_core18(self):
     self.assertThat(
         snapcraft_legacy.ProjectOptions()._get_linker_version_for_base(
             "core18"),
         Equals("2.27"),
     )
     self.get_linker_version_mock.assert_not_called()
Beispiel #2
0
    def setUp(self):
        super().setUp()

        self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(self.fake_logger)
        self.project_options = snapcraft_legacy.ProjectOptions()

        self.fake_install_build_packages = fixtures.MockPatch(
            "snapcraft_legacy.internal.lifecycle._runner._install_build_packages",
            return_value=list(),
        )
        self.useFixture(self.fake_install_build_packages)

        self.useFixture(
            fixtures.MockPatch(
                "snapcraft_legacy.internal.project_loader._config.Config.get_build_packages",
                return_value=set(),
            ))

        self.fake_install_build_snaps = fixtures.MockPatch(
            "snapcraft_legacy.internal.lifecycle._runner._install_build_snaps",
            return_value=list(),
        )
        self.useFixture(self.fake_install_build_snaps)

        self.useFixture(
            fixtures.MockPatch(
                "snapcraft_legacy.internal.project_loader._config.Config.get_build_snaps",
                return_value=set(),
            ))
Beispiel #3
0
    def test_architecture_options(
        self,
        monkeypatch,
        machine,
        architecture,
        expected_arch_triplet,
        expected_deb_arch,
        expected_kernel_arch,
        expected_core_dynamic_linker,
    ):
        monkeypatch.setattr(platform, "architecture", lambda: architecture)
        monkeypatch.setattr(platform, "machine", lambda: machine)

        options = snapcraft_legacy.ProjectOptions()

        assert options.arch_triplet == expected_arch_triplet
        assert options.deb_arch == expected_deb_arch
        assert options.kernel_arch == expected_kernel_arch

        # The core dynamic linker is correct.  Guard against stray absolute
        # paths, as they cause os.path.join to discard the previous
        # argument.
        monkeypatch.setattr(os.path, "lexists", lambda x: True)
        monkeypatch.setattr(os.path, "islink", lambda x: False)
        expected_linker_path = os.path.join(
            common.get_installed_snap_path("core18"),
            expected_core_dynamic_linker)
        assert options.get_core_dynamic_linker(
            "core18") == expected_linker_path
Beispiel #4
0
    def setUp(self):
        super().setUp()
        self.project_options = snapcraft_legacy.ProjectOptions()

        class Options:
            source = "."

        self.options = Options()
Beispiel #5
0
 def test_get_linker_version_for_random_core(self):
     self.get_linker_version_mock.return_value = "4.10"
     self.assertThat(
         snapcraft_legacy.ProjectOptions()._get_linker_version_for_base(
             "random"),
         Equals("4.10"),
     )
     self.get_linker_version_mock.assert_called_once_with("ld-2.23.so")
Beispiel #6
0
    def test_cross_compiler_prefix_missing(self):
        options = snapcraft_legacy.ProjectOptions(target_deb_arch="x86_64")

        with testtools.ExpectedException(
                SnapcraftEnvironmentError,
                "Cross compilation not supported for target arch 'x86_64'",
        ):
            options.cross_compiler_prefix
Beispiel #7
0
    def test_compatibility(self, monkeypatch, codename, base, is_compatible):
        monkeypatch.setattr(
            snapcraft_legacy.internal.os_release.OsRelease,
            "version_codename",
            lambda x: codename,
        )

        assert (snapcraft_legacy.ProjectOptions().is_host_compatible_with_base(
            base) is is_compatible)
Beispiel #8
0
    def setUp(self):
        super().setUp()
        self.project = snapcraft_legacy.ProjectOptions()
        self.wstool = wstool.Wstool("package_path", "wstool_path",
                                    self.project, "core18")

        patcher = mock.patch("snapcraft_legacy.repo.Ubuntu")
        self.ubuntu_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("subprocess.check_output")
        self.check_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
Beispiel #9
0
    def setUp(self):
        super().setUp()
        self.project = snapcraft_legacy.ProjectOptions()

        self.rosdep = rosdep.Rosdep(
            ros_distro="melodic",
            ros_version="1",
            ros_package_path="package_path",
            rosdep_path="rosdep_path",
            ubuntu_distro="bionic",
            base="core18",
            target_arch=self.project._get_stage_packages_target_arch(),
        )

        patcher = mock.patch("snapcraft_legacy.repo.Ubuntu")
        self.ubuntu_mock = patcher.start()
        self.addCleanup(patcher.stop)

        patcher = mock.patch("subprocess.check_output")
        self.check_output_mock = patcher.start()
        self.addCleanup(patcher.stop)
Beispiel #10
0
 def setUp(self):
     super().setUp()
     self.project_options = snapcraft_legacy.ProjectOptions()
Beispiel #11
0
    def test_parts_build_env_ordering_with_deps(self):
        snapcraft_yaml = dedent(
            """\
            name: test
            base: core18
            version: "1"
            summary: test
            description: test
            confinement: strict
            grade: stable

            parts:
              part1:
                plugin: nil
              part2:
                plugin: nil
                after: [part1]
        """
        )

        self.useFixture(fixtures.EnvironmentVariable("PATH", "/bin"))

        arch_triplet = snapcraft_legacy.ProjectOptions().arch_triplet
        self.maxDiff = None
        paths = [
            os.path.join(self.stage_dir, "lib"),
            os.path.join(self.stage_dir, "lib", arch_triplet),
            os.path.join(self.stage_dir, "usr", "lib"),
            os.path.join(self.stage_dir, "usr", "lib", arch_triplet),
            os.path.join(self.stage_dir, "include"),
            os.path.join(self.stage_dir, "usr", "include"),
            os.path.join(self.stage_dir, "include", arch_triplet),
            os.path.join(self.stage_dir, "usr", "include", arch_triplet),
            os.path.join(self.parts_dir, "part1", "install", "include"),
            os.path.join(self.parts_dir, "part1", "install", "lib"),
            os.path.join(self.parts_dir, "part2", "install", "include"),
            os.path.join(self.parts_dir, "part2", "install", "lib"),
        ]
        for path in paths:
            os.makedirs(path)

        project_config = self.make_snapcraft_project(snapcraft_yaml)
        part2 = [
            part for part in project_config.parts.all_parts if part.name == "part2"
        ][0]
        env = project_config.parts.build_env_for_part(part2)
        env_lines = "\n".join(["export {}\n".format(e) for e in env])

        shell_env = {
            "CFLAGS": "-I/user-provided",
            "CXXFLAGS": "-I/user-provided",
            "CPPFLAGS": "-I/user-provided",
            "LDFLAGS": "-L/user-provided",
            "LD_LIBRARY_PATH": "/user-provided",
        }

        def get_envvar(envvar):
            with tempfile.NamedTemporaryFile(mode="w+") as f:
                f.write(env_lines)
                f.write("echo ${}".format(envvar))
                f.flush()
                output = subprocess.check_output(["/bin/sh", f.name], env=shell_env)
            return output.decode(sys.getfilesystemencoding()).strip()

        expected_cflags = (
            "-I/user-provided "
            "-isystem{parts_dir}/part2/install/include -isystem{stage_dir}/include "
            "-isystem{stage_dir}/usr/include "
            "-isystem{stage_dir}/include/{arch_triplet} "
            "-isystem{stage_dir}/usr/include/{arch_triplet}".format(
                parts_dir=self.parts_dir,
                stage_dir=self.stage_dir,
                arch_triplet=project_config.project.arch_triplet,
            )
        )
        self.assertThat(get_envvar("CFLAGS"), Equals(expected_cflags))
        self.assertThat(get_envvar("CXXFLAGS"), Equals(expected_cflags))
        self.assertThat(get_envvar("CPPFLAGS"), Equals(expected_cflags))

        self.assertThat(
            get_envvar("LDFLAGS"),
            Equals(
                "-L/user-provided "
                "-L{parts_dir}/part2/install/lib -L{stage_dir}/lib "
                "-L{stage_dir}/usr/lib -L{stage_dir}/lib/{arch_triplet} "
                "-L{stage_dir}/usr/lib/{arch_triplet}".format(
                    parts_dir=self.parts_dir,
                    stage_dir=self.stage_dir,
                    arch_triplet=project_config.project.arch_triplet,
                )
            ),
        )

        self.assertThat(
            get_envvar("LD_LIBRARY_PATH"),
            Equals(
                "/user-provided:"
                "{parts_dir}/part2/install/lib:"
                "{stage_dir}/lib:"
                "{stage_dir}/usr/lib:"
                "{stage_dir}/lib/{arch_triplet}:"
                "{stage_dir}/usr/lib/{arch_triplet}".format(
                    parts_dir=self.parts_dir,
                    stage_dir=self.stage_dir,
                    arch_triplet=project_config.project.arch_triplet,
                )
            ),
        )
Beispiel #12
0
    def setUp(self):
        super().setUp()

        self.deb_arch = snapcraft_legacy.ProjectOptions().deb_arch
        self.snap_path = os.path.join(os.path.dirname(tests.legacy.__file__),
                                      "data", "test-snap.snap")
Beispiel #13
0
 def test_cross_compiler_prefix_empty(self, mock_platform_machine,
                                      mock_platform_architecture):
     mock_platform_machine.return_value = "x86_64"
     mock_platform_architecture.return_value = ("64bit", "ELF")
     options = snapcraft_legacy.ProjectOptions(target_deb_arch="i386")
     self.assertThat(options.cross_compiler_prefix, Equals(""))