From c968bc2f860900089d9cb9090ad7c8f9cdebefe7 Mon Sep 17 00:00:00 2001 From: "Matthias L. Jugel" Date: Sat, 13 Jan 2018 11:25:22 +0100 Subject: [PATCH] add ci build operations --- tools/export/cmake/CMakeLists.txt.tmpl | 18 ++++++++++++---- tools/export/cmake/__init__.py | 30 +++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/tools/export/cmake/CMakeLists.txt.tmpl b/tools/export/cmake/CMakeLists.txt.tmpl index a466e05bfe..5e0a6a4976 100644 --- a/tools/export/cmake/CMakeLists.txt.tmpl +++ b/tools/export/cmake/CMakeLists.txt.tmpl @@ -11,16 +11,26 @@ SET(CMAKE_CROSSCOMPILING TRUE) SET(CMAKE_C_COMPILER_WORKS TRUE) SET(CMAKE_CXX_COMPILER_WORKS TRUE) -SET(CMAKE_ASM_COMPILER_INIT "{{asm}}") -SET(CMAKE_C_COMPILER_INIT "{{cc}}") -SET(CMAKE_CXX_COMPILER_INIT "{{cxx}}") -SET(ELF2BIN "{{elf2bin}}") +# force cmake compilers +SET(CMAKE_ASM_COMPILER "{{asm}}") +SET(CMAKE_C_COMPILER "{{cc}}") +SET(CMAKE_CXX_COMPILER "{{cxx}}") +SET(ELF2BIN "{{elf2bin}}") {% if hex_files %} SET(SREC_CAT "srec_cat") {%- endif %} +# if the environment does not specify build type, set to Debug +IF(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" + CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." + FORCE) +ENDIF() + # here starts the project PROJECT(cmake-{{name}} C CXX ASM) + +# uncomment below to have a verbose build process #SET(CMAKE_VERBOSE_MAKEFILE ON) SET(LD_SYS_LIBS "{%- block sys_libs -%} -Wl,--start-group {{ld_sys_libs|join(" ")}} {{libraries|join(" ")}} -Wl,--end-group {%- endblock -%}") diff --git a/tools/export/cmake/__init__.py b/tools/export/cmake/__init__.py index 79e815d29d..5d1387f04a 100644 --- a/tools/export/cmake/__init__.py +++ b/tools/export/cmake/__init__.py @@ -16,15 +16,14 @@ limitations under the License. """ import re import shutil -from os import remove -from os.path import splitext, basename, exists +from os import remove, getcwd, chdir, mkdir +from os.path import basename, exists from subprocess import Popen, PIPE from jinja2.exceptions import TemplateNotFound from tools.export.exporters import Exporter, apply_supported_whitelist from tools.targets import TARGET_MAP -from tools.utils import NotSupportedException class CMake(Exporter): @@ -126,14 +125,34 @@ class CMake(Exporter): @staticmethod def build(project_name, log_name="build_log.txt", cleanup=True): """ Build Make project """ - # > Make -j - cmd = ["make", "-j"] + + # change into our build directory + current_dir = getcwd() + if not exists("BUILD"): + mkdir("BUILD") + chdir("BUILD") + + # > run cmake initial command + cmd = ["cmake", ".."] # Build the project p = Popen(cmd, stdout=PIPE, stderr=PIPE) out, err = p.communicate() ret_code = p.returncode + if ret_code == 0: + # we create the cmake files inside BUILD, change into and run cmake + + # > run make -j + cmd = ["make", "-j"] + + p = Popen(cmd, stdout=PIPE, stderr=PIPE) + out, err = p.communicate() + ret_code = p.returncode + + # go back to the original directory + chdir(current_dir) + out_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n" out_string += out out_string += "=" * 10 + "STDERR" + "=" * 10 + "\n" @@ -161,6 +180,7 @@ class CMake(Exporter): if exists('BUILD'): shutil.rmtree('BUILD') + if ret_code != 0: # Seems like something went wrong. return -1