View | Details | Raw Unified | Return to bug 156008 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CCommandDSC.java (-7 / +147 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
11
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
12
12
13
import java.io.File;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collections;
14
import java.util.Iterator;
16
import java.util.Iterator;
15
import java.util.List;
17
import java.util.List;
16
18
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IWorkspaceRoot;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.Path;
17
import org.w3c.dom.Document;
25
import org.w3c.dom.Document;
18
import org.w3c.dom.Element;
26
import org.w3c.dom.Element;
19
import org.w3c.dom.NodeList;
27
import org.w3c.dom.NodeList;
Lines 38-43 Link Here
38
	private List compilerCommand;	// members are KVStringPair objects
46
	private List compilerCommand;	// members are KVStringPair objects
39
	private boolean discovered;
47
	private boolean discovered;
40
	private boolean cppFileType;	// C or C++ file type
48
	private boolean cppFileType;	// C or C++ file type
49
	private IProject project;
41
50
42
    private List symbols;
51
    private List symbols;
43
    private List includes;
52
    private List includes;
Lines 47-52 Link Here
47
	 * @param cppFileType2 
56
	 * @param cppFileType2 
48
	 */
57
	 */
49
	public CCommandDSC(boolean cppFileType) {
58
	public CCommandDSC(boolean cppFileType) {
59
		this(cppFileType, null);
60
	}
61
	
62
	public CCommandDSC(boolean cppFileType, IProject project) {
50
		compilerCommand = new ArrayList();
63
		compilerCommand = new ArrayList();
51
		discovered = false;
64
		discovered = false;
52
		this.cppFileType = cppFileType;
65
		this.cppFileType = cppFileType;
Lines 54-59 Link Here
54
        symbols = new ArrayList();
67
        symbols = new ArrayList();
55
        includes = new ArrayList();
68
        includes = new ArrayList();
56
        quoteIncludes = new ArrayList();
69
        quoteIncludes = new ArrayList();
70
        this.project = project;
57
	}
71
	}
58
72
59
    public boolean appliesToCPPFileType() {
73
    public boolean appliesToCPPFileType() {
Lines 61-66 Link Here
61
    }
75
    }
62
    
76
    
63
	public void addSCOption(KVStringPair option) {
77
	public void addSCOption(KVStringPair option) {
78
		if (project != null &&
79
			(option.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString()) ||
80
			 option.getKey().equals(SCDOptionsEnum.INCLUDE.toString()) ||
81
			 option.getKey().equals(SCDOptionsEnum.IDASH.toString()) ||
82
			 option.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())))
83
		{
84
			String value = option.getValue();
85
			value = (String)CygpathTranslator.translateIncludePaths(project, Collections.singletonList(value)).get(0);
86
			value = makeRelative(project, new Path(value)).toOSString();
87
			option = new KVStringPair(option.getKey(), value);
88
		}
64
		compilerCommand.add(option);
89
		compilerCommand.add(option);
65
	}
90
	}
66
	
91
	
Lines 87-94 Link Here
87
		String commandAsString = new String();
112
		String commandAsString = new String();
88
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
113
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
89
			KVStringPair optionPair = (KVStringPair)i.next();
114
			KVStringPair optionPair = (KVStringPair)i.next();
115
			String value = optionPair.getValue();
90
			commandAsString += optionPair.getKey() + SINGLE_SPACE + 
116
			commandAsString += optionPair.getKey() + SINGLE_SPACE + 
91
                               optionPair.getValue() + SINGLE_SPACE;
117
                               value + SINGLE_SPACE;
92
		}
118
		}
93
		return commandAsString.trim();
119
		return commandAsString.trim();
94
	}
120
	}
Lines 113-127 Link Here
113
    			if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString()) ||
139
    			if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString()) ||
114
    					optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString()))
140
    					optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString()))
115
    				continue;
141
    				continue;
142
    			String value = optionPair.getValue();
143
    			if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE.toString()) ||
144
    				optionPair.getKey().equals(SCDOptionsEnum.IDASH.toString())) {
145
    				value = makeAbsolute(project, value);
146
    			}
116
    			if (quoteIncludePaths) {
147
    			if (quoteIncludePaths) {
117
    				if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE.toString())) {
148
    				if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE.toString())) {
118
    					commandAsString += optionPair.getKey() + SINGLE_SPACE + 
149
    					commandAsString += optionPair.getKey() + SINGLE_SPACE + 
119
    							"\"" + optionPair.getValue() + "\"" + SINGLE_SPACE;  //$NON-NLS-1$//$NON-NLS-2$
150
    							"\"" + value + "\"" + SINGLE_SPACE;  //$NON-NLS-1$//$NON-NLS-2$
120
    				}
151
    				}
121
    			}
152
    			}
153
    			else if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE.toString())) {
154
	    			commandAsString += optionPair.getKey() + SINGLE_SPACE + 
155
	    					value + SINGLE_SPACE;
156
    			}
122
    			else {
157
    			else {
123
	    			commandAsString += optionPair.getKey() + SINGLE_SPACE + 
158
	    			commandAsString += optionPair.getKey() + SINGLE_SPACE + 
124
	                                   optionPair.getValue() + SINGLE_SPACE;
159
	    					value + SINGLE_SPACE;
125
    			}
160
    			}
126
            }
161
            }
127
		}
162
		}
Lines 129-134 Link Here
129
	}
164
	}
130
	
165
	
131
	/**
166
	/**
167
	 * Returns the compiler command
168
	 * @return
169
	 */
170
	public String getCompilerName() {
171
		String compiler = new String();
172
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
173
			KVStringPair optionPair = (KVStringPair)i.next();
174
            if (optionPair.getKey().equals(SCDOptionsEnum.COMMAND.toString())) {
175
            	compiler = optionPair.getValue();
176
            	break;
177
            }
178
		}
179
		return compiler.trim();
180
	}
181
	
182
	/**
132
	 * @return list of strings
183
	 * @return list of strings
133
	 */
184
	 */
134
	public List getImacrosFile() {
185
	public List getImacrosFile() {
Lines 136-142 Link Here
136
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
187
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
137
			KVStringPair optionPair = (KVStringPair)i.next();
188
			KVStringPair optionPair = (KVStringPair)i.next();
138
			if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())) {
189
			if (optionPair.getKey().equals(SCDOptionsEnum.IMACROS_FILE.toString())) {
139
				imacrosFiles.add(optionPair.getValue());
190
				imacrosFiles.add(makeAbsolute(project,optionPair.getValue()));
140
			}
191
			}
141
		}
192
		}
142
		return imacrosFiles;
193
		return imacrosFiles;
Lines 150-156 Link Here
150
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
201
		for (Iterator i = compilerCommand.iterator(); i.hasNext(); ) {
151
			KVStringPair optionPair = (KVStringPair)i.next();
202
			KVStringPair optionPair = (KVStringPair)i.next();
152
			if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) {
203
			if (optionPair.getKey().equals(SCDOptionsEnum.INCLUDE_FILE.toString())) {
153
				includeFiles.add(optionPair.getValue());
204
				includeFiles.add(makeAbsolute(project,optionPair.getValue()));
154
			}
205
			}
155
		}
206
		}
156
		return includeFiles;
207
		return includeFiles;
Lines 182-188 Link Here
182
     * @return Returns the includes as strings.
233
     * @return Returns the includes as strings.
183
     */
234
     */
184
    public List getIncludes() {
235
    public List getIncludes() {
185
        return includes;
236
        return makeAbsolute(project, includes);
186
    }
237
    }
187
    /**
238
    /**
188
     * @param includes The includes to set.
239
     * @param includes The includes to set.
Lines 194-200 Link Here
194
     * @return Returns the quote include paths as strings (for #include "...")
245
     * @return Returns the quote include paths as strings (for #include "...")
195
     */
246
     */
196
    public List getQuoteIncludes() {
247
    public List getQuoteIncludes() {
197
        return quoteIncludes;
248
        return makeAbsolute(project, quoteIncludes);
198
    }
249
    }
199
    /**
250
    /**
200
     * @param includes. Quote include paths (for #include "...")
251
     * @param includes. Quote include paths (for #include "...")
Lines 308-312 Link Here
308
            setDiscovered(true);
359
            setDiscovered(true);
309
        }
360
        }
310
    }
361
    }
362
    
363
    public void resolveOptions(IProject project) {
364
    	ArrayList symbols = new ArrayList();
365
    	ArrayList includes = new ArrayList();
366
    	ArrayList quoteincludes = new ArrayList();
367
		for (Iterator options = compilerCommand.iterator(); options.hasNext(); ) {
368
			KVStringPair optionPair = (KVStringPair)options.next();
369
			String key = optionPair.getKey();
370
			String value = optionPair.getValue();
371
			if (key.equals(SCDOptionsEnum.INCLUDE.toString())) {
372
				includes.add(value);
373
			}
374
			else if (key.equals(SCDOptionsEnum.IDASH.toString())) {
375
				quoteincludes.add(value);
376
			}
377
			else if (key.equals(SCDOptionsEnum.DEFINE.toString())) {
378
				symbols.add(value);
379
			}
380
		}
381
		setIncludes(includes);
382
		setQuoteIncludes(quoteincludes);		                
383
		setSymbols(symbols);
384
        
385
		setDiscovered(true);    	
386
    }
387
    
388
	public static IPath makeRelative(IProject project, IPath path) {
389
		IResource resource = findResource(project, path);
390
		if (resource != null) {
391
			if (resource.getProject() == project) {
392
				path = resource.getProjectRelativePath();
393
			}
394
//			else {
395
//				path = resource.getFullPath();
396
//			}
397
		}
398
		return path;
399
	}
400
401
	private static IResource findResource(IProject project, IPath path) {
402
		IResource resource = project.findMember(path, true);
403
		if (resource == null) {
404
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
405
			resource = root.findMember(path, true);
406
			if (resource == null) {
407
				IResource[] resources = root.findFilesForLocation(path);
408
				if (resources != null) {
409
					for (int i = 0; i < resources.length; i++) {
410
						if (resources[i].getProject() == project) {
411
							resource = resources[i];
412
							break;
413
						}
414
					}
415
					// make a relative path to another project (better than an absolute path)
416
					if (resource == null && resources.length > 0) {
417
						resource = resources[0];
418
					}
419
				}
420
			}
421
		}
422
		return resource;
423
	}
424
425
	public static List makeRelative(IProject project, List paths) {
426
		List list = new ArrayList(paths.size());
427
		for (Iterator iter=paths.iterator(); iter.hasNext(); ) {
428
			String path = (String)iter.next();
429
			path = makeRelative(project, new Path(path)).toOSString();
430
			list.add(path);
431
		}
432
		return list;
433
	}
434
311
435
436
	public static final String makeAbsolute(IProject project, String path) {
437
		if (project != null && !new Path(path).isAbsolute()) {
438
			path = new File(project.getLocation().toOSString(), path).getAbsolutePath();
439
		}
440
		return path;
441
	}
442
443
	public static List makeAbsolute(IProject project, List paths) {
444
		List list = new ArrayList(paths.size());
445
		for (Iterator iter=paths.iterator(); iter.hasNext(); ) {
446
			String path = (String)iter.next();
447
			path = makeAbsolute(project, path);
448
			list.add(path);
449
		}
450
		return list;
451
	}
312
}
452
}
(-)src/org/eclipse/cdt/make/internal/core/scannerconfig2/PerFileSICollector.java (-19 / +36 lines)
Lines 24-29 Link Here
24
import java.util.TreeSet;
24
import java.util.TreeSet;
25
import java.util.Map.Entry;
25
import java.util.Map.Entry;
26
26
27
import org.eclipse.cdt.core.model.CoreModel;
28
import org.eclipse.cdt.core.model.IIncludeEntry;
27
import org.eclipse.cdt.make.core.MakeCorePlugin;
29
import org.eclipse.cdt.make.core.MakeCorePlugin;
28
import org.eclipse.cdt.make.core.scannerconfig.PathInfo;
30
import org.eclipse.cdt.make.core.scannerconfig.PathInfo;
29
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3;
31
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector3;
Lines 39-48 Link Here
39
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil;
41
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil;
40
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
42
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
41
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator;
43
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CygpathTranslator;
44
import org.eclipse.cdt.make.internal.core.scannerconfig.util.KVStringPair;
42
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
45
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
46
import org.eclipse.core.resources.IContainer;
43
import org.eclipse.core.resources.IFile;
47
import org.eclipse.core.resources.IFile;
44
import org.eclipse.core.resources.IProject;
48
import org.eclipse.core.resources.IProject;
45
import org.eclipse.core.resources.IResource;
49
import org.eclipse.core.resources.IResource;
50
import org.eclipse.core.resources.IWorkspaceRoot;
51
import org.eclipse.core.resources.ResourcesPlugin;
46
import org.eclipse.core.runtime.CoreException;
52
import org.eclipse.core.runtime.CoreException;
47
import org.eclipse.core.runtime.IPath;
53
import org.eclipse.core.runtime.IPath;
48
import org.eclipse.core.runtime.IProgressMonitor;
54
import org.eclipse.core.runtime.IProgressMonitor;
Lines 117-123 Link Here
117
                if (child.getNodeName().equals(CC_ELEM)) { 
123
                if (child.getNodeName().equals(CC_ELEM)) { 
118
                    Element cmdElem = (Element) child;
124
                    Element cmdElem = (Element) child;
119
                    boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); //$NON-NLS-1$
125
                    boolean cppFileType = cmdElem.getAttribute(FILE_TYPE_ATTR).equals("c++"); //$NON-NLS-1$
120
                    CCommandDSC command = new CCommandDSC(cppFileType);
126
                    CCommandDSC command = new CCommandDSC(cppFileType, project);
121
                    command.setCommandId(Integer.parseInt(cmdElem.getAttribute(ID_ATTR)));
127
                    command.setCommandId(Integer.parseInt(cmdElem.getAttribute(ID_ATTR)));
122
                    // deserialize command
128
                    // deserialize command
123
                    command.deserialize(cmdElem);
129
                    command.deserialize(cmdElem);
Lines 229-237 Link Here
229
            addScannerInfo(((Integer)resource), scannerInfo);
235
            addScannerInfo(((Integer)resource), scannerInfo);
230
            return;
236
            return;
231
        }
237
        }
232
        else if (!(resource instanceof IFile)) {
238
// GSA allow per project settings
233
            errorMessage = "resource is not an IFile";//$NON-NLS-1$
239
//        else if (!(resource instanceof IFile)) {
234
        }
240
//            errorMessage = "resource is not an IFile";//$NON-NLS-1$
241
//        }
235
        else if (((IFile) resource).getProject() == null) {
242
        else if (((IFile) resource).getProject() == null) {
236
            errorMessage = "project is null";//$NON-NLS-1$
243
            errorMessage = "project is null";//$NON-NLS-1$
237
        }
244
        }
Lines 242-260 Link Here
242
            TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", errorMessage); //$NON-NLS-1$
249
            TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", errorMessage); //$NON-NLS-1$
243
            return;
250
            return;
244
        }
251
        }
245
        IFile file = (IFile) resource;
252
        if (resource instanceof IFile) {
246
       
253
	        IFile file = (IFile) resource;
247
        for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
254
	       
248
            ScannerInfoTypes type = (ScannerInfoTypes) i.next();
255
	        for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
249
            if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
256
	            ScannerInfoTypes type = (ScannerInfoTypes) i.next();
250
                List commands = (List) scannerInfo.get(type);
257
	            if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
251
                for (Iterator j = commands.iterator(); j.hasNext(); ) {
258
	                List commands = (List) scannerInfo.get(type);
252
                    addCompilerCommand(file, (CCommandDSC) j.next());
259
	                for (Iterator j = commands.iterator(); j.hasNext(); ) {
253
                }
260
	                    addCompilerCommand(file, (CCommandDSC) j.next());
254
            }
261
	                }
255
            else {
262
	            }
256
                addScannerInfo(type, (List) scannerInfo.get(type));
263
	            else {
257
            }
264
	                addScannerInfo(type, (List) scannerInfo.get(type));
265
	            }
266
	        }
258
        }
267
        }
259
    }
268
    }
260
269
Lines 268-275 Link Here
268
            List siItem = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
277
            List siItem = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
269
            cmd.setSymbols(siItem);
278
            cmd.setSymbols(siItem);
270
            siItem = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);
279
            siItem = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);
271
            cmd.setIncludes(CygpathTranslator.translateIncludePaths(project, siItem));
280
            siItem = CygpathTranslator.translateIncludePaths(project, siItem);
281
            siItem = CCommandDSC.makeAbsolute(project, siItem);
282
            cmd.setIncludes(siItem);
272
            siItem = (List) scannerInfo.get(ScannerInfoTypes.QUOTE_INCLUDE_PATHS);
283
            siItem = (List) scannerInfo.get(ScannerInfoTypes.QUOTE_INCLUDE_PATHS);
284
            siItem = CygpathTranslator.translateIncludePaths(project, siItem);
285
            siItem = CCommandDSC.makeAbsolute(project, siItem);
273
            cmd.setQuoteIncludes(siItem);
286
            cmd.setQuoteIncludes(siItem);
274
            
287
            
275
            cmd.setDiscovered(true);
288
            cmd.setDiscovered(true);
Lines 336-341 Link Here
336
		        if (fileSet == null) {
349
		        if (fileSet == null) {
337
		            fileSet = new HashSet();
350
		            fileSet = new HashSet();
338
		            sid.commandIdToFilesMap.put(commandId, fileSet);
351
		            sid.commandIdToFilesMap.put(commandId, fileSet);
352
		            CCommandDSC cmd = (CCommandDSC) sid.commandIdCommandMap.get(commandId);
353
		            if (cmd != null) {
354
		            	cmd.resolveOptions(project);
355
		            }
339
		        }
356
		        }
340
		        if (fileSet.add(file)) {
357
		        if (fileSet.add(file)) {
341
		            // update fileToCommandIdsMap
358
		            // update fileToCommandIdsMap
Lines 827-832 Link Here
827
            	}
844
            	}
828
    			for (Iterator j = discovered.iterator(); j.hasNext(); ) {
845
    			for (Iterator j = discovered.iterator(); j.hasNext(); ) {
829
    			    String include = (String) j.next();
846
    			    String include = (String) j.next();
847
    			    include = CCommandDSC.makeRelative(project, new Path(include)).toPortableString();
830
    			    if (!allIncludes.contains(include)) {
848
    			    if (!allIncludes.contains(include)) {
831
    			        allIncludes.add(include);
849
    			        allIncludes.add(include);
832
    			    }
850
    			    }
Lines 872-876 Link Here
872
        }
890
        }
873
        return symbols;
891
        return symbols;
874
    }
892
    }
875
876
}
893
}
(-)src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParser.java (-42 / +172 lines)
Lines 41-46 Link Here
41
    private String[] compilerInvocation;
41
    private String[] compilerInvocation;
42
    private GCCPerFileBOPConsoleParserUtility fUtil;
42
    private GCCPerFileBOPConsoleParserUtility fUtil;
43
    
43
    
44
    /* (non-Javadoc)
45
     * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser#startup(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IPath, org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector, org.eclipse.cdt.core.IMarkerGenerator)
46
     */
44
    public void startup(IProject project, IPath workingDirectory, IScannerInfoCollector collector, IMarkerGenerator markerGenerator) {
47
    public void startup(IProject project, IPath workingDirectory, IScannerInfoCollector collector, IMarkerGenerator markerGenerator) {
45
        fUtil = (project != null && workingDirectory != null && markerGenerator != null) ?
48
        fUtil = (project != null && workingDirectory != null && markerGenerator != null) ?
46
                new GCCPerFileBOPConsoleParserUtility(project, workingDirectory, markerGenerator) : null;
49
                new GCCPerFileBOPConsoleParserUtility(project, workingDirectory, markerGenerator) : null;
Lines 50-59 Link Here
50
        compilerInvocation = getCompilerCommands();
53
        compilerInvocation = getCompilerCommands();
51
    }
54
    }
52
55
56
    /* (non-Javadoc)
57
     * @see org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser#getUtility()
58
     */
53
    protected AbstractGCCBOPConsoleParserUtility getUtility() {
59
    protected AbstractGCCBOPConsoleParserUtility getUtility() {
54
        return fUtil;
60
        return fUtil;
55
    }
61
    }
56
62
63
    /* (non-Javadoc)
64
     * @see org.eclipse.cdt.make.internal.core.scannerconfig.gnu.AbstractGCCBOPConsoleParser#processSingleLine(java.lang.String)
65
     */
57
    protected boolean processSingleLine(String line) {
66
    protected boolean processSingleLine(String line) {
58
        boolean rc = false;
67
        boolean rc = false;
59
        // GCC C/C++ compiler invocation 
68
        // GCC C/C++ compiler invocation 
Lines 66-151 Link Here
66
        if (compilerInvocationIndex == -1)
75
        if (compilerInvocationIndex == -1)
67
            return rc;
76
            return rc;
68
77
69
        // Search for the compiler invocation command
78
        // split and unquote all segments; supports build command such as 
70
        
79
        // sh -c 'gcc -g -O0 -I"includemath" -I "include abc" -Iincludeprint -c impl/testmath.c'
71
        // expecting that compiler invocation is the first token in the line
80
        ArrayList split = splitLine(line, compilerInvocationIndex);
72
        String[] split = line.split("\\s+"); //$NON-NLS-1$
81
73
        boolean found = false;
82
        // get the position of the compiler command in the build command
74
        for (int i = 0; i < split.length; ++i) {
83
        for (compilerInvocationIndex=0; compilerInvocationIndex<split.size(); compilerInvocationIndex++) {
75
	        String command = split[i];
84
	        String command = (String)split.get(compilerInvocationIndex);
76
	        // verify that it is compiler invocation
85
	        // verify that it is compiler invocation
86
	        int cii2 = -1;
77
	        for (int cii = 0; cii < compilerInvocation.length; ++cii) {
87
	        for (int cii = 0; cii < compilerInvocation.length; ++cii) {
78
	            if (command.indexOf(compilerInvocation[cii]) >= 0) {
88
	        	cii2 = command.indexOf(compilerInvocation[cii]);
79
	            	found = true;
89
	        	if (cii2 >= 0)
80
	            	if (i > 0) {
90
	                break;
81
	            		// strip off anything before the compiler command
82
		            	String[] old = split;
83
		            	split = new String[old.length - i];
84
		            	System.arraycopy(old, i, split, 0, split.length);
85
	            	}
86
	            	break;
87
	            }
88
	        }
91
	        }
89
	        if (found)
92
        	if (cii2 >= 0)
90
	        	break;
93
                break;
91
        }
94
        }    
92
        if (!found) {
95
	    if (compilerInvocationIndex >= split.size()) {
93
            TraceUtil.outputTrace("Error identifying compiler command", line, TraceUtil.EOL); //$NON-NLS-1$
96
            TraceUtil.outputTrace("Error identifying compiler command", line, TraceUtil.EOL); //$NON-NLS-1$
94
            return rc;
97
            return rc;
95
        }
98
        }
96
        
97
        // find a file name
99
        // find a file name
98
        int extensionsIndex = -1;
100
        int extensionsIndex = -1;
99
        found = false;
101
        boolean found = false;
100
        String filePath = null;
102
        String filePath = null;
101
        for (int i = 1; i < split.length; ++i) {
103
        for (int i = compilerInvocationIndex+1; i < split.size(); ++i) {
102
            int k = split[i].lastIndexOf('.');
104
        	String segment = (String)split.get(i);
103
            if (k != -1 && (split[i].length() - k < 5)) {
105
            int k = segment.lastIndexOf('.');
104
                String fileExtension = split[i].substring(k);
106
            if (k != -1 && (segment.length() - k < 5)) {
107
                String fileExtension = segment.substring(k);
105
                extensionsIndex = FILE_EXTENSIONS_LIST.indexOf(fileExtension);
108
                extensionsIndex = FILE_EXTENSIONS_LIST.indexOf(fileExtension);
106
                if (extensionsIndex != -1) {
109
                if (extensionsIndex != -1) {
107
                    filePath = split[i];
110
                    filePath = segment;
108
                    found = true;
111
                    found = true;
109
                    break;
112
                    break;
110
                }
113
                }
111
            }
114
            }
112
        }
115
        }
113
116
//              for (int j = 0; j < FILE_EXTENSIONS.length; ++j) {
117
//                  if (split[i].endsWith(FILE_EXTENSIONS[j])) {
118
//                      filePath = split[i];
119
//                      extensionsIndex = j;
120
//                      found = true;
121
//                      break;
122
//                  }
123
//              }
124
//              if (found) break;
114
        if (!found) {
125
        if (!found) {
115
            TraceUtil.outputTrace("Error identifying file name :1", line, TraceUtil.EOL); //$NON-NLS-1$
126
            TraceUtil.outputTrace("Error identifying file name :1", line, TraceUtil.EOL); //$NON-NLS-1$
116
            return rc;
127
            return rc;
117
        }
128
        }
118
        
119
        // sanity check
129
        // sanity check
120
        if (filePath.indexOf(FILE_EXTENSIONS[extensionsIndex]) == -1) {
130
        if (filePath.indexOf(FILE_EXTENSIONS[extensionsIndex]) == -1) {
121
            TraceUtil.outputTrace("Error identifying file name :2", line, TraceUtil.EOL); //$NON-NLS-1$
131
            TraceUtil.outputTrace("Error identifying file name :2", line, TraceUtil.EOL); //$NON-NLS-1$
122
            return rc;
132
            return rc;
123
        }
133
        }
124
        
125
        if (fUtil != null) {
134
        if (fUtil != null) {
126
            IPath pFilePath = fUtil.getAbsolutePath(filePath);
135
            IPath pFilePath = fUtil.getAbsolutePath(filePath);
127
            String shortFileName = pFilePath.removeFileExtension().lastSegment();
136
            String shortFileName = pFilePath.removeFileExtension().lastSegment();
128
137
129
            // generalize occurances of the file name
138
            // generalize occurances of the file name
130
            StringBuffer genericLine = new StringBuffer();
139
            for (int i = 0; i < split.size(); i++) {
131
            for (int i = 0; i < split.length; i++) {
140
				String token = (String)split.get(i);
132
				String token = split[i];
141
				if (token.equals("-include")) { //$NON-NLS-1$
133
				if (token.equals("-include") || token.equals("-imacros")) { //$NON-NLS-1$ //$NON-NLS-2$
142
					++i;
143
				}
144
				else if (token.equals("-imacros")) { //$NON-NLS-1$
134
					++i;
145
					++i;
135
					genericLine.append(token);
136
					genericLine.append(' ');
137
				}
146
				}
138
				else if (token.equals(filePath)) {
147
				else if (token.equals(filePath)) {
139
					split[i] = "LONG_NAME"; //$NON-NLS-1$
148
					split.set(i, "LONG_NAME"); //$NON-NLS-1$
140
				}
149
				}
141
				else if (token.startsWith(shortFileName)) {
150
				else if (token.startsWith(shortFileName)) {
142
					split[i] = token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$
151
					split.set(i, token.replaceFirst(shortFileName, "SHORT_NAME")); //$NON-NLS-1$
143
				}
152
				}
144
				genericLine.append(split[i]);
145
				genericLine.append(' ');
146
			}
153
			}
147
            
154
            
148
            CCommandDSC cmd = fUtil.getNewCCommandDSC(genericLine.toString(), extensionsIndex > 0);
155
            CCommandDSC cmd = fUtil.getNewCCommandDSC((String[])split.toArray(new String[split.size()]), extensionsIndex > 0);
149
            IPath baseDirectory = fUtil.getBaseDirectory();
156
            IPath baseDirectory = fUtil.getBaseDirectory();
150
            if (baseDirectory.isPrefixOf(pFilePath)) {
157
            if (baseDirectory.isPrefixOf(pFilePath)) {
151
	            List cmdList = new ArrayList();
158
	            List cmdList = new ArrayList();
Lines 173-176 Link Here
173
        return rc;
180
        return rc;
174
    }
181
    }
175
182
183
    /**
184
     * Splits and unquotes all compiler command segments; supports build command such as 
185
     *    sh -c 'gcc -g -O0 -I"includemath" -I "include abc" -Iincludeprint -c impl/testmath.c'
186
     */
187
    private ArrayList<String> splitLine(String line, int compilerInvocationIndex) {
188
        ArrayList<String> split = new ArrayList<String>();
189
        boolean bSingleQuotes = false;
190
        boolean bIgnoreSingleQuotes = false;
191
        boolean bDoubleQuotes = false;
192
        boolean bIgnoreDoubleQuotes = false;
193
        char[] chars = line.toCharArray();
194
        int charPos = 0;
195
        int length = line.length();
196
        boolean quit = false;
197
        boolean acceptExtraSingleQuote = false;
198
        boolean acceptExtraDoubleQuote = false;
199
200
        // eat whitespace
201
        while (charPos < length) {
202
        	char ch = chars[charPos];
203
        	if (!Character.isWhitespace(ch)) {
204
        		break;
205
        	}
206
        	charPos++;
207
        }
208
        // read token
209
        while (charPos<length && !quit) {
210
	        int startPos = -1;
211
	        int endPos = -1;
212
	        while (charPos<length && !quit) {
213
	        	char ch = chars[charPos];
214
	        	if (ch == '\'') {
215
	        		// ignore quotes before the actual compiler command (the command itself including its options
216
	        		// could be within quotes--in this case we nevertheless want to split the compiler command into segments)
217
	        		if (charPos <= compilerInvocationIndex) {
218
	        			bIgnoreSingleQuotes = !bIgnoreSingleQuotes;
219
	        		}
220
	        		else {
221
	        			if (bIgnoreSingleQuotes) {
222
	        				bIgnoreSingleQuotes = false;
223
	    	        		if (startPos >= 0) {
224
	    	        			endPos = charPos;  // end of a token
225
	    	        		}
226
    	        			quit = true;  // quit after closed quote containing the actual compiler command
227
	        			}
228
	        			else {
229
	        				bSingleQuotes = !bSingleQuotes;
230
	        			}
231
	        		}
232
// do split token here: allow -DMYKEY='MYVALUE' or-DMYKEY=\'MYVALUE\' 
233
	        		if (startPos >= 0) {
234
	        			char prevch = charPos > 0 ? chars[charPos-1] : '\0';
235
	        			if (acceptExtraSingleQuote) {
236
	        				acceptExtraSingleQuote = false;
237
	        			}
238
	        			else if (prevch != '=' && prevch != '\\') {
239
	        				endPos = charPos;  // end of a token
240
	        			}
241
	        			else {
242
	        				acceptExtraSingleQuote = true;
243
	        			}
244
	        		}
245
	        	}
246
	        	else if (ch == '"') {
247
	        		// ignore quotes before the actual compiler command (the command itself including its options
248
	        		// could be within quotes--in this case we nevertheless want to split the compiler command into segments)
249
	        		if (charPos <= compilerInvocationIndex) {
250
	        			bIgnoreDoubleQuotes = !bIgnoreDoubleQuotes;
251
	        		}
252
	        		else {
253
	        			if (bIgnoreDoubleQuotes) {
254
	        				bIgnoreDoubleQuotes = false;
255
	    	        		if (startPos >= 0) {
256
	    	        			endPos = charPos;  // end of a token
257
	    	        		}
258
    	        			quit = true;  // quit after closed quote containing the actual compiler command
259
	        			}
260
	        			else {
261
	    	        		bDoubleQuotes = !bDoubleQuotes;
262
	        			}
263
	        		}
264
// do split token here: allow -DMYKEY="MYVALUE" or-DMYKEY=\"MYVALUE\" 
265
	        		if (startPos >= 0) {
266
	        			char prevch = charPos > 0 ? chars[charPos-1] : '\0';
267
	        			if (acceptExtraDoubleQuote) {
268
	        				acceptExtraDoubleQuote = false;
269
	        			}
270
	        			else if (prevch != '=' && prevch != '\\') {
271
	        				endPos = charPos;  // end of a token
272
	        			}
273
	        			else {
274
	        				acceptExtraDoubleQuote = true;
275
	        			}
276
	        		}
277
	        	}
278
	        	else if (Character.isWhitespace(ch) || ch == ';') {
279
	        		if (startPos < 0 && (bSingleQuotes || bDoubleQuotes)) {
280
	        			startPos = charPos;
281
	        		}
282
	        		else if (startPos >= 0 && !bSingleQuotes && !bDoubleQuotes) {
283
	        			endPos = charPos;  // end of a token
284
	        		}
285
	        	}
286
	        	else {  // a valid character, starts or continues a token
287
	        		if (startPos < 0) {
288
	        			startPos = charPos;
289
	        		}
290
	        		if (charPos == length-1) {
291
	        			endPos = charPos+1;   // end of token
292
	        		}
293
	        	}
294
	        	charPos++;
295
	        	// a complete token has been found
296
	        	if (startPos >= 0 && endPos > startPos) {
297
	        		break;
298
	        	}
299
	        }
300
	    	if (startPos >= 0 && endPos >= 0 && startPos >= compilerInvocationIndex) {
301
	    		split.add(line.substring(startPos, endPos));
302
	    	}
303
        }
304
        return split;
305
    }
176
}
306
}
(-)src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/AbstractGCCBOPConsoleParser.java (-2 / +13 lines)
Lines 83-91 Link Here
83
     */
83
     */
84
    public boolean processLine(String line) {
84
    public boolean processLine(String line) {
85
        boolean rc = false;
85
        boolean rc = false;
86
        int lineBreakPos = line.length()-1;
87
        char[] lineChars = line.toCharArray();
88
        while(lineBreakPos >= 0 && Character.isWhitespace(lineChars[lineBreakPos])) {
89
        	lineBreakPos--;
90
        }
91
        if (lineBreakPos >= 0) {
92
        	if (lineChars[lineBreakPos] != '\\'
93
        	    || (lineBreakPos > 0 && lineChars[lineBreakPos-1] == '\\')) {
94
        		lineBreakPos = -1;
95
        	}
96
        }
86
        // check for multiline commands (ends with '\')
97
        // check for multiline commands (ends with '\')
87
        if (line.endsWith("\\")) { //$NON-NLS-1$
98
        if (lineBreakPos >= 0) {
88
            sMultiline += line.substring(0, line.length()-1);// + " "; 
99
       		sMultiline += line.substring(0, lineBreakPos);
89
            bMultiline = true;
100
            bMultiline = true;
90
            return rc;
101
            return rc;
91
        }
102
        }
(-)src/org/eclipse/cdt/make/internal/core/scannerconfig/gnu/GCCPerFileBOPConsoleParserUtility.java (-4 / +4 lines)
Lines 111-117 Link Here
111
            return;
111
            return;
112
        compiledFileList.add(longFileName);
112
        compiledFileList.add(longFileName);
113
113
114
        CCommandDSC command = getNewCCommandDSC(genericLine, false); // assume .c file type
114
        String[] tokens = genericLine.split("\\s+"); //$NON-NLS-1$
115
        CCommandDSC command = getNewCCommandDSC(tokens, false); // assume .c file type
115
        int index = commandsList2.indexOf(command);
116
        int index = commandsList2.indexOf(command);
116
        if (index == -1) {
117
        if (index == -1) {
117
            commandsList2.add(command);
118
            commandsList2.add(command);
Lines 130-138 Link Here
130
     * @param cppFileType
131
     * @param cppFileType
131
     * @return CCommandDSC compile command description 
132
     * @return CCommandDSC compile command description 
132
     */
133
     */
133
    public CCommandDSC getNewCCommandDSC(String genericLine, boolean cppFileType) {
134
    public CCommandDSC getNewCCommandDSC(String[] tokens, boolean cppFileType) {
134
        CCommandDSC command = new CCommandDSC(cppFileType);
135
        CCommandDSC command = new CCommandDSC(cppFileType, getProject());
135
        String[] tokens = genericLine.split("\\s+"); //$NON-NLS-1$
136
        command.addSCOption(new KVStringPair(SCDOptionsEnum.COMMAND.toString(), tokens[0]));
136
        command.addSCOption(new KVStringPair(SCDOptionsEnum.COMMAND.toString(), tokens[0]));
137
        for (int i = 1; i < tokens.length; ++i) {
137
        for (int i = 1; i < tokens.length; ++i) {
138
        	String token = tokens[i];
138
        	String token = tokens[i];

Return to bug 156008