我有一个 gradle 项目,用于 gradle(2.10 版)中的本机 c 应用程序,由多个组件组成:
components {
component_1(NativeLibrarySpec)
component_2(NativeLibrarySpec)
...
component_n(NativeLibrarySpec)
main_component(NativeExecutableSpec){
sources {
c.lib library: "component_1", linkage: "static"
c.lib library: "component_2", linkage: "static"
...
c.lib library: "component_n", linkage: "static"
}
}
}
以这种形式拥有应用程序的主要思想是更容易测试单个组件。但是,我有两个大问题:
这main_component
是一个应用程序,因此具有主要功能,这会产生此错误:multiple definition of 'main'
... gradle_cunit_main.c:(.text+0x0): first defined here
。这是可以预料的,并且在文档中有所提及,但我想知道是否有办法避免这个问题,例如,阻止主要组件包含在测试中。这与下一个问题有关
当我尝试按如下方式定义要测试的组件时,CUnit 插件(从 2.10 版开始)抱怨:
testSuites {
component_1Test(CUnitTestSuiteSpec){
testing $.components.component_1
}
}
}
毕业抱怨:
无法使用创建规则 'component_1Test(org.gradle.nativeplatform.test.cunit.CUnitTestSuiteSpec) { ... } @ build.gradle line 68, column 9' 作为规则 'CUnitPlugin.Rules#createCUnitTestSuitePerComponent > 创建 'testSuites.component_1Test' create(component_1Test)' 已注册以创建此模型元素
综上所述,我想指示 cunit 插件只测试一些组件,并防止编译主组件(带有 main 函数)进行测试。同样,请注意我使用的是 gradle 2.10 并且无法升级到更新的版本,因为这会破坏我们的 CI 工具链。
提前感谢您的评论。