Last active
December 17, 2015 04:59
-
-
Save ysb33r/5554324 to your computer and use it in GitHub Desktop.
I am trying to wrapper a Task class in Gradle to wrap some legacy build tools i.e. GNU Make, SCons etc. This is to help migrating legacy builds to Gradle. The idea is to still call parts of the old build systems and just to collect the artifacts from them. So instead of inheriting from DefaultTask I thought it would be easier to just to extend s…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GnuMake extends DefaultTask { | |
@Input | |
@Optional | |
List<String> targets | |
@Input | |
@Optional | |
Map<String,Object> flags = [:] | |
@Input | |
@Optional | |
def switches = [] | |
@Input | |
@Optional | |
String executable | |
ExecResult execResult | |
GnuMake() { | |
// Can make this assume certain defaults based upon the OS | |
executable = executable ?: 'make' | |
} | |
@TaskAction | |
void exec() { | |
execResult = project.exec { | |
executable = this.executable | |
if(this.switches) { | |
args+= switches | |
} | |
if(this.targets) { | |
args+= targets | |
} | |
if(this.flags) { | |
args+= flags.collect { k,v -> "'$k=$v'" } | |
} | |
} | |
} | |
} | |
// This is the basic intention with an interface for calling a legacy build | |
task runMake( type : GnuMake ) { | |
targets = 'build', 'install' | |
flags = DESTDIR : '/path/to/somewhere', BUILDNUMBER : 1234 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A final solution is now on GitHub: https://github.com/ysb33r/Gradle/blob/master/src/main/groovy/org/ysb33r/gradle/gnumake/GnuMake.groovy