Created
November 7, 2012 14:59
-
-
Save PavelGavlik/4032087 to your computer and use it in GitHub Desktop.
Compile and run program after code change
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
module.exports = function( grunt ) { | |
'use strict'; | |
// Compile and run program after code change | |
// | |
// Assumptions: | |
// 1) One cpp file named 1.cpp | |
// 2) One resulting binary a.out compiled with g++ | |
grunt.initConfig({ | |
// Project configuration | |
// --------------------- | |
// watch configuration | |
watch: { | |
recompile: { | |
files: [ | |
'1.cpp' | |
], | |
tasks: 'compile run' | |
} | |
} | |
}); | |
grunt.registerTask('compile', 'run compiler', function () { | |
var done = this.async(); | |
require('child_process').exec('g++ 1.cpp', function (err, stdout, stderr) { | |
grunt.log.write(stdout + stderr); | |
done(err); | |
}); | |
}); | |
grunt.registerTask('run', 'run binary', function () { | |
var done = this.async(); | |
require('child_process').exec('./a.out', function (err, stdout, stderr) { | |
grunt.log.write(stdout + stderr); | |
done(err); | |
}); | |
}); | |
grunt.registerTask('default', 'watch'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment