Difficulty creating model with dynamic NativeExecutableSpecs


(Mike "Traff" Traffanstead) #1

We have a legacy project I’m porting over to Gradle that multiple directories with dozens of executables created from each directory. My hope was to create the NativeExecutableSpec’s dynamically so we avoid past issues with the build file getting out of sync with the source. The problem I’m running into is Gradle 4.9 is balking on the source set.

Map<GString,GString> dayNativeExecutables = [
    'day2000' : 'day2000.c'
]

model {
    components {
        day(NativeLibrarySpec) {
            sources {
                c {
                    source {
                        srcDirs "../day/src"
                        include "**/*.c"
                    }

                    exportedHeaders {
                        srcDirs "../day/src"
                        include "**/*.h"
                    }
                }
            }
        }

        dayNativeExecutables.each { target, source ->
            "$target"(NativeExecutableSpec) {
                sources {
                    c {
                        // build fails on this source block
                        source {
                            srcDirs "../day/src"
                            include "$source"
                        }
                    }
                }
            }
        }
    }
}

If the “$target”(NativeExecutableSpec).sources.c block is empty, the project will build but when I add the source specification commented above, the build fails with:

Exception thrown while executing model rule: components { ... } @ build.gradle line 43, column 5 > create(day2000) > named(c)
   > No signature of method: java.lang.String.call() is applicable for argument types: (build_1e6akgp1nquramrlfq5sjrhq8$_run_closure1$_closure4$_closure6$_closure11$_closure12$_closure13$_closure14) values: [build_1e6akgp1nquramrlfq5sjrhq8$_run_closure1$_closure4$_closure6$_closure11$_closure12$_closure13$_closure14@3b21bea4]
     Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), take(int), any(groovy.lang.Closure)

Any suggestions on what I might be doing wrong?

RHEL 6.5 - Gradle 4.9 - Java 1.8.0_121-b13 - GCC 7.2.1