mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 304139: [Scanner Discovery] Compiler inspection does not work for
gcc with non-english locale
This commit is contained in:
parent
672f318deb
commit
004458cc9b
1 changed files with 110 additions and 94 deletions
|
@ -1,94 +1,110 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.core.scannerconfig2;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Runs a command to retrieve compiler intrinsic scanner info from 'specs' file.
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
public class GCCSpecsRunSIProvider extends DefaultRunSIProvider {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.DefaultRunSIProvider#initialize()
|
||||
*/
|
||||
@Override
|
||||
protected boolean initialize() {
|
||||
boolean rc = super.initialize();
|
||||
|
||||
if (rc) {
|
||||
String targetFile = "dummy"; //$NON-NLS-1$
|
||||
IProject project = resource.getProject();
|
||||
try {
|
||||
if (project.hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
targetFile = GCCScannerConfigUtil.CPP_SPECS_FILE;
|
||||
}
|
||||
else if (project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
targetFile = GCCScannerConfigUtil.C_SPECS_FILE;
|
||||
}
|
||||
// replace string variables in compile arguments
|
||||
// TODO Vmir - use string variable replacement
|
||||
for (int i = 0; i < fCompileArguments.length; ++i) {
|
||||
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{plugin_state_location\\}", //$NON-NLS-1$
|
||||
MakeCorePlugin.getWorkingDirectory().toString());
|
||||
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{specs_file\\}", targetFile); //$NON-NLS-1$
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
//TODO VMIR better error handling
|
||||
MakeCorePlugin.log(e.getStatus());
|
||||
rc = false;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.DefaultRunSIProvider#prepareArguments(boolean)
|
||||
*/
|
||||
@Override
|
||||
protected String[] prepareArguments(boolean isDefaultCommand) {
|
||||
if (collector == null)
|
||||
return fCompileArguments;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> tso = collector.getCollectedScannerInfo(resource.getProject(), ScannerInfoTypes.TARGET_SPECIFIC_OPTION);
|
||||
if (tso == null || tso.size() == 0) {
|
||||
return fCompileArguments;
|
||||
}
|
||||
|
||||
String[] rv = null;
|
||||
// commandArguments may have multiple arguments; tokenizing
|
||||
int nTokens = 0;
|
||||
if (fCompileArguments != null && fCompileArguments.length > 0) {
|
||||
nTokens = fCompileArguments.length;
|
||||
rv = new String[nTokens + tso.size()];
|
||||
System.arraycopy(fCompileArguments, 0, rv, 0, nTokens);
|
||||
}
|
||||
else {
|
||||
rv = new String[tso.size()];
|
||||
}
|
||||
for (int i = 0; i < tso.size(); ++i) {
|
||||
rv[nTokens + i] = tso.get(i);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2011 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.core.scannerconfig2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Runs a command to retrieve compiler intrinsic scanner info from 'specs' file.
|
||||
*
|
||||
* @author vhirsl
|
||||
*/
|
||||
public class GCCSpecsRunSIProvider extends DefaultRunSIProvider {
|
||||
/**
|
||||
* Override LC_ALL so {@link org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser}
|
||||
* understands the diagnostics generated when non-English locale is active.
|
||||
*
|
||||
* @see org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser
|
||||
*/
|
||||
@Override
|
||||
protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) {
|
||||
Properties extendedEnv = new Properties();
|
||||
extendedEnv.putAll(initialEnv);
|
||||
extendedEnv.put("LC_ALL", "C"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
return super.setEnvironment(launcher, extendedEnv);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.DefaultRunSIProvider#initialize()
|
||||
*/
|
||||
@Override
|
||||
protected boolean initialize() {
|
||||
boolean rc = super.initialize();
|
||||
|
||||
if (rc) {
|
||||
String targetFile = "dummy"; //$NON-NLS-1$
|
||||
IProject project = resource.getProject();
|
||||
try {
|
||||
if (project.hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
targetFile = GCCScannerConfigUtil.CPP_SPECS_FILE;
|
||||
}
|
||||
else if (project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
targetFile = GCCScannerConfigUtil.C_SPECS_FILE;
|
||||
}
|
||||
// replace string variables in compile arguments
|
||||
// TODO Vmir - use string variable replacement
|
||||
for (int i = 0; i < fCompileArguments.length; ++i) {
|
||||
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{plugin_state_location\\}", //$NON-NLS-1$
|
||||
MakeCorePlugin.getWorkingDirectory().toString());
|
||||
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{specs_file\\}", targetFile); //$NON-NLS-1$
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
//TODO VMIR better error handling
|
||||
MakeCorePlugin.log(e.getStatus());
|
||||
rc = false;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.internal.core.scannerconfig2.DefaultRunSIProvider#prepareArguments(boolean)
|
||||
*/
|
||||
@Override
|
||||
protected String[] prepareArguments(boolean isDefaultCommand) {
|
||||
if (collector == null)
|
||||
return fCompileArguments;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> tso = collector.getCollectedScannerInfo(resource.getProject(), ScannerInfoTypes.TARGET_SPECIFIC_OPTION);
|
||||
if (tso == null || tso.size() == 0) {
|
||||
return fCompileArguments;
|
||||
}
|
||||
|
||||
String[] rv = null;
|
||||
// commandArguments may have multiple arguments; tokenizing
|
||||
int nTokens = 0;
|
||||
if (fCompileArguments != null && fCompileArguments.length > 0) {
|
||||
nTokens = fCompileArguments.length;
|
||||
rv = new String[nTokens + tso.size()];
|
||||
System.arraycopy(fCompileArguments, 0, rv, 0, nTokens);
|
||||
}
|
||||
else {
|
||||
rv = new String[tso.size()];
|
||||
}
|
||||
for (int i = 0; i < tso.size(); ++i) {
|
||||
rv[nTokens + i] = tso.get(i);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue