【发布时间】:2019-04-17 17:11:16
【问题描述】:
我有一个使用 C 插件生成本机可执行文件的构建脚本。当我尝试添加依赖任务(从 flex 输入文件生成 flex 输出文件的任务)时,我要么收到错误,要么我的依赖任务未执行。我认为正在发生的事情是在模型创建其任务之前正在评估添加依赖任务的声明。如果是这种情况,那么我需要知道如何使依赖任务声明更加懒惰(或者可能在模型中添加一些我还不理解的东西)。我应该用一个单独的项目来做这个吗?
这是我认为构建脚本的重要部分。我已经注释掉了我声明依赖项的尝试。
$ cat build.gradle
apply plugin: 'c'
model {
components {
test(NativeExecutableSpec) {
sources {
c {
source {
srcDir "."
include "*.c"
}
}
}
}
}
}
task compileLang (type: Exec) {
inputs.file(project.file('test.l'))
outputs.file(project.file('lex.test.c'))
commandLine 'flex', '-f', '-L', '-8', '-i', '-P', 'test', 'test.l'
}
//buildDependentsTestExecutable.dependsOn compileLang
//project.task('buildDependentsTestExecutable').dependsOn compileLang
//project.tasks.getByName('buildDependentsTestExecutable').dependsOn compileLang
//tasks['buildDependentsTestExecutable'].dependsOn compileLang
我认为这些是我执行“gradle tasks”时配置的相关任务:
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
clean - Deletes the build directory.
installTestExecutable - Installs a development image of executable 'test:executable'
testExecutable - Assembles executable 'test:executable'.
Build Dependents tasks
----------------------
assembleDependentsTest - Assemble dependents of native executable 'test'.
assembleDependentsTestExecutable - Assemble dependents of executable 'test:executable'.
buildDependentsTest - Build dependents of native executable 'test'.
buildDependentsTestExecutable - Build dependents of executable 'test:executable'.
如果需要 test.c 和 test.l 以便某人更轻松地回答问题...
$ cat test.c
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
puts("hello, world");
testwrap();
}
$ cat test.l
%s OLC
%%
<INITIAL>-- {
BEGIN(OLC);
}
<OLC>\n\r? {
BEGIN(INITIAL);
}
<OLC>. {
}
%%
int yywrap () {
return 1;
}
我正在使用 gradle 5.1.1。
【问题讨论】:
标签: gradle