Modus 2.0 tries to compile files that are excluded

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_1669321
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

Hi,

I use submodules in my project, and one of them has a folder "tests" for some unit tests. I don't want these files to be compiled, so, in Modus, I right-clicked on the "tests" folder, selected properties->C/C++ build->Exclude resource from build.

It seemed to work, as the folder and all its content became grayed out, with a slash going over the icon. Also, every file's "Exclude resource from build" option is now checked.

When I compile my project, I get errors for some of the files inside the test folder. I tried restarting Modus, but to no avail. How can I properly exclude files from a build?

Thanks,

Fred

0 Likes
1 Solution

Ok, I got it.

You need to add the variable CY_IGNORE to the Makefile. It was in the "Running ModusToolbox from the Command Line" guide. Mine looks like:

CY_IGNORE+=$(wildcard ./lib/lib1/tests/*.c)

CY_IGNORE+=$(wildcard ./lib/lib1/tests/utilities/*.c)

CY_IGNORE+=$(wildcard ./lib/lib1/tests/mock/*.c)

It would be nice if the "exclude from build" native to Eclipse worked as-is. Please take note of this suggestion, dear Modus developers.

View solution in original post

4 Replies
user_1669321
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

It seems to be the "Auto-discovery" that happens at the beginning of a build that causes the problem. It lists all source files it finds.

I added this prebuild command:

PREBUILD=$(eval __ODIR__=$(shell 'pwd')) \

cd ./lib/lib1 &&\

rm -rf ./tests &&\

rm -rf makefile &&\

cd $(__ODIR__)

which did work, but as the auto-discovery happens before the prebuild instruction, the first build failed, but the following passed.

This is obviously unacceptable, but I'll keep investigating the auto-discovery. It seems to completely ignore the Eclipse excluded files.

0 Likes

Ok, I got it.

You need to add the variable CY_IGNORE to the Makefile. It was in the "Running ModusToolbox from the Command Line" guide. Mine looks like:

CY_IGNORE+=$(wildcard ./lib/lib1/tests/*.c)

CY_IGNORE+=$(wildcard ./lib/lib1/tests/utilities/*.c)

CY_IGNORE+=$(wildcard ./lib/lib1/tests/mock/*.c)

It would be nice if the "exclude from build" native to Eclipse worked as-is. Please take note of this suggestion, dear Modus developers.

Update: If it can help anybody

Having to add a line for each subfolder in my submodule and doing the same for each new submodule kind of bugged me, so my CY_IGNORE now looks like this:

__LIBS__=lib1 lib2 lib3 lib4

__rwildcard__=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call __rwildcard__,$d/,$2))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/lib,*.c))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/test,*.c))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/tests,*.c))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/lib,*.cpp))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/test,*.cpp))

CY_IGNORE+=$(foreach __LIB__, $(__LIBS__), $(call __rwildcard__,./lib/$(__LIB__)/tests,*.cpp))

Basically, it will ignore the *.c and *.cpp of the subfolders test, tests, and lib in each folder listed in the variable __LIBS__.

CY_IGNORE expands to:

./lib/lib1/lib/src1.c ./lib/lib2/tests/src2.cpp ./lib/lib3/lib/src3.c ./lib/lib3/lib/src4.c .....

Hope this helps someone!

This came up in a separate thread.

Although I kind of like the approach of using the Makefile instead of the IDE, it's clear that the IDE option doesn't work.

Indeed. The root cause of this is simple: the ModusToolbox build infrastructure replaces the build system inherent in Eclipse. So, when you try to manipulate details of the build in the IDE (like "don't compile these files") that has precisely ZERO impact on the actual build.  This is not obvious or intuitive. As you learned, you must modify the makefile, NOT the IDE, to build correctly.

To deal with this general problem, in some cases the engineers actually removed common settings panels from the IDE, so you can't use the IDE to modify compiler settings. I am going to assume it is not possible to disable this bit of functionality (mark files to NOT compile) in the IDE. Hence you went down the obvious (and wrong) path.

We need to document that. 100% agree. I may be doing that documenting. Thanks for calling my attention to this topic.

Jim