/** Execute the actual compilation for each of the given files. */ private void compile() { // let everyone know what we're doing task.log("Starting Compile "); // generate the command line Commandline command = generateCompileCommand(); // get all the files that we should compile // this will run checks for things like incremental compiling File objectDirectory = configuration.getObjectDirectory(); File[] filesToCompile = helper.getFilesThatNeedCompiling(objectDirectory); task.log("" + filesToCompile.length + " files to be compiled."); // Do the compile // We have to support parallel builds by ourselves, so we throw a bunch of compile tasks // into a queue and process with an executor and then wait for them all to finish ExecutorService executor = Executors.newFixedThreadPool(configuration.getThreadCount()); // create a runnable task for the compilation of each file and submit it for (File sourceFile : filesToCompile) executor.submit(new CompileTask(sourceFile, objectDirectory, command)); // run the executor over the queue executor.shutdown(); while (executor.isTerminated() == false) { try { executor.awaitTermination(500, TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { /* just carry on */ } } task.log("Compile complete"); }
/** * This method is the main manager of the linking process. It should only be run if an "outfile" * has been provided in the configuration. It will attempt to link all the files in the objdir * into a simple executable/library. */ private void link() { // generate the command line Commandline commandline = generateLinkCommand(); // create the execution object Execute runner = new Execute( new LogStreamHandler(configuration.getTask(), Project.MSG_INFO, Project.MSG_WARN)); runner.setCommandline(commandline.getCommandline()); // run the command try { task.log("Starting Link "); task.log(commandline.toString(), Project.MSG_DEBUG); int exitValue = runner.execute(); if (exitValue != 0) throw new BuildException("Link Failed, (exit value: " + exitValue + ")"); } catch (IOException e) { String msg = "There was a problem running the linker, this usually occurs when the " + "linker can't be found, make sure it is on your path. full error: " + e.getMessage(); throw new BuildException(msg, e); } task.log("Link complete. Library in directory: " + configuration.getOutputDirectory()); task.log(""); // a little bit of space }
////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////// Private Helper Methods ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// private void debug(String message) { task.log(message, Project.MSG_DEBUG); }