From 44974ac106705a00ae1ea13b02a56dd9f0748ba5 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 29 Nov 2019 14:02:00 +0100 Subject: [PATCH 1/4] Makefile.base: make cpp file extension configurable --- Makefile.base | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile.base b/Makefile.base index d9dfbc00b0..a533316d3d 100644 --- a/Makefile.base +++ b/Makefile.base @@ -48,11 +48,14 @@ ifeq (1, $(SUBMODULES)) endif endif +# By default consider C++ files has a .cpp extension +SRCXXEXT ?= cpp + ifeq ($(strip $(SRC))$(NO_AUTO_SRC),) SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c)) endif ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),) - SRCXX := $(wildcard *.cpp) + SRCXX := $(wildcard *.$(SRCXXEXT)) endif ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),) ASMSRC := $(wildcard *.s) @@ -68,7 +71,7 @@ GENOBJC := $(GENSRC:%.c=%.o) OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o) OBJC_NOLTO := $(SRC_NOLTO:%.c=$(BINDIR)/$(MODULE)/%.o) OBJC := $(OBJC_NOLTO) $(OBJC_LTO) -OBJCXX := $(SRCXX:%.cpp=$(BINDIR)/$(MODULE)/%.o) +OBJCXX := $(SRCXX:%.$(SRCXXEXT)=$(BINDIR)/$(MODULE)/%.o) ASMOBJ := $(ASMSRC:%.s=$(BINDIR)/$(MODULE)/%.o) ASSMOBJ := $(ASSMSRC:%.S=$(BINDIR)/$(MODULE)/%.o) @@ -108,7 +111,7 @@ $(GENOBJC): %.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_H -DRIOT_FILE_NOPATH=\"$(notdir $<)\" \ $(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $< -$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) +$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.$(SRCXXEXT) $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) $(Q)$(CCACHE) $(CXX) \ -DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \ -DRIOT_FILE_NOPATH=\"$(notdir $<)\" \ From 72bed868db9d2f7ec90176ce8f015d359e5e1942 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 29 Nov 2019 14:03:02 +0100 Subject: [PATCH 2/4] Makefile.base: add variable to exclude cpp files from build --- Makefile.base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.base b/Makefile.base index a533316d3d..6b31f36e4b 100644 --- a/Makefile.base +++ b/Makefile.base @@ -55,7 +55,7 @@ ifeq ($(strip $(SRC))$(NO_AUTO_SRC),) SRC := $(filter-out $(SRC_NOLTO), $(wildcard *.c)) endif ifeq ($(strip $(SRCXX))$(NO_AUTO_SRC),) - SRCXX := $(wildcard *.$(SRCXXEXT)) + SRCXX := $(filter-out $(SRCXXEXCLUDE),$(wildcard *.$(SRCXXEXT))) endif ifeq ($(strip $(ASMSRC))$(NO_AUTO_SRC),) ASMSRC := $(wildcard *.s) From 37f2d329149fbbf7a328728f1eebbb7f163cbf3f Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 29 Nov 2019 14:04:16 +0100 Subject: [PATCH 3/4] tests: add test for cpp files exclude --- tests/cpp_exclude/Makefile | 8 ++++ tests/cpp_exclude/Makefile.ci | 6 +++ tests/cpp_exclude/main.cpp | 31 +++++++++++++ tests/cpp_exclude/module_exclude/Makefile | 5 ++ tests/cpp_exclude/module_exclude/Makefile.dep | 1 + .../module_exclude/Makefile.include | 3 ++ tests/cpp_exclude/module_exclude/module.cpp | 32 +++++++++++++ tests/cpp_exclude/module_exclude/module.hpp | 46 +++++++++++++++++++ .../module_exclude/module_excluded.cpp | 34 ++++++++++++++ tests/cpp_exclude/tests/01-run.py | 19 ++++++++ 10 files changed, 185 insertions(+) create mode 100644 tests/cpp_exclude/Makefile create mode 100644 tests/cpp_exclude/Makefile.ci create mode 100644 tests/cpp_exclude/main.cpp create mode 100644 tests/cpp_exclude/module_exclude/Makefile create mode 100644 tests/cpp_exclude/module_exclude/Makefile.dep create mode 100644 tests/cpp_exclude/module_exclude/Makefile.include create mode 100644 tests/cpp_exclude/module_exclude/module.cpp create mode 100644 tests/cpp_exclude/module_exclude/module.hpp create mode 100644 tests/cpp_exclude/module_exclude/module_excluded.cpp create mode 100755 tests/cpp_exclude/tests/01-run.py diff --git a/tests/cpp_exclude/Makefile b/tests/cpp_exclude/Makefile new file mode 100644 index 0000000000..93b4765299 --- /dev/null +++ b/tests/cpp_exclude/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +FEATURES_REQUIRED += cpp + +USEMODULE += module_exclude +EXTERNAL_MODULE_DIRS += $(CURDIR)/module_exclude + +include $(RIOTBASE)/Makefile.include diff --git a/tests/cpp_exclude/Makefile.ci b/tests/cpp_exclude/Makefile.ci new file mode 100644 index 0000000000..d5062a26cb --- /dev/null +++ b/tests/cpp_exclude/Makefile.ci @@ -0,0 +1,6 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-f031k6 \ + nucleo-f042k6 \ + stm32f030f4-demo \ + stm32f0discovery \ + # diff --git a/tests/cpp_exclude/main.cpp b/tests/cpp_exclude/main.cpp new file mode 100644 index 0000000000..c5eade9af1 --- /dev/null +++ b/tests/cpp_exclude/main.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample C++ application + * + * @author Alexandre Abadie + * + * @} + */ + +#include +#include "module.hpp" + +int main() { + puts("Hello from C++"); + + module_class obj; + obj.print_hello(); + + return 0; +} diff --git a/tests/cpp_exclude/module_exclude/Makefile b/tests/cpp_exclude/module_exclude/Makefile new file mode 100644 index 0000000000..84b23c9c04 --- /dev/null +++ b/tests/cpp_exclude/module_exclude/Makefile @@ -0,0 +1,5 @@ +MODULE = module_exclude + +SRCXXEXCLUDE := module_excluded.cpp + +include $(RIOTBASE)/Makefile.base diff --git a/tests/cpp_exclude/module_exclude/Makefile.dep b/tests/cpp_exclude/module_exclude/Makefile.dep new file mode 100644 index 0000000000..e355de5d71 --- /dev/null +++ b/tests/cpp_exclude/module_exclude/Makefile.dep @@ -0,0 +1 @@ +FEATURES_REQUIRED += cpp diff --git a/tests/cpp_exclude/module_exclude/Makefile.include b/tests/cpp_exclude/module_exclude/Makefile.include new file mode 100644 index 0000000000..1a6f083cb8 --- /dev/null +++ b/tests/cpp_exclude/module_exclude/Makefile.include @@ -0,0 +1,3 @@ +# Use an immediate variable to evaluate `MAKEFILE_LIST` now +USEMODULE_INCLUDES_module_exclude := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_module_exclude) diff --git a/tests/cpp_exclude/module_exclude/module.cpp b/tests/cpp_exclude/module_exclude/module.cpp new file mode 100644 index 0000000000..029943789b --- /dev/null +++ b/tests/cpp_exclude/module_exclude/module.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "module.hpp" + +module_class::module_class() {} + +module_class::~module_class() {} + +void module_class::print_hello(void) +{ + puts("Hello from C++ module"); +} diff --git a/tests/cpp_exclude/module_exclude/module.hpp b/tests/cpp_exclude/module_exclude/module.hpp new file mode 100644 index 0000000000..c75f18132d --- /dev/null +++ b/tests/cpp_exclude/module_exclude/module.hpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#ifndef MODULE_H +#define MODULE_H + +#include + +class module_class +{ +public: + /** + * @brief constructor + */ + module_class(); + + /** + * @brief destructor + */ + ~module_class(); + + /** + * @brief public function + */ + void print_hello(void); +}; + +/** @} */ +#endif /* MODULE_H */ diff --git a/tests/cpp_exclude/module_exclude/module_excluded.cpp b/tests/cpp_exclude/module_exclude/module_excluded.cpp new file mode 100644 index 0000000000..c05bf233b8 --- /dev/null +++ b/tests/cpp_exclude/module_exclude/module_excluded.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "module.hpp" + +#error "This should not be built" + +module_class::module_class() {} + +module_class::~module_class() {} + +void module_class::print(void) +{ + puts("Hello from C++ module"); +} diff --git a/tests/cpp_exclude/tests/01-run.py b/tests/cpp_exclude/tests/01-run.py new file mode 100755 index 0000000000..b0e3f260a8 --- /dev/null +++ b/tests/cpp_exclude/tests/01-run.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Inria +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect_exact('Hello from C++') + child.expect_exact('Hello from C++ module') + + +if __name__ == "__main__": + sys.exit(run(testfunc)) From 5fab9ea623387fcc358f8f9ec268d51f8b2c1bc8 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 29 Nov 2019 14:04:53 +0100 Subject: [PATCH 4/4] tests: add test for custom cpp file extensions --- tests/cpp_ext/Makefile | 8 +++++ tests/cpp_ext/Makefile.ci | 6 ++++ tests/cpp_ext/main.cpp | 32 +++++++++++++++++++ tests/cpp_ext/module/Makefile | 5 +++ tests/cpp_ext/module/Makefile.dep | 1 + tests/cpp_ext/module/Makefile.include | 3 ++ tests/cpp_ext/module/module.cc | 32 +++++++++++++++++++ tests/cpp_ext/module/module.cpp | 34 +++++++++++++++++++++ tests/cpp_ext/module/module.hh | 44 +++++++++++++++++++++++++++ tests/cpp_ext/tests/01-run.py | 19 ++++++++++++ 10 files changed, 184 insertions(+) create mode 100644 tests/cpp_ext/Makefile create mode 100644 tests/cpp_ext/Makefile.ci create mode 100644 tests/cpp_ext/main.cpp create mode 100644 tests/cpp_ext/module/Makefile create mode 100644 tests/cpp_ext/module/Makefile.dep create mode 100644 tests/cpp_ext/module/Makefile.include create mode 100644 tests/cpp_ext/module/module.cc create mode 100644 tests/cpp_ext/module/module.cpp create mode 100644 tests/cpp_ext/module/module.hh create mode 100755 tests/cpp_ext/tests/01-run.py diff --git a/tests/cpp_ext/Makefile b/tests/cpp_ext/Makefile new file mode 100644 index 0000000000..e4206736bd --- /dev/null +++ b/tests/cpp_ext/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +FEATURES_REQUIRED += cpp + +USEMODULE += module +EXTERNAL_MODULE_DIRS += $(CURDIR)/module + +include $(RIOTBASE)/Makefile.include diff --git a/tests/cpp_ext/Makefile.ci b/tests/cpp_ext/Makefile.ci new file mode 100644 index 0000000000..d5062a26cb --- /dev/null +++ b/tests/cpp_ext/Makefile.ci @@ -0,0 +1,6 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-f031k6 \ + nucleo-f042k6 \ + stm32f030f4-demo \ + stm32f0discovery \ + # diff --git a/tests/cpp_ext/main.cpp b/tests/cpp_ext/main.cpp new file mode 100644 index 0000000000..9976c43b3f --- /dev/null +++ b/tests/cpp_ext/main.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample C++ application + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "module.hh" + +int main() { + puts("Hello from C++"); + + module_class obj; + obj.print_hello(); + + return 0; +} diff --git a/tests/cpp_ext/module/Makefile b/tests/cpp_ext/module/Makefile new file mode 100644 index 0000000000..c030b1a759 --- /dev/null +++ b/tests/cpp_ext/module/Makefile @@ -0,0 +1,5 @@ +MODULE = module + +SRCXXEXT = cc + +include $(RIOTBASE)/Makefile.base diff --git a/tests/cpp_ext/module/Makefile.dep b/tests/cpp_ext/module/Makefile.dep new file mode 100644 index 0000000000..e355de5d71 --- /dev/null +++ b/tests/cpp_ext/module/Makefile.dep @@ -0,0 +1 @@ +FEATURES_REQUIRED += cpp diff --git a/tests/cpp_ext/module/Makefile.include b/tests/cpp_ext/module/Makefile.include new file mode 100644 index 0000000000..f8c48846e3 --- /dev/null +++ b/tests/cpp_ext/module/Makefile.include @@ -0,0 +1,3 @@ +# Use an immediate variable to evaluate `MAKEFILE_LIST` now +USEMODULE_INCLUDES_module := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_module) diff --git a/tests/cpp_ext/module/module.cc b/tests/cpp_ext/module/module.cc new file mode 100644 index 0000000000..330e2119ac --- /dev/null +++ b/tests/cpp_ext/module/module.cc @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "module.hh" + +module_class::module_class() {} + +module_class::~module_class() {} + +void module_class::print_hello(void) +{ + puts("Hello from C++ module"); +} diff --git a/tests/cpp_ext/module/module.cpp b/tests/cpp_ext/module/module.cpp new file mode 100644 index 0000000000..4a1504523a --- /dev/null +++ b/tests/cpp_ext/module/module.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#include + +#include "module.hh" + +#error "This should not be built" + +module_class::module_class() {} + +module_class::~module_class() {} + +void module_class::print(void) +{ + puts("Hello from C++ module"); +} diff --git a/tests/cpp_ext/module/module.hh b/tests/cpp_ext/module/module.hh new file mode 100644 index 0000000000..650eb8bf9f --- /dev/null +++ b/tests/cpp_ext/module/module.hh @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Sample module C++ class + * + * @author Alexandre Abadie + * + * @} + */ + +#ifndef MODULE_H +#define MODULE_H + +class module_class +{ +public: + /** + * @brief constructor + */ + module_class(); + + /** + * @brief destructor + */ + ~module_class(); + + /** + * @brief public function + */ + void print_hello(void); +}; + +/** @} */ +#endif /* MODULE_H */ diff --git a/tests/cpp_ext/tests/01-run.py b/tests/cpp_ext/tests/01-run.py new file mode 100755 index 0000000000..b0e3f260a8 --- /dev/null +++ b/tests/cpp_ext/tests/01-run.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Inria +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +from testrunner import run + + +def testfunc(child): + child.expect_exact('Hello from C++') + child.expect_exact('Hello from C++ module') + + +if __name__ == "__main__": + sys.exit(run(testfunc))