gradle experimental通过srcDir srcFile指令包含文件目录 [英] gradle experimental include file directories via srcDir srcFile directive

查看:436
本文介绍了gradle experimental通过srcDir srcFile指令包含文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道srcDir的包含如何在gradle实验文件(cpp和h)中工作?这是一个3倍的问题:

<1>)srcDir是如何工作的?



1.a°)它是否递归地包含所有子类?它只包含深层次的文件吗?它是否包含所有cpp / c / cc / cxx文件?



例如这个命令:

  android.sources {
main {
jni {
source {
srcDir../../../../some/ / b





$ b $

它是否包含src下的所有cpp文件? src下的所有文件?所有cpp文件递归地转化为子目录?所有的文件递归到子目录?



谷歌文档非常模糊:



http://tools.android.com/tech-docs/new-build-system/gradle-实验



以及gradle one也不清楚:

https://docs.gradle.org/current/userguide/nativeBinaries.html



它说它只包含src / $ {name} / cpp?这是什么意思?我必须创建一个

  ../../../../some/path/src/cpp 

文件夹?

1.b°)头文件怎么样:

  android.sources {
main {
jni {
exportedHeaders {
srcDir../../../../some/path/src
}
}
}
}

我感觉应用于标头的srcDir指令的工作方式与srcDir for source不同(它只包含其标头当前深度)

2°)如果我想在文件和目录之间进行混合,该怎么办?

  android.sources {
main {
jni {
source {
srcDir../../../../some/path/ src
srcFile../../../../some/path/src/myFile.cpp
}
}
}
}

似乎不起作用



3°)包含/排除指令是如何工作的?



include / exclude指令是如何使用的在以前的srcDir语句中?或者他们是否适用于所有源块的声明?



做:

  android.sources {
main {
jni {
source {
srcDir../../../../some/path/ src
include* .cpp
}
}
}
}

似乎没有包含任何cpp文件。我以为它会包含这个文件夹层次结构中的所有cpp文件,甚至包括src下的所有cpp文件,但它看起来好像没有。



我想指出我使用的是gradle 2.9,这是最新的gradle-experimental-0.6.0-alpha3插件所要求的。

解决方案

至少回答我的第一点。在挖掘源代码之后(在某些时候它成为最好的文档),我找到了检索源的方法的实现:

  public Set< File> getSrcDirs(){
Set< File> dirs = new LinkedHashSet< File>(); (DirectoryTree tree:getSrcDirTrees()){
dirs.add(tree.getDir());

}
return dirs;
}

在DefaultSourceDirectorySet.java中。



这个方法用于gradle-eperimental插件来检索cpp和c源文件:

  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);
sour ce.getSource()包括( ** / * 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);
}
});

来自NdkConfiguration.java文件的执行方法。



对于标题,不同的是,不存在
source.getSource()。include(** / *。H);

,取而代之的是:
$ b

  for(LanguageSourceSet sourceSet:nativeBinary.getSources()){
if (sourceSet instanceof HeaderExportingSourceSet){
HeaderExportingSourceSet source =(HeaderExportingSourceSet)sourceSet;
artifact.getExportedHeaderDirectories()。addAll(
source.getExportedHeaders()。getSrcDirs());
}
}

在NdkComponentModelPlugin.java的执行方法中。它直接使用默认Gradle实现的getSrcDirs方法,其中包括递归地在给定的一个下的所有目录



我将继续研究其他要点

编辑:总结:
$ b $ 1°)
a°)srcDir包含所有匹配模式的文件:
* .C,* .CPP,* .c ++,* .cc,* .cp,* .cpp,* .cxx


b°)includeHeaders有效,在给定的文件夹深度处包含头文件(因此,如果您将它们包括为如下所示的内容,则必须将所有子路径提供给头文件:#includetest.h,而不是#includedir1 / dir2 / dir3 / test.h

<2> 2)看起来我在包装中做了一些错误的事情,因为他们现在看起来似乎有效。但是,您不能只包含文件。因此,最好包含源文件的顶部目录,然后排除每个与给定模式不匹配的文件(如Alex Cohn的答案所述)

<3> )include指令不起作用


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

这篇关于gradle experimental通过srcDir srcFile指令包含文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆