From 9f67629f7aec7b4ab6c8fbf4967ec0c6d497c484 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 16:31:42 +0000 Subject: [PATCH 1/6] Test - add test for tool supported class --- project_generator/tools/coide.py | 4 +- tests/test_tools_supported.py | 113 +++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 tests/test_tools_supported.py diff --git a/project_generator/tools/coide.py b/project_generator/tools/coide.py index 8106aa13..ff58f52b 100644 --- a/project_generator/tools/coide.py +++ b/project_generator/tools/coide.py @@ -63,11 +63,11 @@ def __init__(self, workspace, env_settings): @staticmethod def get_toolnames(): - return ['gcc_arm'] + return ['coide'] @staticmethod def get_toolchain(): - return 'coide' + return 'gcc_arm' def _expand_data(self, old_data, new_data, attribute, group): """ data expansion - coide needs filename and path separately """ diff --git a/tests/test_tools_supported.py b/tests/test_tools_supported.py new file mode 100644 index 00000000..95a053c3 --- /dev/null +++ b/tests/test_tools_supported.py @@ -0,0 +1,113 @@ +# Copyright 2015 0xc0170 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from unittest import TestCase + +from project_generator.tools_supported import ToolsSupported +from project_generator.tools.uvision import Uvision +from project_generator.tools.iar import IAREmbeddedWorkbench +from project_generator.tools.coide import Coide +from project_generator.tools.gccarm import MakefileGccArm +from project_generator.tools.eclipse import EclipseGnuARM +from project_generator.tools.sublimetext import SublimeTextMakeGccARM +from project_generator.tools.cmake import CMakeGccArm +from project_generator.tools.visual_studio import VisualStudioMakeGCCARM, VisualStudioGDB + + +class TestProject(TestCase): + + """test things related to the ToolsSupported class""" + + def setUp(self): + self.tools = ToolsSupported() + + def tearDown(self): + pass + + def test_tools(self): + tool = self.tools.get_tool('uvision4') + assert tool == Uvision + tool = self.tools.get_tool('iar') + assert tool == IAREmbeddedWorkbench + tool = self.tools.get_tool('coide') + assert tool == Coide + tool = self.tools.get_tool('gcc_arm') + assert tool == MakefileGccArm + tool = self.tools.get_tool('eclipse_make_gcc_arm') + assert tool == EclipseGnuARM + tool = self.tools.get_tool('sublime_make_gcc_arm') + assert tool == SublimeTextMakeGccARM + tool = self.tools.get_tool('cmake_gcc_arm') + assert tool == CMakeGccArm + tool = self.tools.get_tool('visual_studio_make_gcc_arm') + assert tool == VisualStudioMakeGCCARM + + def test_alias(self): + tool = self.tools.get_tool('uvision') + assert tool == Uvision + tool = self.tools.get_tool('iar') + assert tool == IAREmbeddedWorkbench + tool = self.tools.get_tool('make_gcc') + assert tool == MakefileGccArm + tool = self.tools.get_tool('gcc_arm') + assert tool == MakefileGccArm + tool = self.tools.get_tool('sublime_text') + assert tool == SublimeTextMakeGccARM + tool = self.tools.get_tool('sublime') + assert tool == SublimeTextMakeGccARM + tool = self.tools.get_tool('visual_studio') + assert tool == VisualStudioMakeGCCARM + tool = self.tools.get_tool('eclipse') + assert tool == EclipseGnuARM + + def test_toolnames(self): + names = self.tools.get_toolnames('uvision') + assert 'uvision' == names[0] + toolchain = self.tools.get_toolchain('uvision') + assert 'uvision' == toolchain + + names = self.tools.get_toolnames('uvision4') + assert 'uvision' == names[0] + toolchain = self.tools.get_toolchain('uvision4') + assert 'uvision' == toolchain + + names = self.tools.get_toolnames('iar_arm') + assert 'iar_arm' == names[0] + toolchain = self.tools.get_toolchain('iar_arm') + assert 'iar' == toolchain + + names = self.tools.get_toolnames('coide') + assert 'coide' == names[0] + toolchain = self.tools.get_toolchain('coide') + assert 'gcc_arm' == toolchain + + names = self.tools.get_toolnames('make_gcc_arm') + assert 'make_gcc_arm' == names[0] + toolchain = self.tools.get_toolchain('make_gcc_arm') + assert 'gcc_arm' == toolchain + + names = self.tools.get_toolnames('eclipse_make_gcc_arm') + assert 'eclipse_make_gcc_arm' == names[0] + toolchain = self.tools.get_toolchain('eclipse_make_gcc_arm') + assert 'gcc_arm' == toolchain + + names = self.tools.get_toolnames('sublime_make_gcc_arm') + assert 'sublime_make_gcc_arm' == names[0] + toolchain = self.tools.get_toolchain('sublime_make_gcc_arm') + assert 'gcc_arm' == toolchain + + names = self.tools.get_toolnames('cmake_gcc_arm') + assert 'cmake_gcc_arm' == names[0] + toolchain = self.tools.get_toolchain('cmake_gcc_arm') + assert 'gcc_arm' == toolchain From e88011f5ffc3536a5b9d10c6dd21c1ed00a41d6d Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 16:38:30 +0000 Subject: [PATCH 2/6] Test export rename to generate --- tests/test_commands/{test_export.py => test_generate.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/test_commands/{test_export.py => test_generate.py} (100%) diff --git a/tests/test_commands/test_export.py b/tests/test_commands/test_generate.py similarity index 100% rename from tests/test_commands/test_export.py rename to tests/test_commands/test_generate.py From b6af0251d031b4035b4c15f213bb81aa64bcff1b Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 16:40:36 +0000 Subject: [PATCH 3/6] Tools supported - cmake alias --- project_generator/tools_supported.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/project_generator/tools_supported.py b/project_generator/tools_supported.py index 8f865fcd..8959b2ad 100644 --- a/project_generator/tools_supported.py +++ b/project_generator/tools_supported.py @@ -28,14 +28,15 @@ class ToolsSupported: # Default tools - aliases TOOLS_ALIAS = { - 'uvision': 'uvision4', - 'iar': 'iar_arm', - 'make_gcc': 'make_gcc_arm', - 'gcc_arm': 'make_gcc_arm', - 'eclipse': 'eclipse_make_gcc_arm', - 'sublime': 'sublime_make_gcc_arm', - 'sublime_text': 'sublime_make_gcc_arm', + 'uvision': 'uvision4', + 'iar': 'iar_arm', + 'make_gcc': 'make_gcc_arm', + 'gcc_arm': 'make_gcc_arm', + 'eclipse': 'eclipse_make_gcc_arm', + 'sublime': 'sublime_make_gcc_arm', + 'sublime_text': 'sublime_make_gcc_arm', 'visual_studio': 'visual_studio_make_gcc_arm', + 'cmake': 'cmake_gcc_arm', } # Tools dictionary From e81fd02cc7431ea01416126b88a22b4bba9b755e Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 16:43:00 +0000 Subject: [PATCH 4/6] Test - add cmake test tool --- tests/test_tools/test_cmake.py | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test_tools/test_cmake.py diff --git a/tests/test_tools/test_cmake.py b/tests/test_tools/test_cmake.py new file mode 100644 index 00000000..2d52fbe3 --- /dev/null +++ b/tests/test_tools/test_cmake.py @@ -0,0 +1,55 @@ +# Copyright 2015 0xc0170 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os +import yaml +import shutil + +from unittest import TestCase + +from project_generator.generate import Generator +from project_generator.project import Project +from project_generator.settings import ProjectSettings +from project_generator.tools.cmake import CMakeGccArm + +from .simple_project import project_1_yaml, projects_1_yaml + +class TestProject(TestCase): + + """test things related to the cmake tool""" + + def setUp(self): + if not os.path.exists('test_workspace'): + os.makedirs('test_workspace') + # write project file + with open(os.path.join(os.getcwd(), 'test_workspace/project_1.yaml'), 'wt') as f: + f.write(yaml.dump(project_1_yaml, default_flow_style=False)) + # write projects file + with open(os.path.join(os.getcwd(), 'test_workspace/projects.yaml'), 'wt') as f: + f.write(yaml.dump(projects_1_yaml, default_flow_style=False)) + + self.project = next(Generator(projects_1_yaml).generate('project_1')) + + self.cmake = CMakeGccArm(self.project.project, ProjectSettings()) + + def tearDown(self): + # remove created directory + shutil.rmtree('test_workspace', ignore_errors=True) + shutil.rmtree('generated_projects', ignore_errors=True) + + def test_export_project(self): + result = self.project.generate('cmake_gcc_arm', False) + projectfiles = self.project.get_generated_project_files('cmake_gcc_arm') + + assert result == 0 + assert projectfiles From fc309c634d645a07f0f79d2c41bbeebd50d734d8 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 17:01:56 +0000 Subject: [PATCH 5/6] Cmake - fix rel path for cmake --- project_generator/tools/cmake.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project_generator/tools/cmake.py b/project_generator/tools/cmake.py index 6e0e60f4..fca42187 100644 --- a/project_generator/tools/cmake.py +++ b/project_generator/tools/cmake.py @@ -48,14 +48,14 @@ def fix_paths_unix(self, data): paths = [] for value in data[key]: # TODO: this needs to be fixed - paths.append(getcwd().replace('\\', '/') + '/' + data['output_dir']['path'] + '/' + value.replace('\\', '/')) + paths.append(getcwd().replace('\\', '/') + '/' + data['output_dir']['path'].replace('\\', '/') + '/' + value.replace('\\', '/')) data[key] = paths # fix includes includes = [] for key in data['include_paths']: - includes.append(getcwd().replace('\\', '/') + '/' + data['output_dir']['path'] + '/' + key.replace('\\', '/')) + includes.append(getcwd().replace('\\', '/') + '/' + data['output_dir']['path'].replace('\\', '/') + '/' + key.replace('\\', '/')) data['include_paths'] = includes - data['linker_file'] = getcwd().replace('\\', '/') + '/' + data['output_dir']['path'] + '/' + data['linker_file'].replace('\\', '/') + data['linker_file'] = getcwd().replace('\\', '/') + '/' + data['output_dir']['path'].replace('\\', '/') + '/' + data['linker_file'].replace('\\', '/') def export_project(self): generated_projects = {} From bb3d2927437a51d8144ec398085876bc3dedb5f6 Mon Sep 17 00:00:00 2001 From: Martin Kojtal Date: Fri, 11 Dec 2015 17:05:43 +0000 Subject: [PATCH 6/6] Clean command - tool help fix --- project_generator/commands/clean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_generator/commands/clean.py b/project_generator/commands/clean.py index 7b52bce9..e5345bf9 100644 --- a/project_generator/commands/clean.py +++ b/project_generator/commands/clean.py @@ -34,4 +34,4 @@ def setup(subparser): subparser.add_argument("-f", "--file", help="YAML projects file", default='projects.yaml') subparser.add_argument("-p", "--project", required = True, help="Specify which project to be removed") subparser.add_argument( - "-t", "--tool", help="Clean project files") + "-t", "--tool", help="Clean project files for this tool")