var _ = require("underscore"); var async = require("async"); var child_process = require("child_process"); var path = require("path"); var P4dUtils = require("./grunt/p4d_utils"); var P4API = "p4api-2013.1.685046"; module.exports = function(grunt) { var p4dUtils = new P4dUtils({ grunt: grunt }); grunt.registerTask("build-go", "Build golang", function() { var done = this.async(); var opts = { env: { "CGO_LDFLAGS": "-L/usr/local/" + P4API + "/lib " + "-framework Carbon -lclient -lsupp -lrpc -lp4sslstub -fPIC", "CGO_CPPFLAGS": "-I/usr/local/" + P4API + "/include" } }; child_process.exec("./go.sh build", opts, function(err, stdout, stderr) { if (err) { console.log(stderr + "\n" + stdout + "\n"); } done(err); }); }); grunt.registerTask("build", "Rebuild the project", [ "build-go" ]); grunt.registerTask("test", "Run tests", function() { var done = this.async(); var opts = { env: { "CGO_LDFLAGS": "-L/usr/local/" + P4API + "/lib " + "-framework Carbon -lclient -lsupp -lrpc -lp4sslstub -fPIC", "CGO_CPPFLAGS": "-I/usr/local/" + P4API + "/include" } }; child_process.exec("./go.sh test -v", opts, function(err, stdout, stderr) { console.log(stderr + "\n" + stdout + "\n"); done(err); }); }); grunt.registerTask("install", "Executes go install", function() { var done = this.async(); var opts = { env: { "CGO_LDFLAGS": "-L/usr/local/" + P4API + "/lib " + "-framework Carbon -lclient -lsupp -lrpc -lp4sslstub -fPIC", "CGO_CPPFLAGS": "-I/usr/local/" + P4API + "/include" } }; child_process.exec("./go.sh install", opts, function(err, stdout, stderr) { if (err) { console.log(stderr + "\n" + stdout + "\n"); } done(err); }); }); grunt.registerTask("p4d", "Launches p4d for testing", function() { p4dUtils.startP4d(this.async()); }); grunt.registerTask("p4d-stop", "Halts the local p4d", function() { p4dUtils.stopP4d(this.async()); }); grunt.registerTask("update", function() { p4dUtils.updateDev(this.async()); }); grunt.registerTask("clean", "Remove work directory", function() { grunt.file.delete(p4dUtils.workDir); grunt.file.delete("libp4go.a"); }); }; function compileFiles(files, callback) { var steps = _.map(files, function(file) { return function(cb) { var output = file.replace(".cpp", ".o"); var cmd = "g++ "; cmd += "-I/usr/local/" + P4API + "/include "; cmd += "-o " + output + " "; cmd += "-c " + file; child_process.exec(cmd, function(err, stdout, stderr) { if (err) { console.log(stderr + "\n" + stdout + "\n"); } cb(err, output); }); } }); async.series(steps, callback); } function createArchive(outputs, callback){ var cmd = "ar rvs libp4go.a " + outputs.join(" "); child_process.exec(cmd, function(err, stdout, stderr) { if (err) { console.log(stderr + "\n" + stdout + "\n"); } callback(err); }); } function isLinux() { return process.platform === "linux"; } function isDarwin() { return process.platform === "darwin"; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 10513 | tjuricek |
A basic experiment with using the C++ API in Go May not work completely. I haven't messed with this in over a year. The Go tools may have come a long ways as well, and we may be able to automate things more directly in the typical toolkit then having to use node. |