mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
bug 342069: Scanner discovery output is lost when running compiler specs command
This commit is contained in:
parent
6aab2550d6
commit
72353369b3
5 changed files with 134 additions and 22 deletions
|
@ -36,11 +36,16 @@ ScannerConfigNature.Missing_Project=Missing or closed project
|
|||
|
||||
ScannerConfigInfoFactory.Missing_Builder=Missing Builder:
|
||||
|
||||
ExternalScannerInfoProvider.Provider_Error=Error launching external scanner info generator ({0})
|
||||
ExternalScannerInfoProvider.Console_Name=CDT Built-in Specs Console, {0}
|
||||
ExternalScannerInfoProvider.Reading_Specs=Reading specs ...
|
||||
ExternalScannerInfoProvider.Invoking_Command=Invoking Command:
|
||||
ExternalScannerInfoProvider.Parsing_Output=Parsing output ...
|
||||
ExternalScannerInfoProvider.Creating_Markers=Generating markers ...
|
||||
# Error_Prefix affects generation of markers in the Problems view
|
||||
ExternalScannerInfoProvider.Error_Prefix=Warning:
|
||||
ExternalScannerInfoProvider.Provider_Error=Error launching external scanner info generator ({0})
|
||||
ExternalScannerInfoProvider.Working_Directory=Working directory: {0}
|
||||
ExternalScannerInfoProvider.Program_Not_In_Path=Program ''{0}'' is not found in $PATH
|
||||
|
||||
ScannerInfoCollector.Processing=Processing discovered scanner configuration ...
|
||||
ScannerInfoCollector.Updating=Updating Scanner Configuration for project
|
||||
|
|
|
@ -20,8 +20,9 @@ import java.util.Properties;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CommandLauncher;
|
||||
import org.eclipse.cdt.core.ErrorParserManager;
|
||||
import org.eclipse.cdt.core.ICommandLauncher;
|
||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
|
||||
import org.eclipse.cdt.make.core.MakeBuilder;
|
||||
|
@ -35,8 +36,8 @@ import org.eclipse.cdt.make.internal.core.MakeMessages;
|
|||
import org.eclipse.cdt.make.internal.core.StreamMonitor;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigUtil;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerInfoConsoleParserFactory;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
|
||||
import org.eclipse.cdt.utils.EFSExtensionManager;
|
||||
import org.eclipse.cdt.utils.PathUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -44,6 +45,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
/**
|
||||
* New default external scanner info provider of type 'run'
|
||||
|
@ -52,8 +56,11 @@ import org.eclipse.core.runtime.SubProgressMonitor;
|
|||
*/
|
||||
public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
||||
private static final String EXTERNAL_SI_PROVIDER_ERROR = "ExternalScannerInfoProvider.Provider_Error"; //$NON-NLS-1$
|
||||
private static final String EXTERNAL_SI_PROVIDER_CONSOLE_ID = MakeCorePlugin.getUniqueIdentifier() + ".ExternalScannerInfoProviderConsole"; //$NON-NLS-1$
|
||||
private static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; //$NON-NLS-1$
|
||||
private static final String PREF_CONSOLE_ENABLED = "org.eclipse.cdt.make.core.scanner.discovery.console.enabled"; //$NON-NLS-1$
|
||||
private static final String LANG_ENV_VAR = "LANG"; //$NON-NLS-1$
|
||||
private static final String NEWLINE = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final String PATH_ENV = "PATH"; //$NON-NLS-1$
|
||||
|
||||
protected IResource resource;
|
||||
protected String providerId;
|
||||
|
@ -96,7 +103,16 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
monitor.beginTask(MakeMessages.getString("ExternalScannerInfoProvider.Reading_Specs"), 100); //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
IConsole console = CCorePlugin.getDefault().getConsole(EXTERNAL_SI_PROVIDER_CONSOLE_ID);
|
||||
ILanguage language = context.getLanguage();
|
||||
IConsole console;
|
||||
if (language!=null && isConsoleEnabled()) {
|
||||
String consoleId = MakeCorePlugin.PLUGIN_ID + '.' + providerId + '.' + language.getId();
|
||||
String consoleName = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Console_Name", language.getName()); //$NON-NLS-1$
|
||||
console = CCorePlugin.getDefault().getBuildConsole(consoleId, consoleName, null);
|
||||
} else {
|
||||
// that looks in extension points registry and won't find the id
|
||||
console = CCorePlugin.getDefault().getConsole(MakeCorePlugin.PLUGIN_ID + ".console.hidden"); //$NON-NLS-1$
|
||||
}
|
||||
console.start(currentProject);
|
||||
OutputStream cos = console.getOutputStream();
|
||||
|
||||
|
@ -110,17 +126,21 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
launcher.showCommand(true);
|
||||
|
||||
String[] comandLineOptions = getCommandLineOptions();
|
||||
String ca = coligate(comandLineOptions);
|
||||
String params = coligate(comandLineOptions);
|
||||
|
||||
monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Invoking_Command") //$NON-NLS-1$
|
||||
+ getCommandToLaunch() + ca);
|
||||
cos = new StreamMonitor(new SubProgressMonitor(monitor, 70), cos, 100);
|
||||
|
||||
ConsoleOutputSniffer sniffer = ScannerInfoConsoleParserFactory.getESIProviderOutputSniffer(
|
||||
cos, cos, currentProject, context, providerId, buildInfo, collector, markerGenerator);
|
||||
+ getCommandToLaunch() + params);
|
||||
|
||||
ErrorParserManager epm = new ErrorParserManager(currentProject, markerGenerator, new String[] {GMAKE_ERROR_PARSER_ID});
|
||||
epm.setOutputStream(cos);
|
||||
StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 70), epm, 100);
|
||||
OutputStream stdout = streamMon;
|
||||
OutputStream stderr = streamMon;
|
||||
|
||||
ConsoleOutputSniffer sniffer = ScannerInfoConsoleParserFactory.getESIProviderOutputSniffer(
|
||||
stdout, stderr, currentProject, context, providerId, buildInfo, collector, markerGenerator);
|
||||
OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
|
||||
OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
|
||||
TraceUtil.outputTrace("Default provider is executing command:", fCompileCommand.toString() + ca, ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
Process p = launcher.execute(getCommandToLaunch(), comandLineOptions, setEnvironment(launcher, env), fWorkingDirectory, monitor);
|
||||
if (p != null) {
|
||||
try {
|
||||
|
@ -138,13 +158,34 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
|
||||
if (errMsg != null) {
|
||||
String errorDesc = MakeMessages.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR,
|
||||
fCompileCommand.toString() + ca);
|
||||
markerGenerator.addMarker(currentProject, -1, errorDesc, IMarkerGenerator.SEVERITY_WARNING, null);
|
||||
}
|
||||
if (errMsg != null) {
|
||||
String errorPrefix = MakeMessages.getString("ExternalScannerInfoProvider.Error_Prefix"); //$NON-NLS-1$
|
||||
String program = fCompileCommand.toString();
|
||||
|
||||
String msg = MakeMessages.getFormattedString(EXTERNAL_SI_PROVIDER_ERROR, program+params);
|
||||
printLine(consoleErr, errorPrefix + msg + NEWLINE);
|
||||
|
||||
// Launching failed, trying to figure out possible cause
|
||||
Properties envMap = getEnvMap(launcher, env);
|
||||
String envPath = envMap.getProperty(PATH_ENV);
|
||||
if (envPath == null) {
|
||||
envPath = System.getenv(PATH_ENV);
|
||||
}
|
||||
if (!fCompileCommand.isAbsolute() && PathUtil.findProgramLocation(program, envPath) == null) {
|
||||
printLine(consoleErr, errMsg);
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", fWorkingDirectory); //$NON-NLS-1$
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Program_Not_In_Path", program); //$NON-NLS-1$
|
||||
printLine(consoleErr, errorPrefix + msg + NEWLINE);
|
||||
printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} else {
|
||||
printLine(consoleErr, errorPrefix + errMsg);
|
||||
msg = MakeMessages.getFormattedString("ExternalScannerInfoProvider.Working_Directory", fWorkingDirectory); //$NON-NLS-1$
|
||||
printLine(consoleErr, PATH_ENV + "=[" + envPath + "]" + NEWLINE); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
monitor.subTask(MakeMessages.getString("ExternalScannerInfoProvider.Creating_Markers")); //$NON-NLS-1$
|
||||
consoleOut.close();
|
||||
consoleErr.close();
|
||||
cos.close();
|
||||
|
@ -169,6 +210,11 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
buildInfo.isUseDefaultProviderCommand(providerId));
|
||||
}
|
||||
|
||||
private void printLine(OutputStream stream, String msg) throws IOException {
|
||||
stream.write((msg + NEWLINE).getBytes());
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of protected fields.
|
||||
* Subclasses are most likely to override default implementation.
|
||||
|
@ -212,8 +258,8 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
return ca;
|
||||
}
|
||||
|
||||
protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) {
|
||||
// Set the environmennt, some scripts may need the CWD var to be set.
|
||||
private Properties getEnvMap(ICommandLauncher launcher, Properties initialEnv) {
|
||||
// Set the environmennt, some scripts may need the CWD var to be set.
|
||||
Properties props = initialEnv != null ? initialEnv : launcher.getEnvironment();
|
||||
|
||||
if (fWorkingDirectory != null) {
|
||||
|
@ -229,6 +275,11 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
if (props.containsKey(LANG_ENV_VAR)) {
|
||||
props.put(LANG_ENV_VAR, "en_US.UTF-8"); //$NON-NLS-1$
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
protected String[] setEnvironment(ICommandLauncher launcher, Properties initialEnv) {
|
||||
Properties props = getEnvMap(launcher, initialEnv);
|
||||
String[] env = null;
|
||||
ArrayList<String> envList = new ArrayList<String>();
|
||||
Enumeration<?> names = props.propertyNames();
|
||||
|
@ -242,4 +293,29 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
return env;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set preference to stream output of scanner discovery to a console.
|
||||
*/
|
||||
public static void setConsoleEnabled(boolean value) {
|
||||
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(MakeCorePlugin.PLUGIN_ID);
|
||||
node.putBoolean(PREF_CONSOLE_ENABLED, value);
|
||||
try {
|
||||
node.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
MakeCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check preference to stream output of scanner discovery to a console.
|
||||
*
|
||||
* @return boolean preference value
|
||||
*/
|
||||
public static boolean isConsoleEnabled() {
|
||||
boolean value = InstanceScope.INSTANCE.getNode(MakeCorePlugin.PLUGIN_ID)
|
||||
.getBoolean(PREF_CONSOLE_ENABLED, false);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -299,6 +299,7 @@ ScannerConfigOptionsDialog.siProvider.command.label=Compiler invocation command
|
|||
ScannerConfigOptionsDialog.siProvider.args.label=Compiler invocation arguments
|
||||
ScannerConfigOptionsDialog.siProvider.browse.button=Browse...
|
||||
ScannerConfigOptionsDialog.siProvider.browse.runCommandDialog='gcc' command:
|
||||
ScannerConfigOptionsDialog.siProvider.show.console.label=Show output in a dedicated console in the Console view (global preference)
|
||||
ScannerConfigOptionsDialog.siProvider.command.errorMessage=Must enter compiler invocation command
|
||||
ScannerConfigOptionsDialog.apply.progressMessage=Setting scanner configuration discovery options...
|
||||
ScannerConfigOptionsDialog.common.variables.button=Variables...
|
||||
|
|
|
@ -59,9 +59,18 @@ public class GCCPerProjectSCDProfilePage extends AbstractDiscoveryPage {
|
|||
private Button sipEnabledButton;
|
||||
private Text sipRunCommandText;
|
||||
private Text sipRunArgsText;
|
||||
private Button sipConsoleEnabledButton;
|
||||
|
||||
private boolean isValid = true;
|
||||
|
||||
/**
|
||||
* Static variable corresponding to global preference to show scanner
|
||||
* discovery console.
|
||||
*
|
||||
* @since 7.1
|
||||
*/
|
||||
public static boolean isSIConsoleEnabled = false;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#createControl(org.eclipse.swt.widgets.Composite)
|
||||
*/
|
||||
|
@ -213,6 +222,17 @@ public class GCCPerProjectSCDProfilePage extends AbstractDiscoveryPage {
|
|||
}
|
||||
});
|
||||
|
||||
// si provider console enabled checkbox
|
||||
String sipConsoleEnabledLabel = MakeUIPlugin.getResourceString("ScannerConfigOptionsDialog.siProvider.show.console.label"); //$NON-NLS-1$
|
||||
sipConsoleEnabledButton = ControlFactory.createCheckBox(profileGroup, sipConsoleEnabledLabel);
|
||||
((GridData)sipConsoleEnabledButton.getLayoutData()).horizontalSpan = 3;
|
||||
((GridData)sipConsoleEnabledButton.getLayoutData()).grabExcessHorizontalSpace = true;
|
||||
sipConsoleEnabledButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
isSIConsoleEnabled = sipConsoleEnabledButton.getSelection();
|
||||
}
|
||||
});
|
||||
|
||||
setControl(page);
|
||||
// set the shell variable; must be after setControl
|
||||
|
@ -298,6 +318,7 @@ public class GCCPerProjectSCDProfilePage extends AbstractDiscoveryPage {
|
|||
sipEnabledButton.setSelection(builderInfo.isProviderOutputParserEnabled(providerId));
|
||||
sipRunCommandText.setText(builderInfo.getProviderRunCommand(providerId));
|
||||
sipRunArgsText.setText(builderInfo.getProviderRunArguments(providerId));
|
||||
sipConsoleEnabledButton.setSelection(isSIConsoleEnabled);
|
||||
}
|
||||
|
||||
private String getProviderIDForSelectedProfile() {
|
||||
|
|
|
@ -36,16 +36,17 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollectorCleaner;
|
|||
import org.eclipse.cdt.make.core.scannerconfig.InfoContext;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathInfo;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredScannerInfoStore;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.DefaultRunSIProvider;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCProfileInstance;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig2.ScannerConfigProfileManager;
|
||||
import org.eclipse.cdt.make.ui.dialogs.AbstractDiscoveryPage;
|
||||
import org.eclipse.cdt.make.ui.dialogs.GCCPerProjectSCDProfilePage;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IInputType;
|
||||
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.IToolChain;
|
||||
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
|
||||
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
|
||||
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
|
||||
|
@ -539,6 +540,8 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
|
|||
*
|
||||
*/
|
||||
private void initializeProfilePageMap() {
|
||||
GCCPerProjectSCDProfilePage.isSIConsoleEnabled = DefaultRunSIProvider.isConsoleEnabled();
|
||||
|
||||
pagesList = new ArrayList<DiscoveryProfilePageConfiguration>(5);
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE, POINT);
|
||||
if (point == null)
|
||||
|
@ -599,16 +602,20 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
|
|||
ManagedBuilderUIPlugin.log(e);
|
||||
}
|
||||
} else {
|
||||
CUIPlugin.logError(Messages.DiscoveryTab_7);
|
||||
IStatus status = new Status(IStatus.ERROR, ManagedBuilderUIPlugin.getUniqueIdentifier(), Messages.DiscoveryTab_7);
|
||||
ManagedBuilderUIPlugin.log(status);
|
||||
}
|
||||
}
|
||||
|
||||
clearChangedDiscoveredInfos();
|
||||
|
||||
DefaultRunSIProvider.setConsoleEnabled(GCCPerProjectSCDProfilePage.isSIConsoleEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performOK() {
|
||||
performOK(true);
|
||||
DefaultRunSIProvider.setConsoleEnabled(GCCPerProjectSCDProfilePage.isSIConsoleEnabled);
|
||||
}
|
||||
|
||||
private void performOK(boolean ok) {
|
||||
|
@ -764,6 +771,8 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
|
|||
}
|
||||
}
|
||||
updateData();
|
||||
|
||||
DefaultRunSIProvider.setConsoleEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue