1
0
Fork 0
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:
Dries Harnie 2011-11-28 16:08:46 -05:00 committed by Andrew Gvozdev
parent 672f318deb
commit 004458cc9b

View file

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