Does anyone knows how the includes of srcDir works in gradle experimental files (cpp AND h)? This is kind of a "3-fold" question:
1°) how do the srcDir work?
1.a°) Does it include recursively all subdirs? Does it only include files at their deep level? Does it they include all cpp/c/cc/cxx files?
for example this command:
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
}
}
}
}
Does it include all cpp files under src? all files under src? all cpp files recursively into subdirs? all files recursively into subdirs?
The google documentation is very vague:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental
and the gradle one is not clear either:
https://docs.gradle.org/current/userguide/nativeBinaries.html
It says it only includes src/${name}/cpp ? what does it mean? Do I have to create a
../../../../some/path/src/cpp
folder?
1.b°) What about the headers:
android.sources {
main {
jni {
exportedHeaders {
srcDir "../../../../some/path/src"
}
}
}
}
I have the feeling that the srcDir directive applied on headers works differently than the srcDir for source (it includes only the headers of its current depth)
2°) What if I want a mix between file and dir?
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
srcFile "../../../../some/path/src/myFile.cpp"
}
}
}
}
doesn't seem to work
3°) how does the include/ exclude directive works?
What about the include/exclude directive, does they apply only on the previous srcDir statement? Or do they apply on all the statement of the "source" block?
doing:
android.sources {
main {
jni {
source {
srcDir "../../../../some/path/src"
include "*.cpp"
}
}
}
}
doesn't seem to include any cpp file. I thought it would include all cpp files of this folder hierarchy, or even all cpp files under src, but it looks like it doesn't.
I want to point that I am using gradle 2.9, which is required by the latest gradle-experimental-0.6.0-alpha3 plugin.
I can at least answer my first point. After digging through the sources (at some point it becomes the best documentation), I found the implementation of the methods that retrieves sources:
public Set<File> getSrcDirs() {
Set<File> dirs = new LinkedHashSet<File>();
for (DirectoryTree tree : getSrcDirTrees()) {
dirs.add(tree.getDir());
}
return dirs;
}
in DefaultSourceDirectorySet.java.
this method is used in the gradle-eperimental plugin to retrieve cpp AND c sources:
languageSourceSets.create(
sourceSetName + "Cpp",
CppSourceSet.class,
new Action<CppSourceSet>() {
@Override
public void execute(CppSourceSet source) {
source.getSource().setSrcDirs(jni.getSource().getSrcDirs());
source.getSource().include("**/*.C");
source.getSource().include("**/*.CPP");
source.getSource().include("**/*.c++");
source.getSource().include("**/*.cc");
source.getSource().include("**/*.cp");
source.getSource().include("**/*.cpp");
source.getSource().include("**/*.cxx");
source.getSource().exclude(jni.getSource().getExcludes());
source.exportedHeaders(new Action<SourceDirectorySet>() {
@Override
public void execute(SourceDirectorySet files) {
files.source(jni.getExportedHeaders());
}
});
configurePrebuiltDependency(source, jni);
}
});
in execute method from the NdkConfiguration.java file.
For the header, it's different, there is no such things as source.getSource().include("**/*.H");
, instead we have:
for (LanguageSourceSet sourceSet : nativeBinary.getSources()) {
if (sourceSet instanceof HeaderExportingSourceSet) {
HeaderExportingSourceSet source = (HeaderExportingSourceSet) sourceSet;
artifact.getExportedHeaderDirectories().addAll(
source.getExportedHeaders().getSrcDirs());
}
}
In the execute method of the NdkComponentModelPlugin.java. It uses directly the getSrcDirs method of the default gradle implementation, which include recursively all dir under the given one
I will keep on investigating the other points
EDIT: In summary:
1°) a°) srcDir includes all file matching the pattern: *.C, *.CPP, *.c++, *.cc, *.cp, *.cpp, *.cxx
b°) includeHeaders works, and only include the header at the given folder depth (so you have to give all the subpath to the header if you are including them like this: #include "test.h", instead of #include "dir1/dir2/dir3/test.h"
2°) it looks I was doing some things wrong in my includes, as they now do seem to work. However, you can't just include files. It is thus better to include top dir of source file, and then exclude every file that doesn't match a given pattern (as described in Alex Cohn answer)
3°) The include directive doesn't work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With