Skip to content

Commit

Permalink
Build and test cmake_gcc_arm
Browse files Browse the repository at this point in the history
resolves #347
  • Loading branch information
theotherjimmy committed Jun 16, 2016
1 parent 3bcdd2f commit aa27fcd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project_generator/templates/cmakelistgccarm.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ set(SOURCES_S ${SOURCES_S} "{{file}}"){% endfor %}
{% for file in source_files_obj %}
set(OBJECT_FILES ${OBJECT_FILES} "{{file}}"){% endfor %}

set(COMMON_FLAGS "-mcpu={{core}} {% for flag in misc['common_flags'] %} {{flag}}{% endfor %}")
set(COMMON_FLAGS "-mcpu={{core}} -mthumb {% for flag in misc['common_flags'] %} {{flag}}{% endfor %}")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} ${DEFINES} {% for flag in misc['cxx_flags'] %} {{flag}}{% endfor %}")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} ${DEFINES} {% for flag in misc['c_flags'] %} {{flag}}{% endfor %}")
set(CMAKE_EXE_LINKER_FLAGS "-mcpu={{core}} {% for flag in misc['linker_flags'] %} {{flag}}{% endfor %}")
Expand Down
65 changes: 65 additions & 0 deletions project_generator/tools/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@
# limitations under the License.

import copy
import logging
import subprocess
from os import getcwd
from os.path import dirname

from .tool import Tool, Exporter
from .gccarm import MakefileGccArm
from ..util import SOURCE_KEYS

logger = logging.getLogger('progen.tools.cmake_gcc_arm')

class CMakeGccArm(Tool,Exporter):

SUCCESSVALUE = 0
ERRORLEVEL = {
0: 'no errors)',
1: 'targets not already up to date',
2: 'errors'
}

generated_project = {
'path': '',
'files': {
Expand Down Expand Up @@ -82,3 +94,56 @@ def export_project(self):

def get_generated_project_files(self):
return {'path': self.workspace['path'], 'files': [self.workspace['files']['cmakelist']]}

def build_project(self):
# cwd: relpath(join(project_path, ("gcc_arm" + project)))
# > make all
path = dirname(self.workspace['files']['cmakelist'])
logging.debug("Building GCC ARM project: %s" % path)

args = ['cmake', '.']
logging.debug(args)

try:
ret_code = None
ret_code = subprocess.call(args, cwd=path)
except:
logging.error("Project: %s build error whilst calling cmake. Is it in your PATH?" % self.workspace['files']['cmakelist'])
return -1
else:
if ret_code != self.SUCCESSVALUE:
# Seems like something went wrong.
if ret_code < 3:
logging.error("Project: %s build failed with the status: %s" %
(self.ERRORLEVEL[ret_code], self.workspace['files']['makefile']))
else:
logging.error("Project: %s build failed with unknown error. Returned: %s" %
(ret_code, self.workspace['files']['makefile']))
return -1
else:
logging.info("CMake succeeded with the status: %s" %
self.ERRORLEVEL[ret_code])

args = ['make', 'all']
logging.debug(args)

try:
ret_code = None
ret_code = subprocess.call(args, cwd=path)
except:
logging.error("Project: build error whilst calling make. Is it in your PATH?")
return -1
else:
if ret_code != self.SUCCESSVALUE:
# Seems like something went wrong.
if ret_code < 3:
logging.error("Project: make failed with the status: %s" %
(self.ERRORLEVEL[ret_code]))
else:
logging.error("Project:make failed with unknown error. Returned: %s" %
(ret_code))
return -1
else:
logging.info("Build succeeded with the status: %s" %
self.ERRORLEVEL[ret_code])
return 0
7 changes: 7 additions & 0 deletions tests/test_commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def test_build_project_make_gcc_arm_tool(self):

assert result == -1

def test_build_project_cmake_gcc_arm_tool(self):
args = self.parser.parse_args(['build','-f','test_workspace/projects.yaml','-p',
'project_2', '-t', 'cmake_gcc_arm'])
result = build.run(args)

assert result == -1

def test_build_project_make_armcc_tool(self):
args = self.parser.parse_args(['build','-f','test_workspace/projects.yaml','-p',
'project_2', '-t', 'make_armcc'])
Expand Down

0 comments on commit aa27fcd

Please sign in to comment.