How to pass various filecollections to a task?

not-a-bug

(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(
                'dir1/A',
                'dir1/B',
                'dir2/C')

FileCollection listB = files(
                'dir1/M',
                'dir2/N',
                'dir4/Q')

FileCollection listC = files(
                'dir1/X',
                'dir2/Y',
                'dir4/Z')

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 -> " + file.name
        from "${projectDir}/file.name"
        into "${buildDir}/file.name"
    }
}

model {
[...]
}

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

 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/prod1.so /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.”