Changeset 419:1325c26adb6a in make_builder


Ignore:
Timestamp:
26.06.2012 23:27:56 (7 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added line number output in make.xml files to make_builder error messages.

Location:
src/makebuilder
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/makebuilder/BuildEntity.java

    r399 r419  
    2525import java.util.ArrayList; 
    2626import java.util.List; 
    27 import java.util.Set; 
    2827import java.util.SortedMap; 
    2928 
     
    5655    public SrcFile buildFile; 
    5756 
     57    /** Line number in build file */ 
     58    public int lineNumber; 
     59 
    5860    /** Involved source files */ 
    5961    public final List<SrcFile> sources = new ArrayList<SrcFile>(); 
     
    7274    /** are any dependencies missing? */ 
    7375    public boolean missingDep; 
    74      
     76 
    7577    /** Has missing dependency check been performed for this build entity? */ 
    7678    private boolean missingDepCheckPerformed = false; 
     
    9395    /** Error message id */ 
    9496    public int errorMessageId = -1; 
    95      
     97 
    9698    /** Stores result of cycle checks: 1 if first cycle check was successful; 2 after second test was successful */ 
    9799    private int checkedForCycles = 0; 
     
    133135    /** 
    134136     * Check dependency tree for cycles 
    135      *  
     137     * 
    136138     * @param cycleCheckRun Number of cycle check run 
    137139     */ 
     
    140142            return; 
    141143        } 
    142          
     144 
    143145        if (cycleCheckStack.contains(this)) { 
    144146            System.out.println("Detected cyclic dependency: "); 
     
    190192            if (be.missingDep) { 
    191193                missingDep = true; 
    192                 mfb.printCannotBuildError(this, Util.color(" due to dependency " + be.name + " (" + be.errorMessageId + ")", Util.Color.X, false) + " (" + be.buildFile.relative + ") " + Util.color("which cannot be built", Util.Color.X, false), Util.Color.X); 
     194                mfb.printCannotBuildError(this, Util.color(" due to dependency " + be.name + " (" + be.errorMessageId + ")", Util.Color.X, false) + " (" + be.buildFile.relative + (be.lineNumber != 0 ? (":" + be.lineNumber) : "") + ") " + Util.color("which cannot be built", Util.Color.X, false), Util.Color.X); 
    193195                return; 
    194196            } 
     
    237239            s = s.substring(s.lastIndexOf("/lib") + 4, s.lastIndexOf(".so")); 
    238240            opts.libs.add(s); 
    239              
     241 
    240242            ArrayList<BuildEntity> visited = new ArrayList<BuildEntity>(); 
    241243            addIndirectIncludePaths(be, visited); 
     
    252254            return; 
    253255        } 
    254          
     256 
    255257        String s = be.getTarget(); 
    256258        s = s.substring(s.lastIndexOf("/lib") + 4, s.lastIndexOf(".so")); 
     
    269271            return; 
    270272        } 
    271          
     273 
    272274        String s = be.getTarget(); 
    273275        opts.includePaths.addAll(be.opts.includePaths); 
  • src/makebuilder/MakeFileBuilder.java

    r391 r419  
    342342    public void printCannotBuildError(BuildEntity be, String string, Util.Color c) { 
    343343        be.errorMessageId = errorMessages.size() + 1; 
    344         printErrorLine(Util.color("(" + be.errorMessageId + ") ", c, false) + Util.color("Cannot build " + be.getReferenceName(), c, true) + " (" + be.buildFile + ")" + Util.color(string, c, false)); 
     344        printErrorLine(Util.color("(" + be.errorMessageId + ") ", c, false) + Util.color("Cannot build " + be.getReferenceName(), c, true) + " (" + be.buildFile + (be.lineNumber != 0 ? (":" + be.lineNumber) : "") + ")" + Util.color(string, c, false)); 
    345345    } 
    346346 
  • src/makebuilder/handler/MakeXMLLoader.java

    r385 r419  
    3232import javax.xml.parsers.DocumentBuilderFactory; 
    3333import javax.xml.parsers.ParserConfigurationException; 
     34import javax.xml.parsers.SAXParser; 
     35import javax.xml.parsers.SAXParserFactory; 
    3436 
    3537import org.w3c.dom.Document; 
     
    3739import org.w3c.dom.Node; 
    3840import org.w3c.dom.NodeList; 
     41import org.xml.sax.helpers.DefaultHandler; 
     42import org.xml.sax.Attributes; 
     43import org.xml.sax.Locator; 
    3944 
    4045import makebuilder.BuildEntity; 
     
    6267    /** Objects for parsing XML */ 
    6368    static private final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     69    static private final SAXParserFactory saxFactory = SAXParserFactory.newInstance(); 
    6470    static private DocumentBuilder dbuilder; 
    6571 
     
    9096 
    9197    @Override 
    92     public void process(SrcFile file, List<BuildEntity> result, SourceScanner scanner, MakeFileBuilder builder) throws Exception { 
     98    public void process(SrcFile file, final List<BuildEntity> result, SourceScanner scanner, MakeFileBuilder builder) throws Exception { 
    9399        if (!isMakeXMLFile(file)) { 
    94100            return; 
    95101        } 
     102        final int originalElementCount = result.size(); 
    96103 
    97104        // parse XML 
     
    170177            } 
    171178        } 
     179 
     180        saxFactory.setValidating(false); 
     181        saxFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 
     182        SAXParser saxParser = saxFactory.newSAXParser(); 
     183        saxParser.parse(file.absolute, new DefaultHandler() { 
     184 
     185            Locator l; 
     186 
     187            @Override 
     188            public void setDocumentLocator(Locator locator) { 
     189                super.setDocumentLocator(locator); 
     190                l = locator; 
     191            } 
     192 
     193            @Override 
     194            public void startElement(String uri, String localName, String qName, Attributes attributes) { 
     195                for (int i = originalElementCount; i < result.size(); i++) { 
     196                    if (qName.equals(result.get(i).getClass().getSimpleName().toLowerCase()) && (result.get(i).name.equals(attributes.getValue("name")))) { 
     197                        result.get(i).lineNumber = l.getLineNumber(); 
     198                    } 
     199                } 
     200            } 
     201        }); 
    172202    } 
    173203 
Note: See TracChangeset for help on using the changeset viewer.