Exemplo n.º 1
0
    def __init__(self, project_root=None):
        # Load config
        try:
            self.project_root = os.getcwd(
            ) if project_root is None else project_root
            self.config_obj = Config(self.project_root).get_config()
            self.logger = self.config_obj["Logger"]
        except ConfigException as e:
            raise WorkflowException("Could not configure project because " +
                                    str(e))

        # Detect build system
        build_system = self.config_obj["BuildSystem"]
        try:
            if build_system == "CppCmake":
                self.builder = CppCmake(self.config_obj)
            else:
                raise WorkflowException("Invalid build system: " +
                                        str(build_system))
        except BuildException as e:
            raise WorkflowException("Could not configure build because: " +
                                    str(e))

        # Initialize other stuff
        try:
            self.resolver = DependencyResolver(self.config_obj)
            self.package = Package(self.config_obj)
        except DependencyResolverException as e:
            raise WorkflowException(
                "Could not initialize dependency resolver because: " + str(e))
Exemplo n.º 2
0
    def test_exception_on_missing_build_folder(self, mock_snap_part,
                                               mock_isdir):
        snap_part = MockSnapPart()
        mock_snap_part.side_effect = [snap_part]

        package = Package(self.config)
        self.assertRaises(PackageException, package.package)
Exemplo n.º 3
0
    def test_exception_on_snap_part_exception(self, mock_snap_part,
                                              mock_isdir):
        snap_part = MockSnapPart()
        snap_part.set_throws()
        mock_snap_part.side_effect = [snap_part]

        package = Package(self.config)
        self.assertRaises(PackageException, package.package)
Exemplo n.º 4
0
    def test_exception_on_invalid_config(self, mock_snap_part, mock_isdir):
        config = copy.deepcopy(self.config)
        del config["BuildFolder"]
        package = Package(config)
        self.assertRaises(PackageException, package.package)

        config["BuildFolder"] = "BUILD"
        del config["ProjectRoot"]
        self.assertRaises(PackageException, package.package)
Exemplo n.º 5
0
    def test_package_happy_case(self, mock_snap_part, mock_snap_cmake,
                                mock_isdir):
        mock_snap_cmake_process = MockSnapCMake()
        mock_snap_cmake.side_effect = [mock_snap_cmake_process]
        snap_part_calls = [
            call(self.config["Packaging"][0]),
            call(self.config["Packaging"][1])
        ]

        package = Package(self.config)
        package.package()

        # Validate snap part calls
        mock_snap_part.assert_has_calls(snap_part_calls, any_order=False)
        # Validate snap CMake calls
        self.assertEquals(1, mock_snap_cmake_process.invocations)

        isdir_calls = [call(self.config["BuildFolder"])]
        mock_isdir.assert_has_calls(isdir_calls)
Exemplo n.º 6
0
    def test_exception_on_missing_package_type(self, mock_isdir):
        config = copy.deepcopy(self.config)
        del config["Packaging"][0]["Type"]

        package = Package(config)
        self.assertRaises(PackageException, package.package)
Exemplo n.º 7
0
    def test_exception_on_invalid_package_type(self, mock_isdir):
        config = copy.deepcopy(self.config)
        config["Packaging"][0]["Type"] = "INVALID"

        package = Package(config)
        self.assertRaises(PackageException, package.package)
Exemplo n.º 8
0
    def test_exception_on_no_package_info(self, mock_isdir):
        config = copy.deepcopy(self.config)
        del config["Packaging"]

        package = Package(config)
        self.assertRaises(PackageException, package.package)
Exemplo n.º 9
0
class Workflow:
    STEPS = ["Bootstrap", "Build", "Test"]

    def __init__(self, project_root=None):
        # Load config
        try:
            self.project_root = os.getcwd(
            ) if project_root is None else project_root
            self.config_obj = Config(self.project_root).get_config()
            self.logger = self.config_obj["Logger"]
        except ConfigException as e:
            raise WorkflowException("Could not configure project because " +
                                    str(e))

        # Detect build system
        build_system = self.config_obj["BuildSystem"]
        try:
            if build_system == "CppCmake":
                self.builder = CppCmake(self.config_obj)
            else:
                raise WorkflowException("Invalid build system: " +
                                        str(build_system))
        except BuildException as e:
            raise WorkflowException("Could not configure build because: " +
                                    str(e))

        # Initialize other stuff
        try:
            self.resolver = DependencyResolver(self.config_obj)
            self.package = Package(self.config_obj)
        except DependencyResolverException as e:
            raise WorkflowException(
                "Could not initialize dependency resolver because: " + str(e))

    def execute_step(self, step_name):
        self.logger.info("Executing step: " + step_name + ".")
        try:
            if step_name == "Bootstrap":
                self.resolver.bfs()
            elif step_name == "Build":
                self.builder.build()
            elif step_name == "Test":
                self.builder.run_tests()
            elif step_name == "Clean":
                self.builder.clean()
            elif step_name == "Package":
                self.package.package()
            else:
                raise WorkflowException("Invalid step name.")
        except DependencyResolverException as e:
            raise WorkflowException(
                "Could not resolve dependencies because: " + str(e))
        except BuildException as e:
            raise WorkflowException(
                "Could not resolve build / test because: " + str(e))
        except PackageException as e:
            raise WorkflowException("Could not package because: " + str(e))
        self.logger.info("Finished executing step: " + step_name + ".")

    def run(self):
        for step in Workflow.STEPS:
            self.execute_step(step)