Package net.sf.antcontrib.cpptasks.compiler

Examples of net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration


        //  determine the eventual linker configuration
        //      (may be null) and collect any explicit
        //          object files or libraries
        Vector objectFiles = new Vector();
        Vector sysObjectFiles = new Vector();
        LinkerConfiguration linkerConfig = collectExplicitObjectFiles(
                objectFiles, sysObjectFiles, versionInfo);
       
       
        //
        //   Assemble hashtable of all files
        //       that we know how to compile (keyed by output file name)
        //
        Hashtable targets = getTargets(linkerConfig, objectFiles, versionInfo, _outfile);
        TargetInfo linkTarget = null;
        //
        //   if output file is not specified,
        //      then skip link step
        //
        if (_outfile != null) {
            linkTarget = getLinkTarget(linkerConfig, objectFiles,
                    sysObjectFiles, targets, versionInfo);
        }
       
        if (projects.size() > 0) {
          ArrayList files = new ArrayList();
          ProjectFileCollector matcher = new ProjectFileCollector(files);
            for (int i = 0; i < _compilers.size(); i++) {
                CompilerDef currentCompilerDef = (CompilerDef) _compilers
                        .elementAt(i);
                if (currentCompilerDef.isActive()) {
                    if (currentCompilerDef.hasFileSets()) {
                        currentCompilerDef.visitFiles(matcher);
                    }
                }
            }
            compilerDef.visitFiles(matcher);
         
         
          Enumeration iter = projects.elements();
          while (iter.hasMoreElements()) {
            ProjectDef projectDef = (ProjectDef) iter.nextElement();
            if (projectDef.isActive()) {
              projectDef.execute(this, files, targets, linkTarget);
            }
          }
        }
        if (projectsOnly) return;
     
       
       
        //
        //     mark targets that don't have a history record or
        //        whose source last modification time is not
        //        the same as the history to be rebuilt
        //
        objHistory.markForRebuild(targets);
        CCTaskProgressMonitor monitor = new CCTaskProgressMonitor(objHistory, versionInfo);
        //
        //      check for changed include files
        //
        int rebuildCount = checkForChangedIncludeFiles(targets);
        if (rebuildCount > 0) {
            BuildException compileException = null;
            //
            //    compile all targets with getRebuild() == true
            //
            Hashtable targetsByConfig = getTargetsToBuildByConfiguration(targets);
            //
            //    build array containing Vectors with precompiled generation
            //       steps going first
            //
            Vector[] targetVectors = new Vector[targetsByConfig.size()];
            int index = 0;
            Enumeration targetVectorEnum = targetsByConfig.elements();
            while (targetVectorEnum.hasMoreElements()) {
                Vector targetsForConfig = (Vector) targetVectorEnum
                        .nextElement();
                //
                //    get the configuration from the first entry
                //
                CompilerConfiguration config = (CompilerConfiguration) ((TargetInfo) targetsForConfig
                        .elementAt(0)).getConfiguration();
                if (config.isPrecompileGeneration()) {
                    targetVectors[index++] = targetsForConfig;
                }
            }
            targetVectorEnum = targetsByConfig.elements();
            while (targetVectorEnum.hasMoreElements()) {
                Vector targetsForConfig = (Vector) targetVectorEnum
                        .nextElement();
                for (int i = 0; i < targetVectors.length; i++) {
                    if (targetVectors[i] == targetsForConfig) {
                        break;
                    }
                    if (targetVectors[i] == null) {
                        targetVectors[i] = targetsForConfig;
                        break;
                    }
                }
            }
            for (int i = 0; i < targetVectors.length; i++) {
                //
                //    get the targets for this configuration
                //
                Vector targetsForConfig = targetVectors[i];
                //
                //    get the configuration from the first entry
                //
                CompilerConfiguration config = (CompilerConfiguration) ((TargetInfo) targetsForConfig
                        .elementAt(0)).getConfiguration();
                //
                //    prepare the list of source files
                //
                String[] sourceFiles = new String[targetsForConfig.size()];
                Enumeration targetsEnum = targetsForConfig.elements();
                index = 0;
                while (targetsEnum.hasMoreElements()) {
                    TargetInfo targetInfo = ((TargetInfo) targetsEnum
                            .nextElement());
                    sourceFiles[index++] = targetInfo.getSources()[0]
                            .toString();
                }
                try {
                    config.compile(this, _objDir, sourceFiles, relentless,
                            monitor);
                } catch (BuildException ex) {
                    if (compileException == null) {
                        compileException = ex;
                    }
                    if (!relentless)
                        break;
                }
            }
            //
            //   save the details of the object file compilation
            //     settings to disk for dependency analysis
            //
            try {
                objHistory.commit();
            } catch (IOException ex) {
                this.log("Error writing history.xml: " + ex.toString());
            }
            //
            //  if we threw a compile exception and
            //     didn't throw it at the time because
            //     we were relentless then
            //        save the history and
            //           throw the exception
            //
            if (compileException != null) {
              if (failOnError) {
                throw compileException;
              } else {
                    log(compileException.getMessage(), Project.MSG_ERR);
                    return;
                }
            }
        }
        //
        //    if the dependency tree was not fully
        //      evaluated, then throw an exception
        //      since we really didn't do what we
        //      should have done
        //
        //
        if (dependencyDepth >= 0) {
            throw new BuildException(
                    "All files at depth "
                            + Integer.toString(dependencyDepth)
                            + " from changes successfully compiled.\n"
                            + "Remove or change dependencyDepth to -1 to perform full compilation.");
        }
        //
        //   if no link target then
        //       commit the history for the object files
        //           and leave the task
        if (linkTarget != null) {
            //
            //    get the history for the link target (may be the same
            //        as the object history)
            TargetHistoryTable linkHistory = getLinkHistory(objHistory);
            //
            //    see if it needs to be rebuilt
            //
            linkHistory.markForRebuild(linkTarget);
            //
            //    if it needs to be rebuilt, rebuild it
            //
            File output = linkTarget.getOutput();
            if (linkTarget.getRebuild()) {
                log("Starting link");
                LinkerConfiguration linkConfig = (LinkerConfiguration) linkTarget
                        .getConfiguration();
                if (failOnError) {
                  linkConfig.link(this, linkTarget);
                } else {
                  try {
                      linkConfig.link(this, linkTarget);                   
                  } catch(BuildException ex) {
                        log(ex.getMessage(), Project.MSG_ERR);
                        return;                   
                  }
                }
View Full Code Here

TOP

Related Classes of net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.