示例#1
0
    def _prepare_step(self, *, step: steps.Step,
                      part: pluginhandler.PluginHandler):
        common.reset_env()
        all_dependencies = self.parts_config.get_dependencies(part.name)

        # Filter dependencies down to only those that need to run the
        # prerequisite step
        prerequisite_step = steps.get_dependency_prerequisite_step(step)
        dependencies = {
            p
            for p in all_dependencies
            if self._cache.should_step_run(p, prerequisite_step)
        }

        if dependencies:
            dependency_names = {p.name for p in dependencies}
            # Dependencies need to go all the way to the prerequisite step to
            # be able to share the common assets that make them a dependency
            logger.info("{!r} has dependencies that need to be {}d: {}".format(
                part.name, prerequisite_step.name, " ".join(dependency_names)))
            self.run(prerequisite_step, dependency_names)

        # Run the preparation function for this step (if implemented)
        preparation_function = getattr(part, "prepare_{}".format(step.name),
                                       None)
        if preparation_function:
            notify_part_progress(part,
                                 "Preparing to {}".format(step.name),
                                 debug=True)
            preparation_function()

        common.env = self.parts_config.build_env_for_part(part)
        common.env.extend(self.config.project_env())

        part = _replace_in_part(part)
示例#2
0
文件: _runner.py 项目: mvo5/snapcraft
    def _prepare_step(self, *, step: steps.Step, part: pluginhandler.PluginHandler):
        common.reset_env()
        all_dependencies = self.parts_config.get_dependencies(part.name)

        # Filter dependencies down to only those that need to run the
        # prerequisite step
        prerequisite_step = steps.get_dependency_prerequisite_step(step)
        dependencies = {
            p
            for p in all_dependencies
            if self._cache.should_step_run(p, prerequisite_step)
        }

        if dependencies:
            dependency_names = {p.name for p in dependencies}
            # Dependencies need to go all the way to the prerequisite step to
            # be able to share the common assets that make them a dependency
            logger.info(
                "{!r} has dependencies that need to be {}d: {}".format(
                    part.name, prerequisite_step.name, " ".join(dependency_names)
                )
            )
            self.run(prerequisite_step, dependency_names)

        # Run the preparation function for this step (if implemented)
        preparation_function = getattr(part, "prepare_{}".format(step.name), None)
        if preparation_function:
            notify_part_progress(part, "Preparing to {}".format(step.name), debug=True)
            preparation_function()

        common.env = self.parts_config.build_env_for_part(part)
        common.env.extend(self.config.project_env())

        part = _replace_in_part(part)
示例#3
0
    def _ensure_dirty_report(self, part: pluginhandler.PluginHandler,
                             step: steps.Step) -> None:
        # If we already have a dirty report, bail
        if step in self._dirty_reports[part.name]:
            return

        # Get the dirty report from the PluginHandler. If it's dirty, we can
        # stop here
        self._dirty_reports[part.name][step] = part.get_dirty_report(step)

        # The dirty report from the PluginHandler only takes into account
        # properties specific to that part. If it's not dirty because of those,
        # we need to expand it here to also take its dependencies (if any) into
        # account
        dependencies = self.config.parts.get_dependencies(part.name,
                                                          recursive=True)

        # core20 uses Plugins V2 which does not require staging parts for pull
        # like V1 Plugins do.
        if (self.config.project._get_build_base() == "core20"
                and part._build_attributes.core22_step_dependencies()):
            prerequisite_step = step
        else:
            prerequisite_step = steps.get_dependency_prerequisite_step(step)

        changed_dependencies: List[pluginhandler.Dependency] = []
        with contextlib.suppress(errors.StepHasNotRunError):
            timestamp = part.step_timestamp(step)
            for dependency in dependencies:
                # Make sure the prerequisite step of this dependency has not
                # run more recently than (or should run _before_) this step.
                try:
                    prerequisite_timestamp = dependency.step_timestamp(
                        prerequisite_step)
                except errors.StepHasNotRunError:
                    dependency_changed = True
                else:
                    dependency_changed = timestamp < prerequisite_timestamp

                if dependency_changed or self.should_step_run(
                        dependency, prerequisite_step):
                    changed_dependencies.append(
                        pluginhandler.Dependency(part_name=dependency.name,
                                                 step=prerequisite_step))

            if changed_dependencies:
                self._dirty_reports[
                    part.name][step] = pluginhandler.DirtyReport(
                        changed_dependencies=changed_dependencies)
示例#4
0
    def _ensure_dirty_report(
        self, part: pluginhandler.PluginHandler, step: steps.Step
    ) -> None:
        # If we already have a dirty report, bail
        if step in self._dirty_reports[part.name]:
            return

        # Get the dirty report from the PluginHandler. If it's dirty, we can
        # stop here
        self._dirty_reports[part.name][step] = part.get_dirty_report(step)
        if self._dirty_reports[part.name][step]:
            return

        # The dirty report from the PluginHandler only takes into account
        # properties specific to that part. If it's not dirty because of those,
        # we need to expand it here to also take its dependencies (if any) into
        # account
        prerequisite_step = steps.get_dependency_prerequisite_step(step)
        dependencies = self.config.parts.get_dependencies(part.name, recursive=True)

        changed_dependencies = []  # type: List[pluginhandler.Dependency]
        with contextlib.suppress(errors.StepHasNotRunError):
            timestamp = part.step_timestamp(step)
            for dependency in dependencies:
                # Make sure the prerequisite step of this dependency has not
                # run more recently than (or should run _before_) this step.
                try:
                    prerequisite_timestamp = dependency.step_timestamp(
                        prerequisite_step
                    )
                except errors.StepHasNotRunError:
                    dependency_changed = True
                else:
                    dependency_changed = timestamp < prerequisite_timestamp

                if dependency_changed or self.should_step_run(
                    dependency, prerequisite_step
                ):
                    changed_dependencies.append(
                        pluginhandler.Dependency(
                            part_name=dependency.name, step=prerequisite_step
                        )
                    )

            if changed_dependencies:
                self._dirty_reports[part.name][step] = pluginhandler.DirtyReport(
                    changed_dependencies=changed_dependencies
                )
示例#5
0
    def _handle_part_dependencies(
        self, *, step: steps.Step, part: pluginhandler.PluginHandler
    ) -> None:
        # core20 uses Plugins V2 which does not require staging parts for pull
        # like V1 Plugins do.
        if (
            part._build_attributes.core22_step_dependencies()
            and self.project._get_build_base() == "core20"
            and step == steps.PULL
        ):
            return
        elif (
            part._build_attributes.core22_step_dependencies()
            and self.project._get_build_base() != "core20"
        ):
            logger.warning(
                f"Ignoring core22 lifecycle request for {part.name!r} as it is only supported for core20."
            )

        all_dependencies = self.parts_config.get_dependencies(part.name)

        # Filter dependencies down to only those that need to run the
        # prerequisite step
        prerequisite_step = steps.get_dependency_prerequisite_step(step)

        dependencies = {
            p
            for p in all_dependencies
            if self._cache.should_step_run(p, prerequisite_step)
        }

        if dependencies:
            dependency_names = {p.name for p in dependencies}
            # Dependencies need to go all the way to the prerequisite step to
            # be able to share the common assets that make them a dependency
            logger.info(
                "{!r} has dependencies that need to be {}d: {}".format(
                    part.name, prerequisite_step.name, " ".join(dependency_names)
                )
            )
            self.run(prerequisite_step, dependency_names)