Gradle FileTree directories only - file

Given a directory dir:
dir
├── sub1
│   ├── file1
│   └── file2
├── sub2
│   ├── file1
│   └── file2
└── sub3
├── file1
└── file2
fileTree('dir').each { println it } gives me this:
dir/sub1/file1
dir/sub1/file2
dir/sub2/file1
dir/sub2/file2
dir/sub3/file1
dir/sub3/file2
Instead of all the file, I just want all the directories and subdirectories:
dir/
dir/sub1/
dir/sub2/
dir/sub3/
How do I do that? I've looked at DirectoryTree, but it does not extend FileCollection (unlike FileTree), so it's not very useful.

What about this :
file('dir').eachFileRecurse(FileType.DIRECTORIES) { println it }
Gives :
dir/sub1/
dir/sub2/
dir/sub3/

You could also do
FileTree dirs = fileTree('dir').matching {
include { FileTreeElement el -> el.directory }
}
doStuff(dirs)
https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileTree.html#matching-groovy.lang.Closure-
https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html#include-groovy.lang.Closure-
https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileTreeElement.html#isDirectory--

Related

LVGL CMake undefined reference to

I'm learning to use LVGL and I plan to use CMake to manage the project. But when I tried to compile, I encountered "undefined reference to". Project Tree looks like this:
.
├── build
├── CMakeLists.txt // C1
└── src
├── CMakeLists.txt // C2
├── lv_conf.h
├── lv_demo_conf.h
├── lv_demos
│ ├── CMakeLists.txt // C3
│ └── src
├── lv_drivers
│ ├── CMakeLists.txt // C4
│ ├── display
│ ├── docs
│ ├── gtkdrv
│ ├── indev
│ ├── library.json
│ ├── LICENSE
│ ├── lv_drivers.mk
│ ├── lv_drv_conf_template.h
│ ├── README.md
│ ├── sdl
│ ├── wayland
│ ├── win32drv
│ ├── win_drv.c
│ └── win_drv.h
├── lv_drv_conf.h
├── lvgl
│ ├── CMakeLists.txt // C5
│ └── src
├── main.c
└── mouse_cursor_icon.c
While I try to make, log is as follows, it seems like I do not add INCLUDE dir or some head file.
[ 76%] Linking C static library liblvgl_lib.a
[ 76%] Built target lvgl_lib
Scanning dependencies of target demo
[ 76%] Building C object bin/CMakeFiles/demo.dir/main.c.o
[ 77%] Linking C executable demo
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: CMakeFiles/demo.dir/main.c.o: in function `main':
/home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:18: undefined reference to `fbdev_init'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: /home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:36: undefined reference to `evdev_init'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: /home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:54: undefined reference to `lv_demo_widgets'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: /home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:58: undefined reference to `fbdev_flush'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: /home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:58: undefined reference to `evdev_read'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: /home/xjt/F1C100S_LVGL_DEMO_WITH_CMAKE/src/main.c:58: undefined reference to `mouse_cursor_icon'
/usr/local/arm/arm-linux-musleabi-cross/bin/../lib/gcc/arm-linux-musleabi/11.2.1/../../../../arm-linux-musleabi/bin/ld: lvgl/liblvgl_lib.a(lv_extra.c.o): in function `lv_extra_init':
Here is my CMakeLists.txt, C1:
PROJECT(F1C100S_DEMO_WITH_CMAKE)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
# INCLUDE_DIRECTORIES(./lib/gpiod/include)
# LINK_DIRECTORIES(./lib/gpiod/lib)
SET(CMAKE_C_COMPILER "arm-linux-musleabi-gcc")
SET(CMAKE_EXE_LINKER_FLAGS "-static")
ADD_COMPILE_OPTIONS(-g)
ADD_SUBDIRECTORY(src bin)
C2:
AUX_SOURCE_DIRECTORY(. SRC_LIST)
# SET(
# ${SRC_LIST}
# lv_drivers/indev/evdev.h
# lv_drivers/display/fbdev.h
# lvgl/demos/lv_demos.h
# )
ADD_SUBDIRECTORY(./lvgl)
ADD_SUBDIRECTORY(./lv_drivers)
ADD_SUBDIRECTORY(./lv_demos)
LINK_DIRECTORIES(./lvgl)
INCLUDE_DIRECTORIES(./lvgl)
SET(
LIB_LIST
lvgl_lib
)
SET(
${LIB_LIST}
lv_drv_lib
)
SET(
${LIB_LIST}
lv_demos_lib
)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR/bin})
ADD_EXECUTABLE(demo ${SRC_LIST})
# TARGET_LINK_LIBRARIES(demo gpiod)
TARGET_LINK_LIBRARIES(demo ${LIB_LIST})
C3:
AUX_SOURCE_DIRECTORY(./src/lv_demo_benchmark DIR_LV_DEMOS_SRC)
AUX_SOURCE_DIRECTORY(./src/lv_demo_keypad_encoder DIR_LV_DEMOS_SRC)
AUX_SOURCE_DIRECTORY(./src/lv_demo_music DIR_LV_DEMOS_SRC)
AUX_SOURCE_DIRECTORY(./src/lv_demo_stress DIR_LV_DEMOS_SRC)
AUX_SOURCE_DIRECTORY(./src/lv_demo_widgets DIR_LV_DEMOS_SRC)
ADD_LIBRARY(lv_demos_lib ${DIR_LV_DEMOS_SRC})
C3 and C4 is similar to C2, just AUX_SOURCE_DIRECTORY and ADD_LIBRARY.
Well, I have a stupid looking solution to this problem, which is to add all the .c files to the SRC_LIST:
# in C2
FILE(GLOB_RECURSE SRC_LIST ./*.c)
This seems unusual because when I build with MAKEFILE it doesn't produce so many .o files.

SDL2 > PNG IMAGE > couldn't load the image

SITUATION
I want to load and use my image (which is .png) in my app. However when I try to load the image I get the following error
Error at ./sources/texture.c:9: 'The texture is NULL'
> Couldn't open pawn.png
CODE
texture.c
texture_t*
texture_load(renderer_t *renderer, const char *path) {
texture_t *tex = IMG_LoadTexture(renderer, path);
if (tex == NULL)
error_print(AT, "The texture is NULL");
return tex;
}
game.c
game_t*
game_create() {
...
IMG_Init(IMG_INIT_PNG);
...
texture_load(renderer, "pawn.png")
...
}
FOLDER STRUCTURE
.
├── build
│   ├── app
│   └── pawn.png
├── headers
│   ...
│   ├── game.h
| ...
│   ├── texture.h
│   ...
├── resources
│   └── pawn.png
└── sources
...
├── game.c
...
├── texture.c
...
BONUS
if You want to see the whole "image" of my project then You can click here
Maybe it's a silly hypothesis, but are you sure the file is in the current application directory?
On a POSIX system you can check it with:
if (access("pawn.png", F_OK) == 0) {
printf("File exists\n");
} else {
printf("File doesn't exist\n");
}
If it prints File doesn't exist, then you need to specify a full path to the file.

Include header file of external library in another header file

Currently I have the following project structure, where the libs directory purpose is to store external C libraries that I download from github because they are not available on my OS's repos:
├── cli
│   └── cli.c
├── libs
│   ├── meson.build
│   └── pqueue
│   ├── pqueue.c
│   └── pqueue.h
├── modules
│   ├── algorithms
│   │   ├── a_star.c
│   │   └── a_star.h
│   ├── meson.build
├── meson.build
Where libs/meson.build is:
libpqueue_sources = [
'pqueue/pqueue.c',
]
pqueue_lib = shared_library('pqueue', libpqueue_sources)
pqueue_dep = declare_dependency(link_with: pqueue_lib)
modules/meson.build is:
algs_sources = [
'algorithms/a_star.c',
]
algs_lib = static_library('algorithms',
sources: algs_sources,
include_directories: libs_include_dirs,
dependencies: pqueue_dep)
and meson.build is:
project('graph-search', 'c')
graph_search_include_dirs = include_directories('modules')
libs_include_dirs = include_directories('libs')
subdir('libs')
subdir('modules')
cli_sources = [
'cli/cli.c'
]
executable('cli',
sources: cli_sources,
include_directories : graph_search_include_dirs,
link_with: [algs_lib])
My problem arises when I try to make an #include "pqueue/pqueue.h" inside a_star.h, it says /modules/algorithms/a_star.h:5:10: fatal error: pqueue/pqueue.h: No such file or directory, but when I move the include to a_star.c the error disappears. Sadly I need to include it on the header file because I need to export a struct that uses a type of pqueue.h
Is there a way to include pqueue.h inside a_star.h without using paths like ../../libs/pqueue/pqueue.h?
Because you don't specify libs_include_dirs for cli.c to build, compiler don't know how to search pqueue/pqueue.h.
Change your meson.build to include libs_include_dirs.
diff --git a/meson.build b/meson.build
index 4087a00..3347466 100644
--- a/meson.build
+++ b/meson.build
## -8,5 +8,5 ## cli_sources = [
]
executable('cli',
sources: cli_sources,
- include_directories : graph_search_include_dirs,
+ include_directories : [graph_search_include_dirs, libs_include_dirs],
link_with: [algs_lib])

Removing files from lcov tracefile using relative paths

I am attempting to remove certain directories from my lcov tracefile, but am not having any success. I am attempting to use relative paths, and I am using cygwin. My test framework is cpputest.
My directory structure looks like this
foo_library
$ tree
├── bar
│   ├── bar.c
│   ├── bar.h
│   ├── bar.o
│   └── makefile
├── makefile
├── readme.md
├── foo.c
├── foo.h
├── foo.o
├── baz
│   ├── baz.c
│   └── baz.h
└── test
  ├── AllTests.cpp
  ├── bar
  │   ├── bar.d
  │   ├── bar.gcda
  │   ├── bar.gcno
  │   └── bar.o
  ├── lcov.info
  ├── lcov-filtered.info
  ├── Makefile
  ├── foo.d
  ├── foo.gcno
  ├── foo.o
  ├── baz
  │   ├── baz.d
  │   ├── baz.gcda
  │   ├── baz.gcno
  │   └── baz.o
  ├── test_foo.cpp
  ├── test-lib
  │   └── libfoo.a
  ├── test-obj
  │   ├── AllTests.d
  │   ├── AllTests.gcda
  │   ├── AllTests.gcno
  │   ├── AllTests.o
  │   ├── test_foo.d
  │   ├── test_foo.gcda
  │   ├── test_foo.gcno
  │   ├── test_foo.o
  │   ├── wrap_foo.d
  │   ├── wrap_foo.gcda
  │   ├── wrap_foo.gcno
  │   └── wrap_foo.o
  ├── foo_tests.exe
  ├── wrap_foo.c
  └── wrap_foo.h
Here is an example
nick test
$ pwd
/cygdrive/C/Work/git/foo_library/test
nick test
$ lcov --capture --directory './' --output-file lcov.info
Capturing coverage data from ./
Found gcov version: 7.3.0
Scanning ./ for .gcda files ...
Found 5 data files in ./
Processing bar/bar.gcda
Processing baz/baz.gcda
Processing test-obj/AllTests.gcda
Processing test-obj/test_foo.gcda
geninfo: WARNING: cannot find an entry for c~#Work#cpputest#include#CppUTest#Utest.h.gcov in .gcno file, skipping file!
Processing test-obj/wrap_foo.gcda
Finished .info-file creation
nick test
$ lcov --list lcov.info
Reading tracefile lcov.info
|Lines |Functions |Branches
Filename |Rate Num|Rate Num|Rate Num
===========================================================================
[/cygdrive/C/Work/git/foo_library/]
bar/bar.c |83.3% 24|66.7% 3| - 0
foo.c |94.0% 100| 100% 4| - 0
baz/baz.c | 100% 5| 100% 1| - 0
test/AllTests.cpp | 100% 3| 100% 1| - 0
test/test_foo.cpp | 100% 131|74.6% 189| - 0
===========================================================================
Total:|96.2% 263|75.3% 198| - 0
nick test
$ lcov --remove lcov.info './bar/*' --output-file lcov-filtered.info
Reading tracefile lcov.info
Deleted 0 files
Writing data to lcov-filtered.info
Summary coverage rate:
lines......: 96.2% (253 of 263 lines)
functions..: 75.3% (149 of 198 functions)
branches...: no data found
Ultimately I just want to produce coverage data of this foo.c file, and I would like to exclude or remove everything else.
I have tried using absolute paths to these directories, like 'cygdrive/C/Work/git/foo_library/test/bar/*', I have also tried
'`pwd`/test/bar/*'
I am also not really sure which paths I should be specifying, the paths to the gcda files, or the path to the source files. I've tried both.
I've also tried using -b ., and -b ../ in my capture and remove commands.
Edit:
I have to run this from the test subdirectory for the paths to work out. The following shows the full paths
nick test
$ lcov -c -d . -b ../ -o lcov.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
Found 5 data files in .
Processing bar/bar.gcda
Processing baz/baz.gcda
Processing test-obj/AllTests.gcda
Processing test-obj/test_foo.gcda
geninfo: WARNING: cannot find an entry for c~#Work#cpputest#include#CppUTest#Utest.h.gcov in .gcno file, skipping file!
Processing test-obj/wrap_foo.gcda
Finished .info-file creation
nick test
$ lcov --list lcov.info --list-full-path
Reading tracefile lcov.info
|Lines |Functions |Branches
Filename |Rate Num|Rate Num|Rate Num
======================================================================================================================
/cygdrive/C/Work/git/foo_library/bar/bar.c |83.3% 24|66.7% 3| - 0
/cygdrive/C/Work/git/foo_library/foo.c |94.0% 100| 100% 4| - 0
/cygdrive/C/Work/git/foo_library/baz/baz.c | 100% 5| 100% 1| - 0
/cygdrive/C/Work/git/foo_library/test/AllTests.cpp | 100% 3| 100% 1| - 0
/cygdrive/C/Work/git/foo_library/test/test_foo.cpp | 100% 131|74.6% 189| - 0
======================================================================================================================
Total:|96.2% 263|75.3% 198| - 0
Edit:
If I do this: $ lcov -r lcov.info '*bar*' '*baz*' '*cpp' -o lcov-filtered.info
it does what I want. However that seems a little heavy handed.
I had the same problem as you excluding folders.
You should remove source code that you don't want to show in the result and add up to the total number of lines in the coverage ratio.
This way of relative paths works for me to exclude paths.
Set the following variable.
testBarSrcPath=pwd/test/bar/*
And then use the variable when you exclude content.
lcov -r lcov.info "$testBarSrcPath" -o lcov-filtered.info

How to configure .ycm_extra_conf.py for current project include PATH

I installed YCM and syntastic for VIM, normally they work fine, but I have problem when it detect some errors in my code, it shows that can NOT find some head files(which is my project head file).
My directory tree shows below:
TOP
├── debug
│   ├── debug.c
│   ├── debug.h
│   ├── debug.mk
│   └── instrument.c
├── driver
│   ├── driver.c
│   ├── driver_ddi.c
│   ├── driver_ddi.h
│   ├── driver.h
│   └── driver.mk
├── include
│   └── common.h
├── libs
├── Makefile
├── mw
│   ├── manager.c
│   └── mw.mk
└── root
   ├── main.c
    └── root.mk
I copied a .ycm_extra_conf.py to the TOP, meanwhile, I will generated tag and cscope file at TOP as well, therefore each time I open file on TOP, like:
howchen#host:~/Work/c/sample/src
-> gvim ./driver/driver.c
to make sure each time I can add tag and cscope file in VIM. The problem is, if I open driver.c, which contain head files: driver.h, driver_ddi.h, debug.h, common.h, code like below:
#include <stdio.h>
#include <stdlib.h>
#include "math.h"
#include "common.h"
#include "debug.h"
#include "driver_ddi.h"
#include "driver.h"
the syntastic or YCM always show it can NOT find common.h and debug.h, other head files are OK.
My YCM and syntastic config part in vimrc file:
" YCM
" let g:ycm_extra_conf_globlist = ['~/.vim/bundle/YouCompleteMe/cpp/ycm/*','!~/*']
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'
" Syntastic
let g:syntastic_c_checkers=['make']
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*gbar
My .ycm_extra_conf.py write flags variable as:
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
'-std=c99',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x', #I don't know if I need remove -x
'c',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'../driver'
'-I',
'../debug'
'-I',
'../include'
'-I',
'../include'
]
any wrong flags I set?
Moved here from the question.
I found the problem:
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
'-std=c99',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x', #I don't know if I need remove -x
'c',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I./driver',
'-I./debug',
'-I./include',
]
I missed a comma and path should be ./xxx, also neeeeed '-I/usr/include', and '-I/usr/local/include'.

Resources