[PATCH] Allow a per-toolchain specified pkg-config binary

50 views
Skip to first unread message

Mélanie Bats

unread,
Jan 6, 2013, 2:13:45 PM1/6/13
to pkg-config-suppor...@googlegroups.com, petri.t...@gmail.com, cdt...@gmail.com, melani...@obeo.fr
When cross-compilation toolchains are used, they often provide their own
pkg-config binary, which automatically points to the right location for the
.pc files, the libraries and headers.

In an Eclipse CDT context, those toolchains are typically registered through
the org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point. In
this model, the toolchain are composed of several tools: the C compiler, the
C++ compiler, the linker, the assembler, etc.

So, what we propose in this patch is to make pkg-config another "tool" of
a toolchain, so that Eclipse plugins registering toolchains can specify the
path to a toolchain-specific pkg-config binary along with the path to other
traditional tools (compilers, etc.). To do so, they would define a tool whose
superClass is org.eclipse.cdt.managedbuilder.pkgconfig.tool (this tool is
defined as an abstract tool in our pkg-config plugin).

Once we have this in place, this patch tunes the configuration interface in
terms of pkg-config path selection. We now have two choices:

* Use the default pkg-config path provided by the toolchain. If this option
is selected but the toolchain does not provide a pkg-config tool, then the
default of just 'pkg-config' is assumed (or pkg-config.exe on Windows).

* A custom path, completely user-defined.

This patch also adds a ICProjectDescriptionListener, which allows us to be
notified when the toolchain selection is changed, so that we can update the
pkg-config settings accordingly.

Signed-off-by: Mélanie Bats <melani...@obeo.fr>
---
.../plugin.xml | 9 ++
.../cdt/managedbuilder/pkgconfig/Activator.java | 68 +++++++++--
.../pkgconfig/preferences/Messages.java | 2 +
.../preferences/PkgConfigBinPathFieldEditor.java | 125 --------------------
.../preferences/PkgConfigSettingsDialog.java | 119 +++++++++++++++----
.../pkgconfig/preferences/PreferenceStore.java | 41 +++++++
.../pkgconfig/preferences/messages.properties | 2 +
.../pkgconfig/properties/PkgConfigPropertyTab.java | 69 ++++++++++-
8 files changed, 275 insertions(+), 160 deletions(-)
delete mode 100644 org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigBinPathFieldEditor.java

diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/plugin.xml b/org.eclipse.cdt.managedbuilder.pkgconfig/plugin.xml
index d6c64c5..14bac67 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/plugin.xml
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/plugin.xml
@@ -47,4 +47,13 @@
class="org.eclipse.cdt.managedbuilder.pkgconfig.settings.PkgConfigExternalSettingProvider">
</provider>
</extension>
+ <extension
+ point="org.eclipse.cdt.managedbuilder.core.buildDefinitions">
+ <tool
+ id="org.eclipse.cdt.managedbuilder.pkgconfig.tool"
+ isAbstract="true"
+ name="Pkg-Config"
+ natureFilter="both">
+ </tool>
+ </extension>
</plugin>
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/Activator.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/Activator.java
index f362e42..93b9a19 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/Activator.java
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/Activator.java
@@ -13,10 +13,21 @@ package org.eclipse.cdt.managedbuilder.pkgconfig;
import java.io.IOException;
import java.util.PropertyResourceBundle;

+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.pkgconfig.settings.PkgConfigExternalSettingProvider;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -29,15 +40,20 @@ public class Activator extends AbstractUIPlugin {
//Plug-in ID
public static final String PLUGIN_ID = "org.eclipse.cdt.managedbuilder.pkgconfig"; //$NON-NLS-1$

+ //Tool ID
+ public static final String TOOL_ID = "org.eclipse.cdt.managedbuilder.pkgconfig.tool"; //$NON-NLS-1$
+
//Shared instance
private static Activator plugin;
-
+
//Name for the properties file
private final static String PROPERTIES = "plugin.properties"; //$NON-NLS-1$
-
+
//Property Resource bundle
private PropertyResourceBundle properties;
-
+
+ private ICProjectDescriptionListener listener;
+
/**
* The constructor
*/
@@ -54,6 +70,41 @@ public class Activator extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ this.listener = new ICProjectDescriptionListener() {
+
+ // Handle the configuration updates in order to clear the pkg
+ // config settings (eg. if a new toolchain is selected, the pkg
+ // config settings will be updated after the user apply the
+ // changes even if he does not go through the pkg config
+ // property tab)
+ @Override
+ public void handleEvent(CProjectDescriptionEvent event) {
+ // Get the configuration description of the updated project
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(event
+ .getProject());
+
+ IConfiguration cfg = info.getDefaultConfiguration();
+ ICProjectDescription projDesc = CoreModel.getDefault()
+ .getProjectDescription(event.getProject(), true);
+ final ICConfigurationDescription confDesc = projDesc
+ .getConfigurationById(cfg.getId());
+
+ Job j = new Job("Update Pkg-config external settings provider") { //$NON-NLS-1$
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ // update external setting providers
+ confDesc.updateExternalSettingsProviders(new String[] { PkgConfigExternalSettingProvider.ID });
+ return Status.OK_STATUS;
+ }
+ };
+ j.setPriority(Job.INTERACTIVE);
+ j.schedule();
+ }
+ };
+ // Listen for the configuration updates (toolchain updates are important
+ // for us as the pkg-config plugin depends on the select toolchain)
+ CoreModel.getDefault().addCProjectDescriptionListener(this.listener,
+ CProjectDescriptionEvent.DATA_APPLIED);
}

/*
@@ -63,6 +114,7 @@ public class Activator extends AbstractUIPlugin {
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
+ CoreModel.getDefault().removeCProjectDescriptionListener(this.listener);
super.stop(context);
}

@@ -85,7 +137,7 @@ public class Activator extends AbstractUIPlugin {
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
-
+
/**
* Get plugin.properties
*
@@ -102,8 +154,8 @@ public class Activator extends AbstractUIPlugin {
}
}
return this.properties;
- }
-
+ }
+
/**
* Log error.
*
@@ -121,7 +173,7 @@ public class Activator extends AbstractUIPlugin {
public void log(IStatus status) {
getLog().log(status);
}
-
+
/**
* Log Status, plug-in id, message and exception.
*
@@ -132,7 +184,7 @@ public class Activator extends AbstractUIPlugin {
public void log(int status, Exception e, String message) {
getLog().log(new Status(status, PLUGIN_ID, message, e));
}
-
+
/**
* Log plug-in id, message and exception.
*
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/Messages.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/Messages.java
index ff37ca3..ada4fb2 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/Messages.java
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/Messages.java
@@ -25,6 +25,8 @@ public class Messages extends NLS {
public static String PreferencePage_1;
public static String PreferencePage_2;
public static String PreferencePage_3;
+ public static String PreferencePage_4;
+ public static String PreferencePage_5;

static {
// initialize resource bundle
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigBinPathFieldEditor.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigBinPathFieldEditor.java
deleted file mode 100644
index 67b2de6..0000000
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigBinPathFieldEditor.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Melanie Bats 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:
- * Melanie Bats - Initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.managedbuilder.pkgconfig.preferences;
-
-import java.io.File;
-
-import org.eclipse.jface.preference.StringButtonFieldEditor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.FileDialog;
-
-public class PkgConfigBinPathFieldEditor extends StringButtonFieldEditor {
-
- /**
- * Initial path for the Browse dialog.
- */
- private File filterPath = null;
-
- /**
- * Creates a pkg-config bin editor
- */
- protected PkgConfigBinPathFieldEditor() {
- }
-
- /**
- * Creates a pkg-config bin editor.
- *
- * @param name
- * the name of the preference this field editor works on
- * @param labelText
- * the label text of the field editor
- * @param parent
- * the parent of the field editor's control
- */
- public PkgConfigBinPathFieldEditor(String name, String labelText,
- Composite parent) {
- init(name, labelText);
- setErrorMessage(JFaceResources
- .getString("FileFieldEditor.errorMessage"));//$NON-NLS-1$
- setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$
- setValidateStrategy(VALIDATE_ON_FOCUS_LOST);
- createControl(parent);
- }
-
- /**
- * Helper that opens the directory chooser dialog.
- *
- * @param startingDirectory
- * The directory the dialog will open in.
- * @return File File or <code>null</code>.
- *
- */
- private File getFile(File startingDirectory) {
- FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET);
-
- if (startingDirectory != null) {
- fileDialog.setFilterPath(startingDirectory.getPath());
- } else if (this.filterPath != null) {
- fileDialog.setFilterPath(this.filterPath.getPath());
- }
-
- String dir = fileDialog.open();
- if (dir != null) {
- dir = dir.trim();
- if (dir.length() > 0) {
- return new File(dir);
- }
- }
- return null;
- }
-
- @Override
- /*
- * (non-Javadoc) Method declared on StringButtonFieldEditor. Opens the
- * directory chooser dialog and returns the selected directory.
- */
- protected String changePressed() {
- File f = new File(getTextControl().getText());
- if (!f.exists()) {
- f = null;
- }
- File d = getFile(f);
- if (d == null) {
- return null;
- }
-
- return d.getAbsolutePath();
- }
-
- @Override
- /*
- * (non-Javadoc) Method declared on StringFieldEditor. Checks whether the
- * text input field contains a valid directory.
- */
- protected boolean doCheckState() {
- String fileName = getTextControl().getText();
- fileName = fileName.trim();
- if (fileName.length() == 0 && isEmptyStringAllowed()) {
- return true;
- }
- File file = new File(fileName);
- return !file.isDirectory() && file.getName().contains("pkg-config"); //$NON-NLS-1$
- }
-
- /**
- * Sets the initial path for the Browse dialog.
- *
- * @param path
- * initial path for the Browse dialog
- * @since 3.6
- */
- public void setFilterPath(File path) {
- this.filterPath = path;
- }
-
-}
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigSettingsDialog.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigSettingsDialog.java
index cb1634f..42e2724 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigSettingsDialog.java
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PkgConfigSettingsDialog.java
@@ -11,7 +11,13 @@

package org.eclipse.cdt.managedbuilder.pkgconfig.preferences;

+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.pkgconfig.Activator;
+import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.PreferenceStore.PkgConfigExecutable;
import org.eclipse.cdt.ui.newui.AbstractPropertyDialog;
+import org.eclipse.core.resources.IProject;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -22,6 +28,8 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

@@ -31,28 +39,53 @@ public class PkgConfigSettingsDialog extends AbstractPropertyDialog {
private static final String PKG_CONFIG_LIBDIR = Messages.PkgConfigSettingsDialog_1;

private Combo pkgConfigPathKindCombo;
- private PkgConfigBinPathFieldEditor pkgconfigBinPathEditor;
private PkgConfigPathListEditor configPathListEditor;

private Button buttonOk;
private Button buttonCancel;

- private String projectName;
+ protected String projectName;
+ protected IProject project;
+ protected String selectedFile;
+ private Button radioDefault;
+ private Button radioCustom;

- public PkgConfigSettingsDialog(Shell _parent, String title,
- String projectName) {
+ public PkgConfigSettingsDialog(Shell _parent, String title, IProject project) {
super(_parent, title);
- this.projectName = projectName;
+ this.project = project;
+ this.projectName = project.getName();
+
}

@Override
public void buttonPressed(SelectionEvent e) {
if (e.widget.equals(this.buttonOk)) {
- String pkgConfigBinEditorValue = this.pkgconfigBinPathEditor
- .getStringValue();
- PreferenceStore.setPkgConfigBinPath(pkgConfigBinEditorValue,
- this.projectName);
-
+ if (this.radioCustom.getSelection() && this.selectedFile != null) {
+ PreferenceStore.setPkgConfigExecutable(PkgConfigExecutable.Custom,
+ PkgConfigSettingsDialog.this.projectName);
+ PreferenceStore.setPkgConfigBinPath(this.selectedFile,
+ PkgConfigSettingsDialog.this.projectName);
+ }else{
+ PreferenceStore.setPkgConfigExecutable(PkgConfigExecutable.Default,
+ PkgConfigSettingsDialog.this.projectName);
+ // Search if a toolchain tool defines the pkg-config tool bin
+ // path
+ String pkgConfigPath = UNSET_PKG_CONFIG;
+ IManagedBuildInfo info = ManagedBuildManager
+ .getBuildInfo(PkgConfigSettingsDialog.this.project);
+ if (info != null) {
+ for (ITool tool : info
+ .getDefaultConfiguration()
+ .getToolChain()
+ .getToolsBySuperClassId(
+ Activator.TOOL_ID)) {
+ pkgConfigPath = tool.getToolCommand();
+ }
+ }
+ PreferenceStore.setPkgConfigBinPath(pkgConfigPath,
+ PkgConfigSettingsDialog.this.projectName);
+ }
+
String pkgConfigPathKind = this.pkgConfigPathKindCombo.getText();

PreferenceStore.clearPkgConfigLibDir(this.projectName);
@@ -76,29 +109,72 @@ public class PkgConfigSettingsDialog extends AbstractPropertyDialog {

@Override
protected Control createDialogArea(Composite parent) {
- this.shell.setSize(700, 250);
+ this.shell.setSize(700, 350);
+
GridLayout gridLayout = new GridLayout();
parent.setLayout(gridLayout);
Composite composite = new Composite(parent, SWT.None);
GridData layoutData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(layoutData);
- composite.setLayout(new GridLayout(3, false));
+ composite.setLayout(new GridLayout(1, false));
+
+ Group group = new Group(composite, SWT.NONE);
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ group.setLayout(new GridLayout(2, false));
+ group.setText(Messages.PreferencePage_3);
+
+ this.radioDefault = new Button(group, SWT.RADIO);
+ GridData layoutData1 = new GridData(GridData.FILL_BOTH);
+ layoutData1.horizontalSpan = 2;
+ this.radioDefault.setLayoutData(layoutData1);
+ boolean isDefaultPkgConfigExecutableSelected = PreferenceStore.isPkgConfigExecutableDefault(this.projectName);
+ this.radioDefault.setSelection(isDefaultPkgConfigExecutableSelected);
+ this.radioDefault.setText(Messages.PreferencePage_4);
+
+ this.radioCustom = new Button(group, SWT.RADIO);
+ this.radioCustom.setSelection(!isDefaultPkgConfigExecutableSelected);
+ this.radioCustom.setText(Messages.PreferencePage_5);
+ final Button browseButton = new Button(group, SWT.PUSH);
+ browseButton.setText("Browse..."); //$NON-NLS-1$
+ browseButton.setEnabled(!isDefaultPkgConfigExecutableSelected);
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String pkgConfigBinPath = PreferenceStore
+ .getPkgConfigBinPath(PkgConfigSettingsDialog.this.projectName);
+ FileDialog dialog = new FileDialog(
+ PkgConfigSettingsDialog.this.shell, SWT.OPEN);
+ dialog.setFileName(pkgConfigBinPath);
+ PkgConfigSettingsDialog.this.selectedFile = dialog.open();
+ }
+ });
+
+ this.radioDefault.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browseButton.setEnabled(false);
+ }
+ });

- this.pkgconfigBinPathEditor = new PkgConfigBinPathFieldEditor(
- PreferenceConstants.PKG_CONFIG_BIN, Messages.PreferencePage_3,
- composite);
+ this.radioCustom.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ browseButton.setEnabled(true);
+ }
+ });

- this.pkgconfigBinPathEditor.setStringValue(PreferenceStore
- .getPkgConfigBinPath(this.projectName));
+ Group group2 = new Group(composite, SWT.NONE);
+ group2.setLayoutData(layoutData);
+ group2.setLayout(new GridLayout(2, false));

- Label comboLabel = new Label(composite, SWT.WRAP);
+ Label comboLabel = new Label(group2, SWT.WRAP);
GridData comboLabelLayout = new GridData();
comboLabel.setLayoutData(comboLabelLayout);
comboLabel.setText(Messages.PkgConfigSettingsDialog_2);

- this.pkgConfigPathKindCombo = new Combo(composite, SWT.BORDER
+ this.pkgConfigPathKindCombo = new Combo(group2, SWT.BORDER
| SWT.READ_ONLY);
- GridData comboLayout = new GridData();
+ GridData comboLayout = new GridData(GridData.FILL_HORIZONTAL);

this.pkgConfigPathKindCombo.setItems(new String[] { UNSET_PKG_CONFIG,
PKG_CONFIG_PATH, PKG_CONFIG_LIBDIR });
@@ -110,7 +186,7 @@ public class PkgConfigSettingsDialog extends AbstractPropertyDialog {
String[] pkgConfigLibDir = PreferenceStore
.getPkgConfigLibDir(this.projectName);

- Composite composite2 = new Composite(composite, SWT.None);
+ Composite composite2 = new Composite(group2, SWT.None);
GridData layoutData2 = new GridData(GridData.FILL_BOTH);
layoutData2.horizontalAlignment = SWT.FILL;
layoutData2.horizontalSpan = 3;
@@ -139,7 +215,6 @@ public class PkgConfigSettingsDialog extends AbstractPropertyDialog {
Composite compButtons = new Composite(composite, SWT.FILL);
GridData gd = new GridData(SWT.RIGHT, SWT.BOTTOM, true, false);
gd.horizontalSpan = 4;
- // gd.grabExcessVerticalSpace = true;
compButtons.setLayoutData(gd);
compButtons.setLayout(new GridLayout(2, true));

diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PreferenceStore.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PreferenceStore.java
index 19c29d7..1374f78 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PreferenceStore.java
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/PreferenceStore.java
@@ -23,10 +23,15 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
public class PreferenceStore {

private static final String PATH_SEPARATOR = ";"; //$NON-NLS-1$
+ private static final String PKG_CONFIG_BIN_KIND = "PKG_CONFIG_BIN_KIND"; //$NON-NLS-1$
private static final String PKG_CONFIG_BIN = "PKG_CONFIG_BIN"; //$NON-NLS-1$
private static final String PKG_CONFIG_LIBDIR = "PKG_CONFIG_LIBDIR"; //$NON-NLS-1$
private static final String PKG_CONFIG_PATH = "PKG_CONFIG_PATH"; //$NON-NLS-1$

+ public enum PkgConfigExecutable {
+ Default, Custom
+ }
+
/**
* Get the Pkg-config preference store.
*
@@ -68,6 +73,29 @@ public class PreferenceStore {
}

/**
+ * Set pkg-config executable type to the preference store.
+ *
+ * @param pkgConfigExecutable
+ * The pkg-config executable.
+ * @param project
+ */
+ public static void setPkgConfigExecutable(
+ PkgConfigExecutable pkgConfigExecutable, String project) {
+ setPreferenceStoreValue(getPkgConfigExecutableKey(project),
+ pkgConfigExecutable.toString());
+ }
+
+ /**
+ * Is pkg-config executable set to default in the preference store.
+ *
+ * @return True if the executable to use is the deafult one else return false to use the custom.
+ */
+ public static boolean isPkgConfigExecutableDefault(String project) {
+ return !PkgConfigExecutable.Custom.name().equals(
+ getPreferenceStoreValue(getPkgConfigExecutableKey(project)));
+ }
+
+ /**
* Set pkg-config bin to the preference store.
*
* @param path
@@ -187,6 +215,19 @@ public class PreferenceStore {
}

/**
+ * Compute the key for the given pkg-config binary kind and the given
+ * project.
+ *
+ * @param project
+ * Project name
+ * @return Key
+ */
+ private static String getPkgConfigExecutableKey(String project) {
+ return PKG_CONFIG_BIN_KIND + " - " //$NON-NLS-1$
+ + project;
+ }
+
+ /**
* Compute the key for the given pkg-config lib dir and the given project.
*
* @param project
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/messages.properties b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/messages.properties
index efe0318..74702ef 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/messages.properties
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/preferences/messages.properties
@@ -2,6 +2,8 @@ PreferencePage_0=Preferences for Pkg-config
PreferencePage_1=PKG_CONFIG_PATH:
PreferencePage_2=PKG_CONFIG_LIBDIR (replaces default):
PreferencePage_3=Path to pkg-config executable:
+PreferencePage_4=Default from toolchain
+PreferencePage_5=Custom
PkgConfigPathListEditor_0=Browse a directory path
PkgConfigPathListEditor_1=Select a directory
PkgConfigPropertyTab_0=Pkg-config project settings
diff --git a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/properties/PkgConfigPropertyTab.java b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/properties/PkgConfigPropertyTab.java
index ed91846..c157560 100644
--- a/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/properties/PkgConfigPropertyTab.java
+++ b/org.eclipse.cdt.managedbuilder.pkgconfig/src/org/eclipse/cdt/managedbuilder/pkgconfig/properties/PkgConfigPropertyTab.java
@@ -23,13 +23,16 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.pkgconfig.Activator;
import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.LibDirFieldEditor;
import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.Messages;
-import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.PkgConfigBinPathFieldEditor;
import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.PkgConfigPathListEditor;
import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.PkgConfigSettingsDialog;
+import org.eclipse.cdt.managedbuilder.pkgconfig.preferences.PreferenceStore;
import org.eclipse.cdt.managedbuilder.pkgconfig.settings.PkgConfigExternalSettingProvider;
import org.eclipse.cdt.managedbuilder.pkgconfig.util.Parser;
import org.eclipse.cdt.managedbuilder.pkgconfig.util.PathToToolOption;
@@ -66,7 +69,6 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class PkgConfigPropertyTab extends AbstractCPropertyTab {

- PkgConfigBinPathFieldEditor pkgConfigBinPathFieldEditor;
PkgConfigPathListEditor configPathListEditor;
LibDirFieldEditor libDirEditor;
CheckboxTableViewer pkgCfgViewer;
@@ -85,6 +87,8 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {
"Advanced..." //$NON-NLS-1$
};

+ private IToolChain selectedToolChain;
+
/*
* (non-Javadoc)
*
@@ -123,6 +127,8 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {

createColumns(c1, this.pkgCfgViewer);
this.pkgCfgViewer.setContentProvider(new ArrayContentProvider());
+ this.selectedToolChain = getSelectedToolchain();
+ updatePkgConfigBinPath();
this.pkgCfgViewer.setInput(new DataModelProvider(this.page.getProject()
.getName()).getEntries());

@@ -150,6 +156,24 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {
Arrays.asList(getCheckedItems()));
}

+ @Override
+ public void handleTabEvent(int kind, Object data) {
+
+ if (this.selectedToolChain != null
+ && this.selectedToolChain.getId() != getSelectedToolchain()
+ .getId()) {
+ this.selectedToolChain = getSelectedToolchain();
+ updatePkgConfigBinPath();
+ if (PkgConfigPropertyTab.this.pkgCfgViewer != null) {
+ PkgConfigPropertyTab.this.pkgCfgViewer
+ .setInput(new DataModelProvider(
+ PkgConfigPropertyTab.this.page.getProject()
+ .getName()).getEntries());
+ PkgConfigPropertyTab.this.pkgCfgViewer.refresh();
+ }
+ }
+ }
+
/**
* Get checked items.
*
@@ -197,8 +221,8 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {
private static void addPackageValues(Object[] addedItems, IProject proj) {
for (Object item : addedItems) {
// handle options
- String cflags = PkgConfigUtil.getCflags(
- item.toString(), proj.getName());
+ String cflags = PkgConfigUtil.getCflags(item.toString(),
+ proj.getName());
String[] optionsArray = Parser.parseCflagOptions(cflags);
if (optionsArray != null) {
for (String option : optionsArray) {
@@ -491,10 +515,11 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {
// Create new dialog
PkgConfigSettingsDialog dialog = new PkgConfigSettingsDialog(
this.usercomp.getShell(), Messages.PkgConfigPropertyTab_0,
- this.page.getProject().getName());
+ this.page.getProject());
dialog.open();
if (PkgConfigPropertyTab.this.pkgCfgViewer != null) {
// Update pkg-config libraries for the project
+ updatePkgConfigBinPath();
PkgConfigPropertyTab.this.pkgCfgViewer
.setInput(new DataModelProvider(
PkgConfigPropertyTab.this.page.getProject()
@@ -503,6 +528,40 @@ public class PkgConfigPropertyTab extends AbstractCPropertyTab {
}

/**
+ * Update the pkg-config path according to the toolchain if the default
+ * toolchain executable is selected by the user in the pkg-config advanced
+ * preferences.
+ */
+ private void updatePkgConfigBinPath() {
+ // Search if a toolchain tool defines the pkg-config tool bin
+ // path
+ String pkgConfigPath = ""; //$NON-NLS-1$
+ if (this.page != null
+ && PreferenceStore.isPkgConfigExecutableDefault(this.page
+ .getProject().getName())) {
+ for (ITool tool : this.selectedToolChain
+ .getToolsBySuperClassId("org.eclipse.cdt.managedbuilder.pkgconfig.tool")) { //$NON-NLS-1$
+ pkgConfigPath = tool.getToolCommand();
+ }
+
+ PreferenceStore.setPkgConfigBinPath(pkgConfigPath, this.page
+ .getProject().getName());
+ }
+ }
+
+ private IToolChain getSelectedToolchain() {
+ if (this.page != null) {
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(this.page
+ .getProject());
+ if (info != null) {
+ return info.getDefaultConfiguration().getToolChain();
+
+ }
+ }
+ return null;
+ }
+
+ /**
* Rebuilts the index of the selected project in the workspace.
*/
private void rebuiltIndex() {
--
1.7.9.5

Reply all
Reply to author
Forward
0 new messages