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/gnu/GCCPerFileBOPConsoleParser.java (-26 / +128 lines)
Lines 75-91 Link Here
75
        if (compilerInvocationIndex == -1)
75
        if (compilerInvocationIndex == -1)
76
            return rc;
76
            return rc;
77
77
78
        // expecting that compiler invocation is the first token in the line
78
        // split and unquote all segments; supports build command such as 
79
        String[] split = line.split("\\s+"); //$NON-NLS-1$
79
        // sh -c 'gcc -g -O0 -I"includemath" -I "include abc" -Iincludeprint -c impl/testmath.c'
80
        String command = split[0];
80
        ArrayList split = splitLine(line, compilerInvocationIndex);
81
        // verify that it is compiler invocation
81
82
        int cii2 = -1;
82
        // get the position of the compiler command in the build command
83
        for (int cii = 0; cii < compilerInvocation.length; ++cii) {
83
        for (compilerInvocationIndex=0; compilerInvocationIndex<split.size(); compilerInvocationIndex++) {
84
            cii2 = command.indexOf(compilerInvocation[cii]);
84
	        String command = (String)split.get(compilerInvocationIndex);
85
            if (cii2 != -1)
85
	        // verify that it is compiler invocation
86
	        int cii2 = -1;
87
	        for (int cii = 0; cii < compilerInvocation.length; ++cii) {
88
	        	cii2 = command.indexOf(compilerInvocation[cii]);
89
	        	if (cii2 >= 0)
90
	                break;
91
	        }
92
        	if (cii2 >= 0)
86
                break;
93
                break;
87
        }
94
        }    
88
        if (cii2 == -1) {
95
	    if (compilerInvocationIndex >= split.size()) {
89
            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$
90
            return rc;
97
            return rc;
91
        }
98
        }
Lines 93-105 Link Here
93
        int extensionsIndex = -1;
100
        int extensionsIndex = -1;
94
        boolean found = false;
101
        boolean found = false;
95
        String filePath = null;
102
        String filePath = null;
96
        for (int i = 1; i < split.length; ++i) {
103
        for (int i = compilerInvocationIndex+1; i < split.size(); ++i) {
97
            int k = split[i].lastIndexOf('.');
104
        	String segment = (String)split.get(i);
98
            if (k != -1 && (split[i].length() - k < 5)) {
105
            int k = segment.lastIndexOf('.');
99
                String fileExtension = split[i].substring(k);
106
            if (k != -1 && (segment.length() - k < 5)) {
107
                String fileExtension = segment.substring(k);
100
                extensionsIndex = FILE_EXTENSIONS_LIST.indexOf(fileExtension);
108
                extensionsIndex = FILE_EXTENSIONS_LIST.indexOf(fileExtension);
101
                if (extensionsIndex != -1) {
109
                if (extensionsIndex != -1) {
102
                    filePath = split[i];
110
                    filePath = segment;
103
                    found = true;
111
                    found = true;
104
                    break;
112
                    break;
105
                }
113
                }
Lines 128-152 Link Here
128
            String shortFileName = pFilePath.removeFileExtension().lastSegment();
136
            String shortFileName = pFilePath.removeFileExtension().lastSegment();
129
137
130
            // generalize occurances of the file name
138
            // generalize occurances of the file name
131
            StringBuffer genericLine = new StringBuffer();
139
            for (int i = 0; i < split.size(); i++) {
132
            for (int i = 0; i < split.length; i++) {
140
				String token = (String)split.get(i);
133
				String token = split[i];
141
				if (token.equals("-include")) { //$NON-NLS-1$
134
				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$
135
					++i;
145
					++i;
136
					genericLine.append(token);
137
					genericLine.append(' ');
138
				}
146
				}
139
				else if (token.equals(filePath)) {
147
				else if (token.equals(filePath)) {
140
					split[i] = "LONG_NAME"; //$NON-NLS-1$
148
					split.set(i, "LONG_NAME"); //$NON-NLS-1$
141
				}
149
				}
142
				else if (token.startsWith(shortFileName)) {
150
				else if (token.startsWith(shortFileName)) {
143
					split[i] = token.replaceFirst(shortFileName, "SHORT_NAME"); //$NON-NLS-1$
151
					split.set(i, token.replaceFirst(shortFileName, "SHORT_NAME")); //$NON-NLS-1$
144
				}
152
				}
145
				genericLine.append(split[i]);
146
				genericLine.append(' ');
147
			}
153
			}
148
            
154
            
149
            CCommandDSC cmd = fUtil.getNewCCommandDSC(genericLine.toString(), extensionsIndex > 0);
155
            CCommandDSC cmd = fUtil.getNewCCommandDSC((String[])split.toArray(new String[split.size()]), extensionsIndex > 0);
150
            IPath baseDirectory = fUtil.getBaseDirectory();
156
            IPath baseDirectory = fUtil.getBaseDirectory();
151
            if (baseDirectory.isPrefixOf(pFilePath)) {
157
            if (baseDirectory.isPrefixOf(pFilePath)) {
152
	            List cmdList = new ArrayList();
158
	            List cmdList = new ArrayList();
Lines 174-177 Link Here
174
        return rc;
180
        return rc;
175
    }
181
    }
176
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
197
        // eat whitespace
198
        while (charPos < length) {
199
        	char ch = chars[charPos];
200
        	if (!Character.isWhitespace(ch)) {
201
        		break;
202
        	}
203
        	charPos++;
204
        }
205
        // read token
206
        while (charPos<length) {
207
	        int startPos = -1;
208
	        int endPos = -1;
209
	        while (charPos<length) {
210
	        	char ch = chars[charPos];
211
	        	if (ch == '\'') {
212
	        		// ignore quotes before the actual compiler command (the command itself including its options
213
	        		// could be within quotes--in this case we nevertheless want to split the compiler command into segments)
214
	        		if (charPos <= compilerInvocationIndex) {
215
	        			bIgnoreSingleQuotes = !bIgnoreSingleQuotes;
216
	        		}
217
	        		else {
218
	        			if (bIgnoreSingleQuotes) {
219
	        				bIgnoreSingleQuotes = false;
220
	        				charPos = length;  // quit after closed quote containing the actual compiler command
221
	        				break;
222
	        			}
223
	        			else {
224
	        				bSingleQuotes = !bSingleQuotes;
225
	        			}
226
	        		}
227
	        		if (startPos >= 0) {
228
	        			endPos = charPos;  // end of a token
229
	        		}
230
	        	}
231
	        	else if (ch == '"') {
232
	        		// ignore quotes before the actual compiler command (the command itself including its options
233
	        		// could be within quotes--in this case we nevertheless want to split the compiler command into segments)
234
	        		if (charPos <= compilerInvocationIndex) {
235
	        			bIgnoreDoubleQuotes = !bIgnoreDoubleQuotes;
236
	        		}
237
	        		else {
238
	        			if (bIgnoreDoubleQuotes) {
239
	        				bIgnoreDoubleQuotes = false;
240
	        				charPos = length;  // quit after closed quote containing the actual compiler command
241
	        				break;
242
	        			}
243
	        			else {
244
	    	        		bDoubleQuotes = !bDoubleQuotes;
245
	        			}
246
	        		}
247
	        		if (startPos >= 0) {
248
	        			endPos = charPos;  // end of a token
249
	        		}
250
	        	}
251
	        	else if (Character.isWhitespace(ch)) {
252
	        		if (startPos < 0 && (bSingleQuotes || bDoubleQuotes)) {
253
	        			startPos = charPos;
254
	        		}
255
	        		else if (startPos >= 0 && !bSingleQuotes && !bDoubleQuotes) {
256
	        			endPos = charPos;  // end of a token
257
	        		}
258
	        	}
259
	        	else {  // a valid character, starts or continues a token
260
	        		if (startPos < 0) {
261
	        			startPos = charPos;
262
	        		}
263
	        		if (charPos == length) {
264
	        			endPos = charPos;   // end of token
265
	        		}
266
	        	}
267
	        	charPos++;
268
	        	// a complete token has been found
269
	        	if (startPos >= 0 && endPos > startPos) {
270
	        		break;
271
	        	}
272
	        }
273
	    	if (startPos >= 0 && endPos >= 0 && startPos >= compilerInvocationIndex) {
274
	    		split.add(line.substring(startPos, endPos));
275
	    	}
276
        }
277
        return split;
278
    }
177
}
279
}

Return to bug 156008