Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and test cmake_gcc_arm #401

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion project_generator/templates/cmakelistgccarm.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ set(CMAKE_SYSTEM_PROCESSOR {{core}})
find_program(ARM_NONE_EABI_GCC arm-none-eabi-gcc)
find_program(ARM_NONE_EABI_GPP arm-none-eabi-g++)
find_program(ARM_NONE_EABI_OBJCOPY arm-none-eabi-objcopy)
if ((ARM_NONE_EABI_GCC MATCHES ".*-NOTFOUND") OR
(ARM_NONE_EABI_GPP MATCHES ".*-NOTFOUND") OR
(ARM_NONE_EABI_OBJCOPY MATCHES ".*-NOTFOUND"))
MESSAGE(FATAL_ERROR "Could not find the arm-none-eabi gnu toolchain")
endif()

cmake_force_c_compiler("${ARM_NONE_EABI_GCC}" GNU)
cmake_force_cxx_compiler("${ARM_NONE_EABI_GPP}" GNU)
Expand Down Expand Up @@ -64,7 +69,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 %}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be in the common flags ? I would assume arm mode is possible, not only thumb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm matching the makefile template for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok we can fix that later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#402 opened to address that issue in the future.

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
66 changes: 66 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,57 @@ 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: 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("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