How to pass various filecollections to a task?


(Joseph Fota) #1

Because Gradle compiles C/C++ code based on a directory structure, like Java, I need to construct an out-of-source build directory of groups of select files to build different products. Rather than construct a copy for every product and every list, is there a way to pass a list and param to a task?

apply plugin: 'c'

buildDir = new File(rootProject.projectDir, '/build/assembly')

FileCollection listA = files(

FileCollection listB = files(

FileCollection listC = files(

task product1() {
    task prep(listA, P1)
    task prep(listB, P1)

task product2() {
    task prep(list, P2)
    task prep(list, P2)

task setup() {
    task prep(listA)
    task prep(listB)

task prep (type: Copy, List: alist) {
    alist.each { File file ->
        println "Copying into -> " +
        from "${projectDir}/"
        into "${buildDir}/"

model {

With gcc, a user would list a file to build/link and where the output should go.

 gcc -c -o /home/build/prod1/A.o /home/tree/prod/dir1/A.c
 gcc -c -o /home/build/prod1/B.o /home/tree/prod/dir1/B.c
 gcc -o /home/tree/build/prod1/ /home/build/prod1/A.o /home/build/prod1/B.o ...

With Gradle, I seem to have to create build directories for each product, copy in only the files to built, and then find-copy the *.o files to yet-another location for linking. Or am I using Gradle for native builds incorrectly? Unfortunately, with regard to C/C++, the C/C++ documentation is pretty terse, examples are few, and even a Gradle instructor will give the response, “You probably know more about than I do.”