Exemplo n.º 1
0
def test_unsupported_base_raises(flutter_options):
    project = Project()
    project._snap_meta = Snap(name="test-snap", base="bad-base", confinement="strict")

    with pytest.raises(errors.PluginBaseError):
        flutter.FlutterPlugin("test-part", flutter_options, project)
Exemplo n.º 2
0
    def __init__(self, project: project.Project) -> None:
        self.build_snaps: Set[str] = set()
        self.project = project

        # raw_snapcraft_yaml is read only, create a new copy
        snapcraft_yaml = apply_extensions(project.info.get_raw_snapcraft())

        self.validator = Validator(snapcraft_yaml)
        self.validator.validate()

        snapcraft_yaml = self._expand_filesets(snapcraft_yaml)

        self.data = self._expand_env(snapcraft_yaml)

        self.data["architectures"] = _process_architectures(
            self.data.get("architectures"), project.deb_arch)

        self._ensure_no_duplicate_app_aliases()

        grammar_processor = grammar_processing.GlobalGrammarProcessor(
            properties=self.data, project=project)

        keys_path = project._get_keys_path()
        if any([
                package_repo.install(keys_path=keys_path)
                for package_repo in project._snap_meta.package_repositories
        ]):
            repo.Repo.refresh_build_packages()

        self.build_tools = grammar_processor.get_build_packages()
        self.build_tools |= set(project.additional_build_packages)

        # If version: git is used we want to add "git" to build-packages
        if self.data.get("version") == "git":
            self.build_tools.add("git")

        # XXX: Resetting snap_meta due to above mangling of data.
        # Convergence to operating on snap_meta will remove this requirement...
        project._snap_meta = Snap.from_dict(self.data)

        # Always add the base for building for non os and base snaps
        if project.info.base is None and project.info.type in ("app",
                                                               "gadget"):
            raise SnapcraftEnvironmentError(
                "A base is required for snaps of type {!r}.".format(
                    project.info.type))
        if project.info.base is not None:
            # If the base is already installed by other means, skip its installation.
            # But, we should always add it when in a docker environment so
            # the creator of said docker image is aware that it is required.
            if common.is_process_container(
            ) or not repo.snaps.SnapPackage.is_snap_installed(
                    project.info.base):
                self.build_snaps.add(project.info.base)

        self.parts = PartsConfig(
            parts=self.data,
            project=project,
            validator=self.validator,
            build_snaps=self.build_snaps,
            build_tools=self.build_tools,
        )
Exemplo n.º 3
0
def test_setup_environment_content_x86(
    tmp_work_path, monkeypatch, machine_platform, distro
):
    snapcraft_project = Project()
    snapcraft_project._snap_meta = Snap(name="test-snap", base=distro[0])

    monkeypatch.setattr(platform, "machine", lambda: machine_platform[0])

    recorded_files = dict()

    @contextlib.contextmanager
    def fake_namedtempfile(*, suffix: str, **kwargs):
        # Usage hides the file basename in the suffix.
        tmp_path = os.path.join("tmpfile")
        with open(tmp_path, "wb") as f_write:
            yield f_write
        with open(tmp_path, "r") as f_read:
            recorded_files[suffix] = f_read.read()

    monkeypatch.setattr(tempfile, "NamedTemporaryFile", fake_namedtempfile)

    provider = ProviderImpl(project=snapcraft_project, echoer=Mock())
    provider._setup_environment()

    assert recorded_files == {
        ".bashrc": '#!/bin/bash\nexport PS1="\\h \\$(/bin/_snapcraft_prompt)# "\n',
        "00-snapcraft": 'Apt::Install-Recommends "false";\n',
        "_snapcraft_prompt": dedent(
            """\
            #!/bin/bash
            if [[ "$PWD" =~ ^$HOME.* ]]; then
                path="${PWD/#$HOME/\\ ..}"
                if [[ "$path" == " .." ]]; then
                    ps1=""
                else
                    ps1="$path"
                fi
            else
                ps1="$PWD"
            fi
            echo -n $ps1
            """
        ),
        "default.sources": dedent(
            f"""\
                Types: deb
                URIs: {machine_platform[1]["main"]}
                Suites: {distro[1]} {distro[1]}-updates
                Components: main multiverse restricted universe
            """
        ),
        "default-security.sources": dedent(
            f"""\
                Types: deb
                URIs: {machine_platform[1]["security"]}
                Suites: {distro[1]}-security
                Components: main multiverse restricted universe
            """
        ),
        "sources.list": "",
    }